Mandy/progress.lua

70 lines
1.8 KiB
Lua
Raw Normal View History

2013-07-23 21:23:31 -05:00
require ('iuplua')
2013-07-27 11:51:07 -05:00
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
2013-07-23 21:23:31 -05:00
end
2013-07-27 11:51:07 -05:00
-- 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
2013-07-23 21:23:31 -05:00
end
2013-07-27 11:51:07 -05:00
until not c
pipe:close()
2013-07-23 21:23:31 -05:00
end
popin = {}
popin.ytdl = function(tubeLink)
DL_progress(tubeLink)
end