70 lines
1.8 KiB
Lua
70 lines
1.8 KiB
Lua
require ('iuplua')
|
|
|
|
local cancelflag
|
|
local downloadProgress
|
|
|
|
|
|
--create button with cancel flag
|
|
local function downloadStart(YtLink)
|
|
cancelButton = iup.button{
|
|
title = "Cancel",
|
|
action = function()
|
|
cancelflag = true
|
|
end}
|
|
|
|
downloadProgress = iup.progressbar{expand="HORIZONTAL"}
|
|
dlgProgress = iup.dialog{
|
|
title = "Downloading.. ",
|
|
dialogframe = "YES", border = "YES",
|
|
iup.vbox {
|
|
downloadProgress,
|
|
cancelButton,
|
|
pTest,
|
|
}
|
|
}
|
|
dlgProgress.size = "QUARTERxEIGHT"
|
|
dlgProgress.menubox = "NO" -- no windows menus
|
|
dlgProgress.close_cb = cancelButton.action
|
|
dlgProgress:showxy(iup.CENTER, iup.CENTER)
|
|
return dlgProgress
|
|
end
|
|
|
|
|
|
-- start download, create progress bar, monitor progress
|
|
local function DL_progress(YtLink)
|
|
downloadStart(YtLink)
|
|
downloadProgress.value = 0
|
|
local pipe = io.popen("youtube-dl " ..YtLink)
|
|
repeat
|
|
local c = pipe:read(20) -- read the first 20 characters of each line
|
|
if c then
|
|
local b = string.match(c, '.....%%')
|
|
|
|
if b then
|
|
local b = string.sub(b,0,-2)
|
|
downloadProgress.value = b/100 -- x out of 100
|
|
iup.Flush()
|
|
iup.LoopStep() --check for user input
|
|
iup.Flush()
|
|
if cancelflag then
|
|
iup.Message("Terminated", "You have canceled the download")
|
|
iup.Flush()
|
|
break
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
until not c
|
|
pipe:close()
|
|
end
|
|
|
|
popin = {}
|
|
popin.ytdl = function(tubeLink)
|
|
DL_progress(tubeLink)
|
|
end
|
|
|