failed at ffmpeg bar, now delete temp flv
This commit is contained in:
		| @@ -1,7 +1,11 @@ | ||||
| require ('iuplua') | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| local cancelflag		 | ||||
| local downloadProgress		 | ||||
| local ffmpeg_downloadProgress		 | ||||
|  | ||||
| local function downloadStart(YtLink) | ||||
|   cancelButton = iup.button{ | ||||
| @@ -12,12 +16,12 @@ local function downloadStart(YtLink) | ||||
|  | ||||
|   } | ||||
|    | ||||
|   local downloadProgress = iup.progressbar{expand="HORIZONTAL", MARQUEE="YES"}	 | ||||
|   local ffmpeg_downloadProgress = iup.progressbar{expand="HORIZONTAL", MARQUEE="YES"}	 | ||||
|   local dlgProgress = iup.dialog{				    | ||||
|   title = "converting", | ||||
|   dialogframe = "YES", border = "YES", | ||||
|   iup.vbox {			 | ||||
|     downloadProgress, | ||||
|     ffmpeg_downloadProgress, | ||||
|     cancelButton, | ||||
|     } | ||||
|   } | ||||
| @@ -29,33 +33,37 @@ local function downloadStart(YtLink) | ||||
| end | ||||
|  | ||||
|  | ||||
| local function DL_progress(YtLink)  | ||||
| local function DL_progress(YtLink, tmpPath)  | ||||
|   downloadStart() 		   | ||||
|   local pipe = io.popen(YtLink) | ||||
|    | ||||
|    | ||||
|    | ||||
|   repeat | ||||
|     local c = pipe:read()	   | ||||
|     if c then 		 | ||||
|       iup.Flush()		      | ||||
|       iup.LoopStep()  | ||||
|       iup.Flush()  | ||||
|        c = pipe:read(1) 		 | ||||
|        		      | ||||
|         iup.LoopStep()  | ||||
|       --  iup.Message("Terminated","You have failed")  | ||||
|  | ||||
|       if cancelflag then   | ||||
|        iup.Message("Terminated", "You have canceled the conversion")  | ||||
|        iup.Flush() | ||||
|        pipe:close() | ||||
|        iup.Flush() | ||||
|        dlgProgress:destroy() | ||||
|        return false  | ||||
|       end | ||||
|     end | ||||
|   until not c | ||||
|   pipe:close()  | ||||
|   iup.Close() | ||||
|      | ||||
|     until not c | ||||
|   dlgProgress:destroy() | ||||
|   pipe:close() | ||||
|   os.remove(tmpPath) | ||||
|   return true | ||||
| end | ||||
|  | ||||
| convert_mp3 = {} | ||||
| convert_mp3.go = function(tubeLink) | ||||
| local flag =  DL_progress(tubeLink) | ||||
| convert_mp3.go = function(tubeLink, tmpPath) | ||||
| local flag =  DL_progress(tubeLink, tmpPath) | ||||
| if not flag then return false else return true end | ||||
| end | ||||
|  | ||||
|   | ||||
							
								
								
									
										35
									
								
								mandy.lua
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								mandy.lua
									
									
									
									
									
								
							| @@ -80,21 +80,25 @@ function ytDl(x) | ||||
|   local tmpPath = x.." --output=/tmp/youtube-dl-"..tmpName.."-"..tmpNameTwo..".flv" | ||||
|   local tmpPath2 = "/tmp/youtube-dl-"..tmpName.."-"..tmpNameTwo..".flv" | ||||
|  | ||||
|   local flag = popin.ytdl(tmpPath) | ||||
|   local flag = popin.ytdl(tmpPath, tmpPath2) | ||||
|   if not flag then return false end | ||||
|    | ||||
|   return tmpPath2 | ||||
| end | ||||
|  | ||||
| --optional function to implement autoplay | ||||
|  | ||||
| function ask_play(x) | ||||
|   play = "" | ||||
|   local play = "" | ||||
|   res, play = iup.GetParam("Play now?", nil, | ||||
|                           "Do you want to play the file now? %t\n", play) | ||||
|                            "Do you want to play the file now? %t\n") | ||||
|  | ||||
|   if res == true then | ||||
|     io.popen("notify-send 'The file was saved to' "..x) | ||||
|     io.close() | ||||
|     io.popen("xdg-open "..x) | ||||
|     io.close() | ||||
|     return true | ||||
|   else | ||||
|     return false | ||||
|   end | ||||
| @@ -103,23 +107,22 @@ end | ||||
|  | ||||
|  | ||||
| function ffmpeg(tmpPath, dirD) | ||||
|    | ||||
|    if gFormat == ".mp3" then gFormat = "libmp3lame" end | ||||
|    if gFormat == ".ogg" then gFormat = "libvorbis" end  | ||||
|    if gFormat == ".flac" then gFormat = "flac" end | ||||
|  | ||||
|  | ||||
|   local subSpaces = string.gsub(dirD, " ", "\\ ") | ||||
|   local mp3 = "ffmpeg -i "..tmpPath.." -acodec libmp3lame -ac 2 -ab 192k -vn -y "..subSpaces | ||||
|   local ogg = "ffmpeg -i "..tmpPath.." -acodec libvorbis -ac 2 -ab 192k -vn -y "..subSpaces | ||||
|   local flac = "ffmpeg -i "..tmpPath.." -acodec flac -ac 2 -ab 192k -vn -y "..subSpaces | ||||
|    | ||||
|   if gFormat == ".mp3" then | ||||
|   local flag = convert_mp3.go(mp3) | ||||
|   elseif gFormat == ".ogg" then | ||||
|     local flag = convert_mp3.go(ogg) | ||||
|   elseif gFormat == ".flac" then | ||||
|    local flag = convert_mp3.go(flac) | ||||
|   else | ||||
|   local codec = "ffmpeg -i "..tmpPath.." -acodec "..gFormat.." -ac 2 -ab 192k -y "..subSpaces | ||||
|  | ||||
|   print(format)   | ||||
|   local flag = convert_mp3.go(codec, tmpPath) | ||||
|     if not flag then return false end | ||||
|  | ||||
|   end | ||||
|   io.popen("notify-send 'The file was saved to' "..subSpaces) | ||||
|   --end | ||||
|   --io.popen("notify-send 'The file was saved to' "..subSpaces) | ||||
|   ask_play(subSpaces) | ||||
| end | ||||
|  | ||||
| --put everything into a table to use local functions globally | ||||
|   | ||||
| @@ -31,7 +31,7 @@ end | ||||
|  | ||||
|  | ||||
| -- start download, create progress bar, monitor progress | ||||
| local function DL_progress(YtLink)   | ||||
| local function DL_progress(YtLink, tmpPath)   | ||||
|   downloadStart(YtLink) 		   | ||||
|   downloadProgress.value = 0   | ||||
|   local pipe = io.popen("youtube-dl " ..YtLink ) | ||||
| @@ -50,7 +50,9 @@ local function DL_progress(YtLink) | ||||
|           iup.Message("Terminated", "You have canceled the download")  | ||||
|           iup.Flush() | ||||
|           pipe:close() | ||||
|           os.remove(tmpPath..".part") | ||||
|           iup.Flush() | ||||
|           dlgProgress:destroy() | ||||
|           return false | ||||
|             | ||||
|         end | ||||
| @@ -62,13 +64,14 @@ local function DL_progress(YtLink) | ||||
|     end | ||||
|  | ||||
|   until not c | ||||
|   dlgProgress:destroy() | ||||
|   pipe:close() | ||||
|  return true  | ||||
| end | ||||
|  | ||||
| popin = {} | ||||
| popin.ytdl = function(tubeLink) | ||||
| local flag =  DL_progress(tubeLink) | ||||
| popin.ytdl = function(tubeLink, tmpPath) | ||||
| local flag =  DL_progress(tubeLink, tmpPath) | ||||
|   if not flag then return false else return true end | ||||
| end | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user