Mandy/progress.lua

78 lines
2.1 KiB
Lua
Raw Permalink 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, tmpPath)
2013-07-27 11:51:07 -05:00
downloadStart(YtLink)
downloadProgress.value = 0
local pipe = io.popen("youtube-dl " ..YtLink )
2013-07-27 11:51:07 -05:00
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()
pipe:close()
os.remove(tmpPath..".part")
iup.Flush()
dlgProgress:destroy()
return false
2013-07-27 11:51:07 -05:00
end
end
2013-07-23 21:23:31 -05:00
end
2013-07-27 11:51:07 -05:00
until not c
dlgProgress:destroy()
2013-07-27 11:51:07 -05:00
pipe:close()
return true
2013-07-23 21:23:31 -05:00
end
popin = {}
popin.ytdl = function(tubeLink, tmpPath)
local flag = DL_progress(tubeLink, tmpPath)
if not flag then return false else return true end
2013-07-23 21:23:31 -05:00
end