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