Cleaned code, fixed spaceing

This commit is contained in:
Logen Kain 2013-07-27 11:51:07 -05:00 committed by silvernode
parent 66c890a06a
commit cdfcbcc21f
3 changed files with 129 additions and 208 deletions

View File

@ -11,6 +11,7 @@ local function downloadStart(YtLink)
end end
} }
local downloadProgress = iup.progressbar{expand="HORIZONTAL", MARQUEE="YES"} local downloadProgress = iup.progressbar{expand="HORIZONTAL", MARQUEE="YES"}
local dlgProgress = iup.dialog{ local dlgProgress = iup.dialog{
title = "converting", title = "converting",
@ -31,29 +32,19 @@ end
local function DL_progress(YtLink) local function DL_progress(YtLink)
downloadStart() downloadStart()
local pipe = io.popen(YtLink) local pipe = io.popen(YtLink)
--os.execute(YtLink)
repeat repeat
local c = pipe:read() local c = pipe:read()
if c then if c then
iup.Flush() iup.Flush()
iup.LoopStep() iup.LoopStep()
iup.Flush() iup.Flush()
if cancelflag then if cancelflag then
iup.Message("Terminated", "You have canceled the conversion") iup.Message("Terminated", "You have canceled the conversion")
iup.Flush() iup.Flush()
break break
end end
end end
until not c until not c
pipe:close() pipe:close()
iup.Close() iup.Close()

View File

@ -1,52 +1,32 @@
#!/usr/bin/lua5.2 #!/usr/bin/lua5.2
--ffmpeg
--libavcodec-extra-53 <-Ubuntu...suck it
require("iuplua") require("iuplua")
require("iupluacontrols") require("iupluacontrols")
require('progress') require('progress')
require('ffmpeg_progress') require('ffmpeg_progress')
--Main url entry box --Main url entry box
function url_entry() function url_entry()
res, url = iup.GetParam("Mandy 0.4 - Enter URL", nil, res, url = iup.GetParam("Mandy 0.4 - Enter URL", nil,
"Enter Youtube URL: %s\n", "") "Enter Youtube URL: %s\n", "")
if res == true then if res == true then
if string.match(url, "youtube.com/watch") then if string.match(url, "youtube.com/watch") then
return url return url
else else
iup.Message("Error", "The URL is not a youtube link") iup.Message("Error", "The URL is not a youtube link")
iup.Flush() iup.Flush()
iup.Close() iup.Close()
end end
else else
return false return false
end end
end end
--Ask user to select a codec --Ask user to select a codec
function sel_Codec() function sel_Codec()
end end
--Ask user to set directory --Ask user to set directory
function set_dir() function set_dir()
getPath = iup.filedlg{dialogtype = "SAVE", title="Save file...", getPath = iup.filedlg{dialogtype = "SAVE", title="Save file...",
@ -69,25 +49,17 @@ function set_dir()
end end
elseif status == "0" then elseif status == "0" then
local savedPath = getPath.value local savedPath = getPath.value
g_status = "23" g_status = "23"
return savedPath, g_status return savedPath, g_status
elseif status == "-1" then elseif status == "-1" then
g_status = "23" g_status = "23"
return g_status return g_status
end end
end end
function ytDl(x) function ytDl(x)
@ -97,19 +69,17 @@ function ytDl(x)
local tmpPath2 = "/tmp/youtube-dl-"..tmpName.."-"..tmpNameTwo..".flv" local tmpPath2 = "/tmp/youtube-dl-"..tmpName.."-"..tmpNameTwo..".flv"
popin.ytdl(tmpPath) popin.ytdl(tmpPath)
return tmpPath2 return tmpPath2
end end
function ffmpeg(tmpPath, dirD) function ffmpeg(tmpPath, dirD)
local subSpaces = string.gsub(dirD, "", "\\") local subSpaces = string.gsub(dirD, "", "\\")
local mp3 = "ffmpeg -i "..tmpPath.." -acodec libmp3lame -ac 2 -ab 192k -vn -y "..subSpaces local mp3 = "ffmpeg -i "..tmpPath.." -acodec libmp3lame -ac 2 -ab 192k -vn -y "..subSpaces
--os.execute(mp3)
convert_mp3.go(mp3) convert_mp3.go(mp3)
io.popen("notify-send 'The file was saved to' "..subSpaces) io.popen("notify-send 'The file was saved to' "..subSpaces)
io.popen("xdg-open "..subSpaces) io.popen("xdg-open "..subSpaces)
end end
--put everything into a table to use local functions globally --put everything into a table to use local functions globally
global = {} global = {}
global.url = function () global.url = function ()

View File

@ -1,86 +1,55 @@
-- take note of YtLink, I keep passing it around in order to show it as the title bar
-- of the download window, YOU WILL HAVE TO PAY ATTENTION TO IT
-- IT GOES THROUGH FUCKING EVERYTHING
-- Also it will be replaced by what the user saves the file as
-- keep that in mind as well
require ('iuplua') require ('iuplua')
local cancelflag --set variable local cancelflag
local downloadProgress --set variable local downloadProgress
local function downloadStart(YtLink) --create button and cancle flag
--create button with cancel flag
local function downloadStart(YtLink)
cancelButton = iup.button{ cancelButton = iup.button{
title = "Cancel", title = "Cancel",
action = function() action = function()
cancelflag = true cancelflag = true
end}
--return iup.CLOSE --not sure if needed
end
}
local pTest = "1"
downloadProgress = iup.progressbar{expand="HORIZONTAL"} downloadProgress = iup.progressbar{expand="HORIZONTAL"}
dlgProgress = iup.dialog{ --create main window dlgProgress = iup.dialog{
title = "Downloading.. ", title = "Downloading.. ",
dialogframe = "YES", border = "YES", dialogframe = "YES", border = "YES",
iup.vbox { -- create vbox that contains said objects iup.vbox {
downloadProgress, downloadProgress,
cancelButton, cancelButton,
pTest, pTest,
} }
} }
dlgProgress.size = "QUARTERxEIGHT" --should be size of dialog box dlgProgress.size = "QUARTERxEIGHT"
-- dlgProgress.menubox = "NO" -- no windows menus dlgProgress.menubox = "NO" -- no windows menus
dlgProgress.close_cb = cancelButton.action -- calls the action of the button dlgProgress.close_cb = cancelButton.action
dlgProgress:showxy(iup.CENTER, iup.CENTER) -- show and position box dlgProgress:showxy(iup.CENTER, iup.CENTER)
return dlgProgress return dlgProgress
end end
local function DL_progress(YtLink) -- monitor download progress -- start download, create progress bar, monitor progress
downloadStart(YtLink) -- start the progress bar local function DL_progress(YtLink)
downloadStart(YtLink)
downloadProgress.value = 0 downloadProgress.value = 0
local pipe = io.popen("youtube-dl " ..YtLink) local pipe = io.popen("youtube-dl " ..YtLink)
repeat repeat
local c = pipe:read(20) -- read the first 20 characters of each line local c = pipe:read(20) -- read the first 20 characters of each line
if c then -- if c is true then... if c then
local b = string.match(c, '.....%%')
local b = string.match(c, '.....%%') -- %% in a string is "%"
-- string.match finds the percent sign and then finds every character
-- for every dot you place. dots before grab before the character
-- dots after grab after the character
--[[
Perhaps do a different method
round up and only update if number has changed
-- didn't help at all, reverted to less code]]
if b then if b then
--here we take the last character off of the string
--in this case it is the "percent" sign
local b = string.sub(b,0,-2) local b = string.sub(b,0,-2)
downloadProgress.value = b/100 -- x out of 100 downloadProgress.value = b/100 -- x out of 100
-- in this case x is the progress iup.Flush()
-- data we grabbed iup.LoopStep() --check for user input
iup.Flush() -- speeds everything up considerably iup.Flush()
-- when changing an attribute of an element, the change may not if cancelflag then
-- take place immediately
-- in that case throw in a flush after the change
iup.LoopStep() -- required to work, also allows user to click button
iup.Flush() -- added this second flush... helps a shit ton
if cancelflag then -- if cancelflag is true, then break
-- which happens if you click the button
iup.Message("Terminated", "You have canceled the download") iup.Message("Terminated", "You have canceled the download")
iup.Flush() iup.Flush()
break break
end end
end end
@ -89,9 +58,8 @@ round up and only update if number has changed
end end
until not c-- creating a loop until c is not true until not c
pipe:close() -- closing the ipopen pipe:close()
--iup.Close()
end end
popin = {} popin = {}
@ -99,11 +67,3 @@ popin.ytdl = function(tubeLink)
DL_progress(tubeLink) DL_progress(tubeLink)
end end
--if you can have your script call this one and insert the link to YtLink... win
--local YtLink = ('http://www.youtube.com/watch?v=jrmlums5bV8')
--DL_progress( YtLink)