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

@ -4,66 +4,57 @@ local cancelflag
local downloadProgress local downloadProgress
local function downloadStart(YtLink) local function downloadStart(YtLink)
cancelButton = iup.button{ cancelButton = iup.button{
title = "Cancel", title = "Cancel",
action = function() action = function()
cancelflag = true cancelflag = true
end end
}
local downloadProgress = iup.progressbar{expand="HORIZONTAL", MARQUEE="YES"}
local dlgProgress = iup.dialog{
title = "converting",
dialogframe = "YES", border = "YES",
iup.vbox {
downloadProgress,
cancelButton,
} }
local downloadProgress = iup.progressbar{expand="HORIZONTAL", MARQUEE="YES"} }
local dlgProgress = iup.dialog{ dlgProgress.size = "QUARTERxEIGHT"
title = "converting", dlgProgress.menubox = "NO"
dialogframe = "YES", border = "YES", dlgProgress.close_cb = cancelButton.action
iup.vbox { dlgProgress:showxy(iup.CENTER, iup.CENTER)
downloadProgress, return dlgProgress
cancelButton,
}
}
dlgProgress.size = "QUARTERxEIGHT"
dlgProgress.menubox = "NO"
dlgProgress.close_cb = cancelButton.action
dlgProgress:showxy(iup.CENTER, iup.CENTER)
return dlgProgress
end 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.LoopStep()
iup.Flush() iup.Flush()
if cancelflag then
iup.LoopStep() iup.Message("Terminated", "You have canceled the conversion")
iup.Flush() iup.Flush()
if cancelflag then break
end
iup.Message("Terminated", "You have canceled the conversion") end
iup.Flush() until not c
break pipe:close()
iup.Close()
end return
end
until not c
pipe:close()
iup.Close()
return
end end
convert_mp3 = {} convert_mp3 = {}
convert_mp3.go = function(tubeLink) convert_mp3.go = function(tubeLink)
DL_progress(tubeLink) DL_progress(tubeLink)
return return
end end

112
mandy.lua
View File

@ -1,93 +1,65 @@
#!/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 string.match(url, "youtube.com/watch") then
if res == true then return url
if string.match(url, "youtube.com/watch") then
return url
else
iup.Message("Error", "The URL is not a youtube link")
iup.Flush()
iup.Close()
end
else else
return false iup.Message("Error", "The URL is not a youtube link")
iup.Flush()
iup.Close()
end end
else
return false
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...",
filter="*.mp3", filterinfo="mp3", filter="*.mp3", filterinfo="mp3",
directory=".", directory=".",
file="*.mp3"} file="*.mp3"}
getPath:popup(iup.ANYWHERE, iup.ANYWHERE) getPath:popup(iup.ANYWHERE, iup.ANYWHERE)
local status = getPath.status local status = getPath.status
if status == "1" then if status == "1" then
if string.match(getPath.value, ".mp3") then if string.match(getPath.value, ".mp3") then
local savedPath = getPath.value local savedPath = getPath.value
return savedPath return savedPath
else else
local savedPath = getPath.value..".mp3" local savedPath = getPath.value..".mp3"
return savedPath return savedPath
end
elseif status == "0" then
local savedPath = getPath.value
g_status = "23"
return savedPath, g_status
elseif status == "-1" then
g_status = "23"
return g_status
end end
elseif status == "0" then
local savedPath = getPath.value
g_status = "23"
return savedPath, g_status
elseif status == "-1" then
g_status = "23"
return g_status
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,97 +1,65 @@
-- 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
cancelButton = iup.button{
title = "Cancel",
action = function()
cancelflag = true
--return iup.CLOSE --not sure if needed
end
} --create button with cancel flag
local pTest = "1" local function downloadStart(YtLink)
downloadProgress = iup.progressbar{expand="HORIZONTAL"} cancelButton = iup.button{
dlgProgress = iup.dialog{ --create main window title = "Cancel",
title = "Downloading.. ", action = function()
dialogframe = "YES", border = "YES", cancelflag = true
iup.vbox { -- create vbox that contains said objects end}
downloadProgress,
cancelButton, downloadProgress = iup.progressbar{expand="HORIZONTAL"}
pTest, dlgProgress = iup.dialog{
} title = "Downloading.. ",
} dialogframe = "YES", border = "YES",
dlgProgress.size = "QUARTERxEIGHT" --should be size of dialog box iup.vbox {
-- dlgProgress.menubox = "NO" -- no windows menus downloadProgress,
dlgProgress.close_cb = cancelButton.action -- calls the action of the button cancelButton,
dlgProgress:showxy(iup.CENTER, iup.CENTER) -- show and position box pTest,
return dlgProgress }
}
dlgProgress.size = "QUARTERxEIGHT"
dlgProgress.menubox = "NO" -- no windows menus
dlgProgress.close_cb = cancelButton.action
dlgProgress:showxy(iup.CENTER, iup.CENTER)
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)
downloadProgress.value = 0 downloadStart(YtLink)
local pipe = io.popen("youtube-dl " ..YtLink) downloadProgress.value = 0
repeat local pipe = io.popen("youtube-dl " ..YtLink)
local c = pipe:read(20) -- read the first 20 characters of each line repeat
if c then -- if c is true then... local c = pipe:read(20) -- read the first 20 characters of each line
if c then
local b = string.match(c, '.....%%') -- %% in a string is "%" local b = string.match(c, '.....%%')
-- 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
--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)
downloadProgress.value = b/100 -- x out of 100
-- in this case x is the progress
-- data we grabbed
iup.Flush() -- speeds everything up considerably
-- when changing an attribute of an element, the change may not
-- 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.Flush()
break
end 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
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)