diff --git a/TODO.txt b/TODO.txt index 739878b..26595f8 100644 --- a/TODO.txt +++ b/TODO.txt @@ -2,14 +2,15 @@ TODO: key: + = to add, - = to remove, x = completed, # = comment -+Append extensions to file name in save dialog unless exists +xAppend extensions to file name in save dialog unless exists +Add option for multiple audio formats +Dynamic libraries +Create custom url entry dialog -+Url validation +xUrl validation +Percentage in progress bar +Replace spaces in file name with dashes/underscores +Make cancel button exit in url dialog +Create dialog asking to play finished file or not +Display current action in progressbar instead of youtube link itself ++Fix progress bar cancel button #possibly more later diff --git a/ffmpeg_progress.lua b/ffmpeg_progress.lua new file mode 100644 index 0000000..ef26a8b --- /dev/null +++ b/ffmpeg_progress.lua @@ -0,0 +1,89 @@ +-- 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 downloadProgress = iup.progressbar{expand="HORIZONTAL", MARQUEE="YES"} + local dlgProgress = iup.dialog{ --create main window + title = YtLink, + dialogframe = "YES", border = "YES", + iup.vbox { -- create vbox that contains said objects + downloadProgress, + cancelButton, + } + } + 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(YtLink) + os.execute(YtLink) + --[[repeat + local c = pipe:read() -- read the first 20 characters of each line + if c then -- if c is true then... + + --downloadProgress.value = c/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 conversion") + iup.Flush() + break + + end + + end + + + + +until not c-- creating a loop until c is not true +pipe:close() -- closing the ipopen--]] +iup.Close() +end + +convert_mp3 = {} +convert_mp3.go = 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) + + diff --git a/main.lua b/main.lua old mode 100644 new mode 100755 index a0de8f8..4b3e63d --- a/main.lua +++ b/main.lua @@ -1,3 +1,4 @@ +#!/usr/bin/lua5.2 require("mandy") function main() diff --git a/mandy.lua b/mandy.lua index 4a60f7a..e858642 100644 --- a/mandy.lua +++ b/mandy.lua @@ -6,6 +6,7 @@ require("iuplua") require("iupluacontrols") require('progress') +require('ffmpeg_progress') --Main url entry box @@ -13,9 +14,17 @@ function url_entry() res, url = iup.GetParam("Mandy - Enter URL", nil, "Enter Youtube URL: %s\n", "") + 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 - return url end @@ -41,8 +50,16 @@ function set_dir() local status = getPath.status if status == "1" then - local savedPath = getPath.value - return savedPath + 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 @@ -78,18 +95,12 @@ function ytDl(x) end function ffmpeg(tmpPath, dirD) - - if dirD == dirD..".mp3" then - dirD = dirD - mp3 = "ffmpeg -i "..tmpPath.." -acodec libmp3lame -ac 2 -ab 192k -vn -y "..dirD.."" + + local mp3 = "ffmpeg -i "..tmpPath.." -acodec libmp3lame -ac 2 -ab 192k -vn -y "..dirD os.execute(mp3) + -- convert_mp3.go(mp3) io.popen("vlc "..dirD) - elseif dirD ~= dirD..".mp3" then - dirD = dirD..".mp3" - mp3 = "ffmpeg -i "..tmpPath.." -acodec libmp3lame -ac 2 -ab 192k -vn -y"..dirD.."" - os.execute(mp3) - io.popen("vlc "..dirD) - end + end --put everything into a table to use local functions globally diff --git a/test.lua b/test.lua new file mode 100644 index 0000000..c553181 --- /dev/null +++ b/test.lua @@ -0,0 +1,7 @@ +link = "http://www.youtube.com/watch?v=vGylDMu_0TU" + +print(string.match(link, "youtube.com/watch")) + + + +