Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple options to language code in file name #98

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions vlsub.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
local options = {
language = nil,
downloadBehaviour = 'save',
langExt = false,
langExt = '0 chars',
removeTag = false,
showMediaInformation = true,
progressBarSize = 80,
Expand Down Expand Up @@ -91,6 +91,8 @@ local options = {
int_vlsub_work_dir = 'VLSub working directory',
int_os_username = 'Username',
int_os_password = 'Password',
int_language_code_2 = 'Yes (2 chars)',
int_language_code_3 = 'Yes (3 chars)',
int_help_mess =[[
Download subtitles from
<a href='http://www.opensubtitles.org/'>
Expand Down Expand Up @@ -500,10 +502,6 @@ function interface_config()
lang["int_save"],
apply_config, 3, 10, 1, 1)

input_table['langExt']:add_value(
lang["int_bool_"..tostring(openSub.option.langExt)], 1)
input_table['langExt']:add_value(
lang["int_bool_"..tostring(not openSub.option.langExt)], 2)
input_table['removeTag']:add_value(
lang["int_bool_"..tostring(openSub.option.removeTag)], 1)
input_table['removeTag']:add_value(
Expand All @@ -525,6 +523,8 @@ function interface_config()
'downloadBehaviour',
openSub.conf.downloadBehaviours,
1)

assoc_select_conf('langExt', 'langExt', openSub.conf.langExt, 1)
end

function interface_help()
Expand Down Expand Up @@ -833,6 +833,8 @@ function check_config()
setError(lang["mess_err_conf_access"])
end

set_language_code_file()

-- Set table list of available translations from assoc. array
-- so it is sortable

Expand Down Expand Up @@ -956,8 +958,15 @@ function apply_config()
openSub.option.os_username = input_table['os_username']:get_text()
openSub.option.os_password = input_table['os_password']:get_text()

if input_table["langExt"]:get_value() == 2 then
openSub.option.langExt = not openSub.option.langExt
if input_table["langExt"]:get_text() == lang["int_bool_false"] then
openSub.option.langExt = '0 chars'
elseif input_table["langExt"]:get_text() == lang["int_language_code_2"] then
openSub.option.langExt = '2 chars'
elseif input_table["langExt"]:get_text() == lang["int_language_code_3"] then
openSub.option.langExt = '3 chars'
else
vlc.msg.err("[VLSub] Unknown language extension: " ..
input_table["langExt"]:get_value())
end

if input_table["removeTag"]:get_value() == 2 then
Expand Down Expand Up @@ -1066,6 +1075,15 @@ function SetDownloadBehaviours()
}
end

function set_language_code_file() -- ap
openSub.conf.langExt = nil
openSub.conf.langExt = {
{ '0 chars', lang["int_bool_false"] },
{ '2 chars', lang["int_language_code_2"] },
{ '3 chars', lang["int_language_code_3"] }
}
end

function get_available_translations()
-- Get all available translation files from the internet
-- (drop previous direct download from github repo
Expand Down Expand Up @@ -1681,7 +1699,9 @@ function download_subtitles()
local message = ""
local subfileName = openSub.file.name or ""

if openSub.option.langExt then
if openSub.option.langExt == '2 chars' then
subfileName = subfileName.."."..get_key(lang_os_to_iso, item.SubLanguageID)
elseif openSub.option.langExt == '3 chars' then
subfileName = subfileName.."."..item.SubLanguageID
end

Expand Down Expand Up @@ -1789,6 +1809,16 @@ function dump_zip(url, dir, subfileName)
.."!/"..subfileName, tmpFileName
end

function get_key(table, value)
for k, v in pairs(table) do
if v == value then
return k
end
end

return nil
end

function add_sub(subPath)
if vlc.item or vlc.input.item() then
subPath = decode_uri(subPath)
Expand Down