Mandy/mandy.lua

109 lines
1.9 KiB
Lua
Raw Normal View History

2013-07-23 21:23:31 -05:00
#!/usr/bin/lua5.2
--ffmpeg
--libavcodec-extra-53 <-Ubuntu...suck it
require("iuplua")
require("iupluacontrols")
require('progress')
--Main url entry box
function url_entry()
2013-07-23 22:56:10 -05:00
res, url = iup.GetParam("Mandy - Enter URL", nil,
2013-07-23 21:23:31 -05:00
"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)
2013-07-23 22:56:10 -05:00
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"
2013-07-23 21:23:31 -05:00
2013-07-23 22:56:10 -05:00
popin.ytdl(tmpPath)
2013-07-23 21:23:31 -05:00
2013-07-23 22:56:10 -05:00
return tmpPath2
2013-07-23 21:23:31 -05:00
end
function ffmpeg(tmpPath, dirD)
2013-07-23 22:56:10 -05:00
mp3 = "ffmpeg -i "..tmpPath.." -acodec libmp3lame -ac 2 -ab 192k -vn -y "..dirD..".mp3"
os.execute(mp3)
io.popen("vlc "..dirD..".mp3")
2013-07-23 21:23:31 -05:00
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