2013-08-05 18:41:16 -05:00
|
|
|
#!/usr/bin/env lua
|
2013-07-23 21:23:31 -05:00
|
|
|
|
|
|
|
require("iuplua")
|
|
|
|
require("iupluacontrols")
|
|
|
|
require('progress')
|
2013-07-27 01:52:23 -05:00
|
|
|
require('ffmpeg_progress')
|
2013-07-26 20:36:15 -05:00
|
|
|
|
2013-07-23 21:23:31 -05:00
|
|
|
--Main url entry box
|
|
|
|
function url_entry()
|
2013-08-03 17:36:45 -05:00
|
|
|
local format = sel_format()
|
2013-08-05 04:10:10 -05:00
|
|
|
local bitRate = sel_bitrate()
|
2013-07-31 02:29:11 -05:00
|
|
|
local url = ""
|
2013-08-05 07:22:05 -05:00
|
|
|
local playNow = sel_play()
|
|
|
|
local changeLog = "* Set the default settings in 'mandy.cfg'\n"..
|
|
|
|
"* Can now select audio bitrate\n"..
|
|
|
|
"* Autoremove old video files from /tmp\n"..
|
|
|
|
"* Added option to play completed file\n"..
|
|
|
|
"- Still unknown bug with 'converting' bar\n"
|
2013-08-05 04:10:10 -05:00
|
|
|
|
2013-08-03 17:36:45 -05:00
|
|
|
|
2013-08-05 07:22:05 -05:00
|
|
|
res, url, format, bitRate, playNow, changeLog = iup.GetParam("Mandy 0.6.0 (alpha)", nil,
|
2013-07-31 02:29:11 -05:00
|
|
|
"Enter Youtube URL: %s\n"..
|
2013-08-05 04:10:10 -05:00
|
|
|
"Audio Options %t\n"..
|
|
|
|
"Select an audio format: %l|mp3|ogg|flac|\n"..
|
2013-08-05 18:41:16 -05:00
|
|
|
"Select the bitrate: %l|320 kbps|192 kbps|160 kbps|128 kbps|96 kbps|\n"..
|
2013-08-05 07:22:05 -05:00
|
|
|
"Play file when finished?: %l|no|yes|\n"..
|
|
|
|
"Changelog: %m\n",
|
|
|
|
url, format, bitRate, playNow, changeLog)
|
2013-08-03 17:36:45 -05:00
|
|
|
|
2013-08-05 07:22:05 -05:00
|
|
|
gPlay = ask_play(playNow)
|
2013-07-31 02:29:11 -05:00
|
|
|
gFormat = sel_Codec(format)
|
2013-08-05 04:10:10 -05:00
|
|
|
gBitrate = bit_logic(bitRate)
|
2013-07-27 11:51:07 -05:00
|
|
|
if res == true then
|
|
|
|
if string.match(url, "youtube.com/watch") then
|
|
|
|
return url
|
2013-07-26 22:49:41 -05:00
|
|
|
else
|
2013-07-27 11:51:07 -05:00
|
|
|
iup.Message("Error", "The URL is not a youtube link")
|
|
|
|
iup.Flush()
|
|
|
|
iup.Close()
|
2013-07-24 13:13:50 -05:00
|
|
|
end
|
2013-07-27 11:51:07 -05:00
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
2013-07-23 21:23:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-08-03 17:36:45 -05:00
|
|
|
-- checks mandy.cfg for format
|
|
|
|
function sel_format()
|
|
|
|
local format = cfg_table["format"]
|
|
|
|
if format == "mp3" then return 0
|
|
|
|
elseif format == "ogg" then return 1
|
|
|
|
elseif format == "flac" then return 2
|
|
|
|
else return 0
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-05 04:10:10 -05:00
|
|
|
function sel_bitrate()
|
|
|
|
local bitrate = cfg_table["bitrate"]
|
|
|
|
if bitrate == "320k" then return 0
|
|
|
|
elseif bitrate == "192k" then return 1
|
|
|
|
elseif bitrate == "160k" then return 2
|
|
|
|
elseif bitrate == "128k" then return 3
|
|
|
|
elseif bitrate == "96k" then return 4
|
|
|
|
elseif bitrate == "32k" then return 5
|
|
|
|
else return 0
|
|
|
|
end
|
|
|
|
end
|
2013-08-03 17:36:45 -05:00
|
|
|
|
2013-08-05 07:22:05 -05:00
|
|
|
function sel_play()
|
|
|
|
local playFile = cfg_table["playFile"]
|
|
|
|
if playFile == "no" then return 0
|
|
|
|
elseif playFile == "yes" then return 1
|
|
|
|
else return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-08-03 17:36:45 -05:00
|
|
|
|
2013-07-31 02:29:11 -05:00
|
|
|
--make format dropdown menu items work
|
|
|
|
function sel_Codec(x)
|
|
|
|
if x == 0 then
|
|
|
|
local mp3 = ".mp3"
|
|
|
|
print("Selected "..mp3)
|
|
|
|
return mp3
|
|
|
|
elseif x == 1 then
|
|
|
|
local ogg = ".ogg"
|
|
|
|
print("Selected "..ogg)
|
|
|
|
return ogg
|
|
|
|
elseif x == 2 then
|
|
|
|
local flac = ".flac"
|
|
|
|
print("Selected "..flac)
|
|
|
|
return flac
|
|
|
|
end
|
|
|
|
|
2013-07-23 21:23:31 -05:00
|
|
|
end
|
|
|
|
|
2013-08-05 04:10:10 -05:00
|
|
|
function bit_logic(x)
|
|
|
|
if x == 0 then
|
|
|
|
local b320k = "320k"
|
|
|
|
print ("Selected "..b320k)
|
|
|
|
return b320k
|
|
|
|
elseif x == 1 then
|
2013-08-05 07:22:05 -05:00
|
|
|
local b192k = "192k"
|
2013-08-05 04:10:10 -05:00
|
|
|
print ("Selected "..b192k)
|
|
|
|
return b192k
|
|
|
|
elseif x == 2 then
|
|
|
|
local b160k = "160k"
|
|
|
|
print ("Selected "..b160k)
|
|
|
|
return b160k
|
|
|
|
elseif x == 3 then
|
|
|
|
local b128k = "128k"
|
|
|
|
print ("Selected "..b128k)
|
|
|
|
return b128k
|
|
|
|
elseif x == 4 then
|
|
|
|
local b96k = "96k"
|
|
|
|
print ("Selected "..b96k)
|
|
|
|
return b96k
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-23 21:23:31 -05:00
|
|
|
--Ask user to set directory
|
|
|
|
function set_dir()
|
2013-07-31 02:29:11 -05:00
|
|
|
|
2013-07-27 11:51:07 -05:00
|
|
|
getPath = iup.filedlg{dialogtype = "SAVE", title="Save file...",
|
2013-07-31 02:29:11 -05:00
|
|
|
filter="*.mp3; *.ogg; *.flac",
|
2013-07-27 11:51:07 -05:00
|
|
|
directory=".",
|
2013-07-31 02:29:11 -05:00
|
|
|
file=""}
|
2013-07-23 21:23:31 -05:00
|
|
|
|
2013-07-27 11:51:07 -05:00
|
|
|
getPath:popup(iup.ANYWHERE, iup.ANYWHERE)
|
2013-07-23 21:23:31 -05:00
|
|
|
|
2013-07-27 11:51:07 -05:00
|
|
|
local status = getPath.status
|
2013-07-23 21:23:31 -05:00
|
|
|
|
2013-08-03 17:36:45 -05:00
|
|
|
-- The "%" is used to escape the "." comming from gFormat
|
2013-07-29 22:49:23 -05:00
|
|
|
if status == "1" or status == "0" then
|
2013-07-31 02:29:11 -05:00
|
|
|
if string.match(getPath.value, "%"..gFormat) then
|
2013-07-27 11:51:07 -05:00
|
|
|
local savedPath = getPath.value
|
|
|
|
return savedPath
|
2013-07-24 13:13:50 -05:00
|
|
|
|
2013-07-27 11:51:07 -05:00
|
|
|
else
|
2013-07-31 02:29:11 -05:00
|
|
|
local savedPath = getPath.value..gFormat
|
2013-07-27 11:51:07 -05:00
|
|
|
return savedPath
|
2013-07-24 13:13:50 -05:00
|
|
|
|
2013-07-27 11:51:07 -05:00
|
|
|
end
|
2013-07-23 21:23:31 -05:00
|
|
|
|
2013-07-27 11:51:07 -05:00
|
|
|
elseif status == "-1" then
|
2013-07-29 22:49:23 -05:00
|
|
|
return false
|
2013-07-27 11:51:07 -05:00
|
|
|
end
|
2013-07-23 21:23:31 -05:00
|
|
|
end
|
|
|
|
|
2013-07-26 21:07:19 -05:00
|
|
|
function ytDl(x)
|
|
|
|
local tmpName = math.random(0,999999999999)
|
|
|
|
local tmpNameTwo = math.random(0,999999999999)
|
2013-07-26 21:32:28 -05:00
|
|
|
local tmpPath = x.." --output=/tmp/youtube-dl-"..tmpName.."-"..tmpNameTwo..".flv"
|
2013-07-26 21:07:19 -05:00
|
|
|
local tmpPath2 = "/tmp/youtube-dl-"..tmpName.."-"..tmpNameTwo..".flv"
|
2013-08-05 04:10:10 -05:00
|
|
|
print(x)
|
2013-07-31 21:35:58 -05:00
|
|
|
local flag = popin.ytdl(tmpPath, tmpPath2)
|
2013-07-29 22:55:12 -05:00
|
|
|
if not flag then return false end
|
2013-07-29 22:49:23 -05:00
|
|
|
|
2013-07-26 21:07:19 -05:00
|
|
|
return tmpPath2
|
2013-07-23 21:23:31 -05:00
|
|
|
end
|
|
|
|
|
2013-07-31 02:29:11 -05:00
|
|
|
--optional function to implement autoplay
|
2013-07-31 21:35:58 -05:00
|
|
|
|
2013-08-05 18:07:14 -05:00
|
|
|
function ask_play(x)
|
2013-08-05 07:22:05 -05:00
|
|
|
if x == 0 then
|
2013-07-31 02:29:11 -05:00
|
|
|
return false
|
2013-08-05 07:22:05 -05:00
|
|
|
elseif x == 1 then
|
|
|
|
return true
|
2013-07-31 02:29:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-07-26 21:07:19 -05:00
|
|
|
function ffmpeg(tmpPath, dirD)
|
2013-07-31 21:35:58 -05:00
|
|
|
|
|
|
|
if gFormat == ".mp3" then gFormat = "libmp3lame" end
|
|
|
|
if gFormat == ".ogg" then gFormat = "libvorbis" end
|
|
|
|
if gFormat == ".flac" then gFormat = "flac" end
|
2013-08-08 16:02:57 -05:00
|
|
|
local subSymbols = string.gsub(dirD, "'", "")
|
|
|
|
local subSpaces = string.gsub(subSymbols, " ", "\\ ")
|
2013-08-05 04:10:10 -05:00
|
|
|
local codec = "ffmpeg -i "..tmpPath.." -acodec "..gFormat.." -ac 2 -ab "..gBitrate.." -vn -y "..subSpaces
|
2013-07-31 21:35:58 -05:00
|
|
|
|
|
|
|
local flag = convert_mp3.go(codec, tmpPath)
|
2013-07-31 02:29:11 -05:00
|
|
|
if not flag then return false end
|
|
|
|
|
2013-08-05 07:22:05 -05:00
|
|
|
io.popen("notify-send 'The file was saved to' "..subSpaces)
|
|
|
|
io.close()
|
|
|
|
if gPlay == true then
|
|
|
|
io.popen("xdg-open "..subSpaces)
|
|
|
|
io.close()
|
|
|
|
|
|
|
|
elseif gPlay == false then
|
|
|
|
print ("You chose not to open the file")
|
|
|
|
end
|
2013-07-23 21:23:31 -05:00
|
|
|
end
|
2013-07-27 11:51:07 -05:00
|
|
|
|
2013-07-23 21:23:31 -05:00
|
|
|
--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
|
|
|
|
|
2013-07-26 21:07:19 -05:00
|
|
|
global.path = function(url)
|
|
|
|
local yt = ytDl(url)
|
|
|
|
return yt
|
2013-07-23 21:23:31 -05:00
|
|
|
end
|
|
|
|
|
2013-07-26 21:07:19 -05:00
|
|
|
global.ffmpeg = function(tmpPath, saveDir)
|
|
|
|
local convert = ffmpeg(tmpPath, saveDir)
|
|
|
|
return convert
|
|
|
|
end
|
2013-07-23 21:23:31 -05:00
|
|
|
|
|
|
|
|