Added a cfg file, poorly.

This commit is contained in:
Logen Kain 2013-08-03 17:36:45 -05:00
parent 154958d5de
commit 5785087ee1
3 changed files with 32 additions and 3 deletions

2
main.lua Normal file → Executable file
View File

@ -1,6 +1,6 @@
#!/usr/bin/lua5.2 #!/usr/bin/lua5.2
require("mandy") require("mandy")
dofile("mandy.cfg")
function main() function main()
local url=global.url() local url=global.url()
if not url then return false end if not url then return false end

6
mandy.cfg Normal file
View File

@ -0,0 +1,6 @@
cfg_table = {
format = "ogg" -- 0 for mp3, 1 for ogg, 2 for flac
}

View File

@ -7,15 +7,24 @@ require('ffmpeg_progress')
--Main url entry box --Main url entry box
function url_entry() function url_entry()
local format = sel_format()
local url = "" local url = ""
local format = 0
res, url, format = iup.GetParam("Mandy 0.5.0 - Enter URL", nil, res, url, format = iup.GetParam("Mandy 0.5.0 - Enter URL", nil,
"Enter Youtube URL: %s\n".. "Enter Youtube URL: %s\n"..
"Select an audio format: %l|mp3|ogg|flac|\n", url, format) "Select an audio format: %l|mp3|ogg|flac|\n", url, format)
gFormat = sel_Codec(format) gFormat = sel_Codec(format)
if res == true then if res == true then
if string.match(url, "youtube.com/watch") then if string.match(url, "youtube.com/watch") then
local format_config = io.open("Config.txt", "w")
format_config:write("local format = "..format)
format_config:close()
return url return url
else else
iup.Message("Error", "The URL is not a youtube link") iup.Message("Error", "The URL is not a youtube link")
@ -28,6 +37,19 @@ function url_entry()
end end
-- checks mandy.cfg for format
function sel_format()
local format = cfg_table["format"]
if format == "mp3" then return 0
elseif format == "ogg" then return 1
elseif format == "flac" then return 2
else return 0
end
end
--make format dropdown menu items work --make format dropdown menu items work
function sel_Codec(x) function sel_Codec(x)
if x == 0 then if x == 0 then
@ -58,6 +80,7 @@ function set_dir()
local status = getPath.status local status = getPath.status
-- The "%" is used to escape the "." comming from gFormat
if status == "1" or status == "0" then if status == "1" or status == "0" then
if string.match(getPath.value, "%"..gFormat) then if string.match(getPath.value, "%"..gFormat) then
local savedPath = getPath.value local savedPath = getPath.value
@ -114,7 +137,7 @@ function ffmpeg(tmpPath, dirD)
local subSpaces = string.gsub(dirD, " ", "\\ ") local subSpaces = string.gsub(dirD, " ", "\\ ")
local codec = "ffmpeg -i "..tmpPath.." -acodec "..gFormat.." -ac 2 -ab 192k -y "..subSpaces local codec = "ffmpeg -i "..tmpPath.." -acodec "..gFormat.." -ac 2 -ab 192k -vn -y "..subSpaces
print(format) print(format)
local flag = convert_mp3.go(codec, tmpPath) local flag = convert_mp3.go(codec, tmpPath)