Added project files

This commit is contained in:
silvernode 2013-07-23 21:23:31 -05:00
parent d45577eafb
commit fbdb4bf64a
3 changed files with 233 additions and 0 deletions

16
main.lua Normal file
View File

@ -0,0 +1,16 @@
require("mandy")
function main()
local url=global.url()
-- codec=sel_Codec()
local saveDir=global.dir()
if saveDir == "23" then
return 0
end
local tmpPath = global.path(url)
local convert = global.ffmpeg(tmpPath, saveDir)
end
main()

108
mandy.lua Normal file
View File

@ -0,0 +1,108 @@
#!/usr/bin/lua5.2
--ffmpeg
--libavcodec-extra-53 <-Ubuntu...suck it
require("iuplua")
require("iupluacontrols")
require('progress')
--Main url entry box
function url_entry()
res, url = iup.GetParam("Zymp3 - Enter URL", nil,
"Enter Youtube URL: %s\n", "")
return url
end
--Ask user to select a codec
function sel_Codec()
end
--Ask user to set directory
function set_dir()
getPath = iup.filedlg{dialogtype = "SAVE", title="Save file...",
filter="*.mp3", filterinfo="mp3",
directory="~/Music"}
getPath:popup(iup.ANYWHERE, iup.ANYWHERE)
local status = getPath.status
if status == "1" then
local savedPath = getPath.value
return savedPath
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
function ytDl(x)
local tmpName = math.random(0,999999999999)
local tmpNameTwo = math.random(0,999999999999)
local tmpPath = x.." --output=/tmp/youtube-dl-"..tmpName.."-"..tmpNameTwo..".flv"
local tmpPath2 = "/tmp/youtube-dl-"..tmpName.."-"..tmpNameTwo..".flv"
popin.ytdl(tmpPath)
return tmpPath2
end
function ffmpeg(tmpPath, dirD)
mp3 = "ffmpeg -i "..tmpPath.." -acodec libmp3lame -ac 2 -ab 192k -vn -y "..dirD..".mp3"
os.execute(mp3)
io.popen("vlc "..dirD..".mp3")
end
--put everything into a table to use local functions globally
global = {}
global.url = function ()
local url = url_entry()
return url
end
global.dir = function()
local dir = set_dir()
return dir
end
global.path = function(url)
local yt = ytDl(url)
return yt
end
global.ffmpeg = function(tmpPath, saveDir)
local convert = ffmpeg(tmpPath, saveDir)
return convert
end

109
progress.lua Normal file
View File

@ -0,0 +1,109 @@
-- 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')
local cancelflag --set variable
local downloadProgress --set variable
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
}
local pTest = "1"
downloadProgress = iup.progressbar{expand="HORIZONTAL"}
dlgProgress = iup.dialog{ --create main window
title = YtLink,
dialogframe = "YES", border = "YES",
iup.vbox { -- create vbox that contains said objects
downloadProgress,
cancelButton,
pTest,
}
}
dlgProgress.size = "QUARTERxEIGHT" --should be size of dialog box
-- dlgProgress.menubox = "NO" -- no windows menus
dlgProgress.close_cb = cancelButton.action -- calls the action of the button
dlgProgress:showxy(iup.CENTER, iup.CENTER) -- show and position box
return dlgProgress
end
local function DL_progress(YtLink) -- monitor download progress
downloadStart(YtLink) -- start the progress bar
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 -- if c is true then...
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
--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
end
end
until not c-- creating a loop until c is not true
pipe:close() -- closing the ipopen
iup.Close()
end
popin = {}
popin.ytdl = function(tubeLink)
DL_progress(tubeLink)
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)