Cleaned code, fixed spaceing
This commit is contained in:
parent
66c890a06a
commit
cdfcbcc21f
@ -4,66 +4,57 @@ local cancelflag
|
||||
local downloadProgress
|
||||
|
||||
local function downloadStart(YtLink)
|
||||
cancelButton = iup.button{
|
||||
title = "Cancel",
|
||||
action = function()
|
||||
cancelflag = true
|
||||
end
|
||||
cancelButton = iup.button{
|
||||
title = "Cancel",
|
||||
action = function()
|
||||
cancelflag = true
|
||||
end
|
||||
|
||||
}
|
||||
|
||||
local downloadProgress = iup.progressbar{expand="HORIZONTAL", MARQUEE="YES"}
|
||||
local dlgProgress = iup.dialog{
|
||||
title = "converting",
|
||||
dialogframe = "YES", border = "YES",
|
||||
iup.vbox {
|
||||
downloadProgress,
|
||||
cancelButton,
|
||||
}
|
||||
local downloadProgress = iup.progressbar{expand="HORIZONTAL", MARQUEE="YES"}
|
||||
local dlgProgress = iup.dialog{
|
||||
title = "converting",
|
||||
dialogframe = "YES", border = "YES",
|
||||
iup.vbox {
|
||||
downloadProgress,
|
||||
cancelButton,
|
||||
}
|
||||
}
|
||||
dlgProgress.size = "QUARTERxEIGHT"
|
||||
dlgProgress.menubox = "NO"
|
||||
dlgProgress.close_cb = cancelButton.action
|
||||
dlgProgress:showxy(iup.CENTER, iup.CENTER)
|
||||
return dlgProgress
|
||||
}
|
||||
dlgProgress.size = "QUARTERxEIGHT"
|
||||
dlgProgress.menubox = "NO"
|
||||
dlgProgress.close_cb = cancelButton.action
|
||||
dlgProgress:showxy(iup.CENTER, iup.CENTER)
|
||||
return dlgProgress
|
||||
end
|
||||
|
||||
|
||||
local function DL_progress(YtLink)
|
||||
downloadStart()
|
||||
local pipe = io.popen(YtLink)
|
||||
--os.execute(YtLink)
|
||||
|
||||
repeat
|
||||
local c = pipe:read()
|
||||
if c then
|
||||
|
||||
iup.Flush()
|
||||
|
||||
iup.LoopStep()
|
||||
iup.Flush()
|
||||
if cancelflag then
|
||||
|
||||
iup.Message("Terminated", "You have canceled the conversion")
|
||||
iup.Flush()
|
||||
break
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
until not c
|
||||
pipe:close()
|
||||
iup.Close()
|
||||
return
|
||||
downloadStart()
|
||||
local pipe = io.popen(YtLink)
|
||||
|
||||
repeat
|
||||
local c = pipe:read()
|
||||
if c then
|
||||
iup.Flush()
|
||||
iup.LoopStep()
|
||||
iup.Flush()
|
||||
if cancelflag then
|
||||
iup.Message("Terminated", "You have canceled the conversion")
|
||||
iup.Flush()
|
||||
break
|
||||
end
|
||||
end
|
||||
until not c
|
||||
pipe:close()
|
||||
iup.Close()
|
||||
return
|
||||
end
|
||||
|
||||
convert_mp3 = {}
|
||||
convert_mp3.go = function(tubeLink)
|
||||
DL_progress(tubeLink)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
112
mandy.lua
112
mandy.lua
@ -1,93 +1,65 @@
|
||||
#!/usr/bin/lua5.2
|
||||
|
||||
--ffmpeg
|
||||
--libavcodec-extra-53 <-Ubuntu...suck it
|
||||
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
return false
|
||||
|
||||
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 = iup.filedlg{dialogtype = "SAVE", title="Save file...",
|
||||
filter="*.mp3", filterinfo="mp3",
|
||||
directory=".",
|
||||
file="*.mp3"}
|
||||
|
||||
getPath:popup(iup.ANYWHERE, iup.ANYWHERE)
|
||||
getPath:popup(iup.ANYWHERE, iup.ANYWHERE)
|
||||
|
||||
local status = getPath.status
|
||||
local status = getPath.status
|
||||
|
||||
if status == "1" then
|
||||
if string.match(getPath.value, ".mp3") then
|
||||
local savedPath = getPath.value
|
||||
return savedPath
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
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)
|
||||
@ -97,19 +69,17 @@ function ytDl(x)
|
||||
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
|
||||
--os.execute(mp3)
|
||||
convert_mp3.go(mp3)
|
||||
io.popen("notify-send 'The file was saved to' "..subSpaces)
|
||||
io.popen("xdg-open "..subSpaces)
|
||||
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 ()
|
||||
|
136
progress.lua
136
progress.lua
@ -1,97 +1,65 @@
|
||||
-- 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 cancelflag
|
||||
local downloadProgress
|
||||
|
||||
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 pTest = "1"
|
||||
downloadProgress = iup.progressbar{expand="HORIZONTAL"}
|
||||
dlgProgress = iup.dialog{ --create main window
|
||||
title = "Downloading.. ",
|
||||
dialogframe = "YES", border = "YES",
|
||||
iup.vbox { -- create vbox that contains said objects
|
||||
downloadProgress,
|
||||
cancelButton,
|
||||
pTest,
|
||||
}
|
||||
}
|
||||
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
|
||||
--create button with cancel flag
|
||||
local function downloadStart(YtLink)
|
||||
cancelButton = iup.button{
|
||||
title = "Cancel",
|
||||
action = function()
|
||||
cancelflag = true
|
||||
end}
|
||||
|
||||
downloadProgress = iup.progressbar{expand="HORIZONTAL"}
|
||||
dlgProgress = iup.dialog{
|
||||
title = "Downloading.. ",
|
||||
dialogframe = "YES", border = "YES",
|
||||
iup.vbox {
|
||||
downloadProgress,
|
||||
cancelButton,
|
||||
pTest,
|
||||
}
|
||||
}
|
||||
dlgProgress.size = "QUARTERxEIGHT"
|
||||
dlgProgress.menubox = "NO" -- no windows menus
|
||||
dlgProgress.close_cb = cancelButton.action
|
||||
dlgProgress:showxy(iup.CENTER, iup.CENTER)
|
||||
return dlgProgress
|
||||
end
|
||||
|
||||
|
||||
local function DL_progress(YtLink) -- monitor download progress
|
||||
downloadStart(YtLink) -- start the progress bar
|
||||
downloadProgress.value = 0
|
||||
local pipe = io.popen("youtube-dl " ..YtLink)
|
||||
repeat
|
||||
local c = pipe:read(20) -- read the first 20 characters of each line
|
||||
if c then -- if c is true then...
|
||||
|
||||
local b = string.match(c, '.....%%') -- %% in a string is "%"
|
||||
|
||||
-- string.match finds the percent sign and then finds every character
|
||||
-- for every dot you place. dots before grab before the character
|
||||
-- dots after grab after the character
|
||||
|
||||
--[[
|
||||
Perhaps do a different method
|
||||
round up and only update if number has changed
|
||||
-- didn't help at all, reverted to less code]]
|
||||
|
||||
|
||||
if b then
|
||||
|
||||
--here we take the last character off of the string
|
||||
--in this case it is the "percent" sign
|
||||
|
||||
local b = string.sub(b,0,-2)
|
||||
downloadProgress.value = b/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 download")
|
||||
iup.Flush()
|
||||
break
|
||||
-- start download, create progress bar, monitor progress
|
||||
local function DL_progress(YtLink)
|
||||
downloadStart(YtLink)
|
||||
downloadProgress.value = 0
|
||||
local pipe = io.popen("youtube-dl " ..YtLink)
|
||||
repeat
|
||||
local c = pipe:read(20) -- read the first 20 characters of each line
|
||||
if c then
|
||||
local b = string.match(c, '.....%%')
|
||||
|
||||
end
|
||||
if b then
|
||||
local b = string.sub(b,0,-2)
|
||||
downloadProgress.value = b/100 -- x out of 100
|
||||
iup.Flush()
|
||||
iup.LoopStep() --check for user input
|
||||
iup.Flush()
|
||||
if cancelflag then
|
||||
iup.Message("Terminated", "You have canceled the download")
|
||||
iup.Flush()
|
||||
break
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
until not c-- creating a loop until c is not true
|
||||
pipe:close() -- closing the ipopen
|
||||
--iup.Close()
|
||||
until not c
|
||||
pipe:close()
|
||||
end
|
||||
|
||||
popin = {}
|
||||
@ -99,11 +67,3 @@ popin.ytdl = 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)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user