#!/usr/bin/lua5.2 require("iuplua") require("iupluacontrols") require('progress') require('ffmpeg_progress') --Main url entry box function url_entry() res, url = iup.GetParam("Mandy 0.4 - Enter URL", nil, "Enter Youtube URL: %s\n", "") if res == true then 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 return false end 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=".", file="*.mp3"} getPath:popup(iup.ANYWHERE, iup.ANYWHERE) local status = getPath.status if status == "1" then if string.match(getPath.value, "%.mp3") then local savedPath = getPath.value return savedPath else local savedPath = getPath.value..".mp3" 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 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) local subSpaces = string.gsub(dirD, " ", "\\") local mp3 = "ffmpeg -i "..tmpPath.." -acodec libmp3lame -ac 2 -ab 192k -vn -y "..subSpaces convert_mp3.go(mp3) io.popen("notify-send 'The file was saved to' "..subSpaces) io.popen("xdg-open "..subSpaces) 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