[vlc-commits] VLCSub: Remove trailing whitespaces
Hugo Beauzée-Luyssen
git at videolan.org
Thu Sep 21 17:49:40 CEST 2017
vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Thu Sep 21 10:49:04 2017 +0200| [1edecb7790cf63a58ea8066e768ed36abb45b49f] | committer: Hugo Beauzée-Luyssen
VLCSub: Remove trailing whitespaces
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1edecb7790cf63a58ea8066e768ed36abb45b49f
---
share/lua/extensions/VLSub.lua | 646 ++++++++++++++++++++---------------------
1 file changed, 323 insertions(+), 323 deletions(-)
diff --git a/share/lua/extensions/VLSub.lua b/share/lua/extensions/VLSub.lua
index 59646ec518..4ff2343f4d 100644
--- a/share/lua/extensions/VLSub.lua
+++ b/share/lua/extensions/VLSub.lua
@@ -3,7 +3,7 @@ VLSub Extension for VLC media player 1.1 and 2.0
Copyright 2013 Guillaume Le Maout
Authors: Guillaume Le Maout
-Contact:
+Contact:
http://addons.videolan.org/messages/?action=newmessage&username=exebetche
Bug report: http://addons.videolan.org/content/show.php/?content=148752
@@ -23,12 +23,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
--]]
- --[[ Global var ]]--
+ --[[ Global var ]]--
-- You can set here your default language by replacing nil with
--- your language code (see below).Example:
--- language = "fre",
--- language = "ger",
+-- your language code (see below).Example:
+-- language = "fre",
+-- language = "ger",
-- language = "eng",
-- ...
@@ -42,8 +42,8 @@ local options = {
intLang = 'eng',
translations_avail = {
eng = 'English',
- cze = 'Czech',
- dan = 'Danish',
+ cze = 'Czech',
+ dan = 'Danish',
dut = 'Nederlands',
fre = 'Français',
ell = 'Greek',
@@ -92,70 +92,70 @@ local options = {
int_os_username = 'Username',
int_os_password = 'Password',
int_help_mess =[[
- Download subtitles from
+ Download subtitles from
<a href='http://www.opensubtitles.org/'>
opensubtitles.org
</a> and display them while watching a video.<br>
<br>
<b><u>Usage:</u></b><br>
<br>
- Start your video. If you use Vlsub witout playing a video
- you will get a link to download the subtitles in your browser
+ Start your video. If you use Vlsub witout playing a video
+ you will get a link to download the subtitles in your browser
but the subtitles won't be saved and loaded automatically.<br>
<br>
- Choose the language for your subtitles and click on the
- button corresponding to one of the two research methods
+ Choose the language for your subtitles and click on the
+ button corresponding to one of the two research methods
provided by VLSub:<br>
<br>
<b>Method 1: Search by hash</b><br>
- It is recommended to try this method first, because it
- performs a research based on the video file print, so you
+ It is recommended to try this method first, because it
+ performs a research based on the video file print, so you
can find subtitles synchronized with your video.<br>
<br>
<b>Method 2: Search by name</b><br>
- If you have no luck with the first method, just check the
- title is correct before clicking. If you search subtitles
- for a series, you can also provide a season and episode
+ If you have no luck with the first method, just check the
+ title is correct before clicking. If you search subtitles
+ for a series, you can also provide a season and episode
number.<br>
<br>
<b>Downloading Subtitles</b><br>
Select one subtitle in the list and click on 'Download'.<br>
- It will be put in the same directory that your video, with
+ It will be put in the same directory that your video, with
the same name (different extension)
- so VLC will load them automatically the next time you'll
+ so VLC will load them automatically the next time you'll
start the video.<br>
<br>
- <b>/!\\ Beware :</b> Existing subtitles are overwritten
- without asking confirmation, so put them elsewhere if
+ <b>/!\\ Beware :</b> Existing subtitles are overwritten
+ without asking confirmation, so put them elsewhere if
they're important.<br>
<br>
- Find more VLC extensions at
+ Find more VLC extensions at
<a href='http://addons.videolan.org'>addons.videolan.org</a>.
]],
int_no_support_mess = [[
- <strong>VLSub is not working with Vlc 2.1.x on
+ <strong>VLSub is not working with Vlc 2.1.x on
any platform</strong>
- because the lua "net" module needed to interact
- with opensubtitles has been
+ because the lua "net" module needed to interact
+ with opensubtitles has been
removed in this release for the extensions.
<br>
<strong>Works with Vlc 2.2 on mac and linux.</strong>
<br>
- <strong>On windows you have to install an older version
+ <strong>On windows you have to install an older version
of Vlc (2.0.8 for example)</strong>
to use Vlsub:
<br>
- <a target="_blank" rel="nofollow"
+ <a target="_blank" rel="nofollow"
href="http://download.videolan.org/pub/videolan/vlc/2.0.8/">
http://download.videolan.org/pub/videolan/vlc/2.0.8/</a><br>
]],
-
+
action_login = 'Logging in',
action_logout = 'Logging out',
action_noop = 'Checking session',
action_search = 'Searching subtitles',
action_hash = 'Calculating movie hash',
-
+
mess_success = 'Success',
mess_error = 'Error',
mess_warn = 'Warning',
@@ -322,12 +322,12 @@ local lang_os_to_iso = {
local dlg = nil
local input_table = {} -- General widget id reference
-local select_conf = {} -- Drop down widget / option table association
+local select_conf = {} -- Drop down widget / option table association
--[[ VLC extension stuff ]]--
function descriptor()
- return {
+ return {
title = "VLsub 0.9.13",
version = "0.9.13",
author = "exebetche",
@@ -340,17 +340,17 @@ end
function activate()
vlc.msg.dbg("[VLsub] Welcome")
-
- if not check_config() then
+
+ if not check_config() then
vlc.msg.err("[VLsub] Unsupported VLC version")
- return false
+ return false
end
-
+
if vlc.input.item() then
openSub.getFileInfo()
openSub.getMovieInfo()
end
-
+
show_main()
end
@@ -361,18 +361,18 @@ end
function deactivate()
vlc.msg.dbg("[VLsub] Bye bye!")
if dlg then
- dlg:hide()
+ dlg:hide()
end
-
+
if openSub.session.token and openSub.session.token ~= "" then
openSub.request("LogOut")
end
end
function menu()
- return {
- lang.int_research,
- lang.int_config,
+ return {
+ lang.int_research,
+ lang.int_config,
lang.int_help
}
end
@@ -392,13 +392,13 @@ end
function interface_main()
dlg:add_label(lang["int_default_lang"]..':', 1, 1, 1, 1)
input_table['language'] = dlg:add_dropdown(2, 1, 2, 1)
- dlg:add_button(lang["int_search_hash"],
+ dlg:add_button(lang["int_search_hash"],
searchHash, 4, 1, 1, 1)
-
+
dlg:add_label(lang["int_title"]..':', 1, 2, 1, 1)
input_table['title'] = dlg:add_text_input(
openSub.movie.title or "", 2, 2, 2, 1)
- dlg:add_button(lang["int_search_name"],
+ dlg:add_button(lang["int_search_name"],
searchIMBD, 4, 2, 1, 1)
dlg:add_label(lang["int_season"]..':', 1, 3, 1, 1)
input_table['seasonNumber'] = dlg:add_text_input(
@@ -416,25 +416,25 @@ function interface_main()
dlg:add_button(
lang["int_dowload_sel"], download_subtitles, 3, 7, 1, 1)
dlg:add_button(
- lang["int_close"], deactivate, 4, 7, 1, 1)
-
+ lang["int_close"], deactivate, 4, 7, 1, 1)
+
assoc_select_conf(
'language',
'language',
- openSub.conf.languages,
- 2,
+ openSub.conf.languages,
+ 2,
lang["int_all"])
-
+
display_subtitles()
end
function set_interface_main()
-- Update movie title and co. if video input change
if not type(input_table['title']) == 'userdata' then return false end
-
+
openSub.getFileInfo()
openSub.getMovieInfo()
-
+
input_table['title']:set_text(
openSub.movie.title or "")
input_table['episodeNumber']:set_text(
@@ -449,10 +449,10 @@ function interface_config()
input_table['intLangBut'] = dlg:add_button(
lang["int_search_transl"],
get_available_translations, 2, 1, 1, 1)
- input_table['intLang'] = dlg:add_dropdown(3, 1, 1, 1)
+ input_table['intLang'] = dlg:add_dropdown(3, 1, 1, 1)
dlg:add_label(
lang["int_default_lang"]..':', 1, 2, 2, 1)
- input_table['default_language'] = dlg:add_dropdown(3, 2, 1, 1)
+ input_table['default_language'] = dlg:add_dropdown(3, 2, 1, 1)
dlg:add_label(
lang["int_dowload_behav"]..':', 1, 3, 2, 1)
input_table['downloadBehaviour'] = dlg:add_dropdown(3, 3, 1, 1)
@@ -462,7 +462,7 @@ function interface_config()
dlg:add_label(
lang["int_remove_tag"]..':', 1, 5, 0, 1)
input_table['removeTag'] = dlg:add_dropdown(3, 5, 1, 1)
-
+
if openSub.conf.dirPath then
if openSub.conf.os == "win" then
dlg:add_label(
@@ -477,31 +477,31 @@ function interface_config()
dlg :add_label(
lang["int_vlsub_work_dir"], 1, 6, 2, 1)
end
-
+
input_table['dir_path'] = dlg:add_text_input(
openSub.conf.dirPath, 2, 6, 2, 1)
-
+
dlg:add_label(
lang["int_os_username"]..':', 1, 7, 0, 1)
input_table['os_username'] = dlg:add_text_input(
- type(openSub.option.os_username) == "string"
+ type(openSub.option.os_username) == "string"
and openSub.option.os_username or "", 2, 7, 2, 1)
dlg:add_label(
lang["int_os_password"]..':', 1, 8, 0, 1)
input_table['os_password'] = dlg:add_text_input(
- type(openSub.option.os_password) == "string"
+ type(openSub.option.os_password) == "string"
and openSub.option.os_password or "", 2, 8, 2, 1)
-
+
input_table['message'] = nil
input_table['message'] = dlg:add_label(' ', 1, 9, 3, 1)
-
+
dlg:add_button(
lang["int_cancel"],
show_main, 2, 10, 1, 1)
dlg:add_button(
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(
@@ -510,7 +510,7 @@ function interface_config()
lang["int_bool_"..tostring(openSub.option.removeTag)], 1)
input_table['removeTag']:add_value(
lang["int_bool_"..tostring(not openSub.option.removeTag)], 2)
-
+
assoc_select_conf(
'intLang',
'intLang',
@@ -531,7 +531,7 @@ end
function interface_help()
local help_html = lang["int_help_mess"]
-
+
input_table['help'] = dlg:add_html(
help_html, 1, 1, 4, 1)
dlg:add_label(
@@ -542,7 +542,7 @@ end
function interface_no_support()
local no_support_html = lang["int_no_support_mess"]
-
+
input_table['no_support'] = dlg:add_html(
no_support_html, 1, 1, 4, 1)
dlg:add_label(
@@ -566,8 +566,8 @@ function trigger_menu(dlg_id)
openSub.conf.useragent..': '..lang["int_help"])
interface_help()
end
- collectgarbage() --~ !important
-end
+ collectgarbage() --~ !important
+end
function show_main()
trigger_menu(1)
@@ -584,15 +584,15 @@ end
function close_dlg()
vlc.msg.dbg("[VLSub] Closing dialog")
- if dlg ~= nil then
+ if dlg ~= nil then
--~ dlg:delete() -- Throw an error
- dlg:hide()
+ dlg:hide()
end
-
+
dlg = nil
input_table = nil
input_table = {}
- collectgarbage() --~ !important
+ collectgarbage() --~ !important
end
--[[ Drop down / config association]]--
@@ -610,18 +610,18 @@ function assoc_select_conf(select_id, option, conf, ind, default)
end
function set_default_option(select_id)
--- Put the selected option of a list in first place of the associated table
+-- Put the selected option of a list in first place of the associated table
local opt = select_conf[select_id].opt
local cfg = select_conf[select_id].cf
local ind = select_conf[select_id].ind
if openSub.option[opt] then
- table.sort(cfg, function(a, b)
+ table.sort(cfg, function(a, b)
if a[1] == openSub.option[opt] then
return true
elseif b[1] == openSub.option[opt] then
return false
else
- return a[ind] < b[ind]
+ return a[ind] < b[ind]
end
end)
end
@@ -634,11 +634,11 @@ function display_select(select_id)
local option = openSub.option[opt]
local default = select_conf[select_id].dflt
local default_isset = false
-
- if not default then
+
+ if not default then
default_isset = true
end
-
+
for k, l in ipairs(conf) do
if default_isset then
input_table[select_id]:add_value(l[2], k)
@@ -658,19 +658,19 @@ end
--[[ Config & interface localization]]--
function check_config()
- -- Make a copy of english translation to use it as default
+ -- Make a copy of english translation to use it as default
-- in case some element aren't translated in other translations
eng_translation = {}
for k, v in pairs(openSub.option.translation) do
eng_translation[k] = v
end
-
+
-- Get available translation full name from code
trsl_names = {}
for i, lg in ipairs(languages) do
trsl_names[lg[1]] = lg[2]
end
-
+
if is_window_path(vlc.config.datadir()) then
openSub.conf.os = "win"
slash = "\\"
@@ -678,17 +678,17 @@ function check_config()
openSub.conf.os = "lin"
slash = "/"
end
-
+
local path_generic = {"lua", "extensions", "userdata", "vlsub"}
local dirPath = slash..table.concat(path_generic, slash)
local filePath = slash.."vlsub_conf.xml"
local config_saved = false
sub_dir = slash.."vlsub_subtitles"
-
+
-- Check if config file path is stored in vlc config
local other_dirs = {}
-
- for path in
+
+ for path in
vlc.config.get("sub-autodetect-path"):gmatch("[^,]+") do
if path:match(".*"..sub_dir.."$") then
openSub.conf.dirPath = path:gsub(
@@ -697,10 +697,10 @@ function check_config()
end
table.insert(other_dirs, path)
end
-
+
-- if not stored in vlc config
- -- try to find a suitable config file path
-
+ -- try to find a suitable config file path
+
if openSub.conf.dirPath then
if not is_dir(openSub.conf.dirPath) and
(openSub.conf.os == "lin" or
@@ -710,7 +710,7 @@ function check_config()
else
local userdatadir = vlc.config.userdatadir()
local datadir = vlc.config.datadir()
-
+
-- check if the config already exist
if file_exist(userdatadir..dirPath..filePath) then
-- in vlc.config.userdatadir()
@@ -724,15 +724,15 @@ function check_config()
-- if not found determine an accessible path
local extension_path = slash..path_generic[1]
..slash..path_generic[2]
-
+
-- use the same folder as the extension if accessible
- if is_dir(userdatadir..extension_path)
+ if is_dir(userdatadir..extension_path)
and file_touch(userdatadir..dirPath..filePath) then
openSub.conf.dirPath = userdatadir..dirPath
elseif file_touch(datadir..dirPath..filePath) then
openSub.conf.dirPath = datadir..dirPath
end
-
+
-- try to create working dir in user folder
if not openSub.conf.dirPath
and is_dir(userdatadir) then
@@ -744,8 +744,8 @@ function check_config()
openSub.conf.dirPath = userdatadir..dirPath
end
end
-
- -- try to create working dir in vlc folder
+
+ -- try to create working dir in vlc folder
if not openSub.conf.dirPath and
is_dir(datadir) then
if not is_dir(datadir..dirPath) then
@@ -757,15 +757,15 @@ function check_config()
end
end
end
-
+
if openSub.conf.dirPath then
vlc.msg.dbg("[VLSub] Working directory: " ..
(openSub.conf.dirPath or "not found"))
-
- openSub.conf.filePath = openSub.conf.dirPath..filePath
+
+ openSub.conf.filePath = openSub.conf.dirPath..filePath
openSub.conf.localePath = openSub.conf.dirPath..slash.."locale"
-
- if config_saved
+
+ if config_saved
and file_exist(openSub.conf.filePath) then
vlc.msg.dbg(
"[VLSub] Loading config file: "..openSub.conf.filePath)
@@ -778,20 +778,20 @@ function check_config()
vlc.msg.dbg("[VLSub] Unable to save config")
end
end
-
- -- Check presence of a translation file
+
+ -- Check presence of a translation file
-- in "%vlsub_directory%/locale"
-- Add translation files to available translation list
local file_list = list_dir(openSub.conf.localePath)
local translations_avail = openSub.conf.translations_avail
-
+
if file_list then
for i, file_name in ipairs(file_list) do
local lg = string.gsub(
file_name,
"^(%w%w%w).xml$",
"%1")
- if lg
+ if lg
and not openSub.option.translations_avail[lg] then
table.insert(translations_avail, {
lg,
@@ -800,9 +800,9 @@ function check_config()
end
end
end
-
+
-- Load selected translation from file
- if openSub.option.intLang ~= "eng"
+ if openSub.option.intLang ~= "eng"
and not openSub.conf.translated
then
local transl_file_path = openSub.conf.localePath..
@@ -818,10 +818,10 @@ function check_config()
vlc.msg.dbg("[VLSub] Unable to find a suitable path"..
"to save config, please set it manually")
end
-
+
lang = nil
lang = options.translation -- just a short cut
-
+
if not vlc.net or not vlc.net.poll then
dlg = vlc.dialog(
openSub.conf.useragent..': '..lang["mess_error"])
@@ -829,16 +829,16 @@ function check_config()
dlg:show()
return false
end
-
+
SetDownloadBehaviours()
if not openSub.conf.dirPath then
setError(lang["mess_err_conf_access"])
end
-
- -- Set table list of available translations from assoc. array
+
+ -- Set table list of available translations from assoc. array
-- so it is sortable
-
- for k, l in pairs(openSub.option.translations_avail) do
+
+ for k, l in pairs(openSub.option.translations_avail) do
if k == openSub.option.int_research then
table.insert(openSub.conf.translations_avail, 1, {k, l})
else
@@ -857,7 +857,7 @@ function load_config()
tmpFile:flush()
tmpFile:close()
local option = parse_xml(resp)
-
+
for key, value in pairs(option) do
if type(value) == "table" then
if key == "translation" then
@@ -888,8 +888,8 @@ function load_transl(path)
tmpFile:flush()
tmpFile:close()
openSub.option.translation = nil
-
- openSub.option.translation = parse_xml(resp)
+
+ openSub.option.translation = parse_xml(resp)
collectgarbage()
end
@@ -903,9 +903,9 @@ function apply_translation()
end
function getenv_lang()
--- Retrieve the user OS language
+-- Retrieve the user OS language
local os_lang = os.getenv("LANG")
-
+
if os_lang then -- unix, mac
os_lang = string.sub(os_lang, 0, 2)
if type(lang_os_to_iso[os_lang]) then
@@ -919,7 +919,7 @@ function getenv_lang()
if v[2] == lang_w then
openSub.option.language = v[1]
end
- end
+ end
end
end
@@ -929,55 +929,55 @@ function apply_config()
local sel_val
local opt
local sel_cf
-
- if lg_sel and lg_sel ~= 1
+
+ if lg_sel and lg_sel ~= 1
and openSub.conf.translations_avail[lg_sel] then
local lg = openSub.conf.translations_avail[lg_sel][1]
set_translation(lg)
SetDownloadBehaviours()
end
-
+
for select_id, v in pairs(select_conf) do
- if input_table[select_id]
+ if input_table[select_id]
and select_conf[select_id] then
sel_val = input_table[select_id]:get_value()
sel_cf = select_conf[select_id]
opt = sel_cf.opt
-
+
if sel_val == 0 then
openSub.option[opt] = nil
else
openSub.option[opt] = sel_cf.cf[sel_val][1]
end
-
+
set_default_option(select_id)
end
end
-
-
+
+
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
end
-
+
if input_table["removeTag"]:get_value() == 2 then
openSub.option.removeTag = not openSub.option.removeTag
end
-
+
-- Set a custom working directory
local dir_path = input_table['dir_path']:get_text()
local dir_path_err = false
if trim(dir_path) == "" then dir_path = nil end
-
+
if dir_path ~= openSub.conf.dirPath then
- if openSub.conf.os == "lin"
- or is_win_safe(dir_path)
+ if openSub.conf.os == "lin"
+ or is_win_safe(dir_path)
or not dir_path then
local other_dirs = {}
-
- for path in
+
+ for path in
vlc.config.get(
"sub-autodetect-path"):gmatch("[^,]+"
) do
@@ -988,13 +988,13 @@ function apply_config()
end
openSub.conf.dirPath = dir_path
if dir_path then
- table.insert(other_dirs,
+ table.insert(other_dirs,
string.gsub(dir_path, "^(.-)[\\/]?$", "%1")..sub_dir)
-
+
if not is_dir(dir_path) then
mkdir_p(dir_path)
end
-
+
openSub.conf.filePath = openSub.conf.dirPath..
slash.."vlsub_conf.xml"
openSub.conf.localePath = openSub.conf.dirPath..
@@ -1018,7 +1018,7 @@ function apply_config()
"</b>")
end
end
-
+
if openSub.conf.dirPath and
not dir_path_err then
local config_saved = save_config()
@@ -1032,13 +1032,13 @@ function apply_config()
end
function save_config()
--- Dump local config into config file
+-- Dump local config into config file
if openSub.conf.dirPath
and openSub.conf.filePath then
vlc.msg.dbg(
"[VLSub] Saving config file: "..
openSub.conf.filePath)
-
+
if file_touch(openSub.conf.filePath) then
local tmpFile = assert(
io.open(openSub.conf.filePath, "wb"))
@@ -1061,8 +1061,8 @@ function save_config()
end
function SetDownloadBehaviours()
- openSub.conf.downloadBehaviours = nil
- openSub.conf.downloadBehaviours = {
+ openSub.conf.downloadBehaviours = nil
+ openSub.conf.downloadBehaviours = {
{'save', lang["int_dowload_save"]},
{'manual', lang["int_dowload_manual"]}
}
@@ -1070,24 +1070,24 @@ end
function get_available_translations()
-- Get all available translation files from the internet
--- (drop previous direct download from github repo
+-- (drop previous direct download from github repo
-- causing error with github https CA certficate on OS X an XP)
-- https://github.com/exebetche/vlsub/tree/master/locale
-
+
local translations_url = "http://addons.videolan.org/CONTENT/"..
"content-files/148752-vlsub_translations.xml"
-
- if input_table['intLangBut']:get_text() == lang["int_search_transl"]
+
+ if input_table['intLangBut']:get_text() == lang["int_search_transl"]
then
openSub.actionLabel = lang["int_searching_transl"]
-
+
local translations_content, lol = get(translations_url)
local translations_avail = openSub.option.translations_avail
all_trsl = parse_xml(translations_content)
local lg, trsl
-
+
for lg, trsl in pairs(all_trsl) do
- if lg ~= options.intLang[1]
+ if lg ~= options.intLang[1]
and not translations_avail[lg] then
translations_avail[lg] = trsl_names[lg] or ""
table.insert(openSub.conf.translations_avail, {
@@ -1099,7 +1099,7 @@ function get_available_translations()
#openSub.conf.translations_avail)
end
end
-
+
setMessage(success_tag(lang["mess_complete"]))
collectgarbage()
end
@@ -1108,14 +1108,14 @@ end
function set_translation(lg)
openSub.option.translation = nil
openSub.option.translation = {}
-
+
if lg == 'eng' then
for k, v in pairs(eng_translation) do
openSub.option.translation[k] = v
end
else
-- If translation file exists in /locale directory load it
- if openSub.conf.localePath
+ if openSub.conf.localePath
and file_exist(openSub.conf.localePath..
slash..lg..".xml") then
local transl_file_path = openSub.conf.localePath..
@@ -1139,11 +1139,11 @@ function set_translation(lg)
all_trsl = nil
end
end
-
+
lang = nil
lang = openSub.option.translation
collectgarbage()
-end
+end
--[[ Core ]]--
@@ -1189,22 +1189,22 @@ openSub = {
local params = openSub.methods[methodName].params()
local reqTable = openSub.getMethodBase(methodName, params)
local request = "<?xml version='1.0'?>"..dump_xml(reqTable)
- local host, path = parse_url(openSub.conf.url)
+ local host, path = parse_url(openSub.conf.url)
local header = {
- "POST "..path.." HTTP/1.0",
- "Host: "..host,
- "User-Agent: "..openSub.conf.userAgentHTTP,
- "Content-Type: text/xml",
+ "POST "..path.." HTTP/1.0",
+ "Host: "..host,
+ "User-Agent: "..openSub.conf.userAgentHTTP,
+ "Content-Type: text/xml",
"Content-Length: "..string.len(request),
"",
""
}
request = table.concat(header, "\r\n")..request
-
+
local response
local status, responseStr = http_req(host, 80, request)
-
- if status == 200 then
+
+ if status == 200 then
response = parse_xmlrpc(responseStr)
if response then
if response.status == "200 OK" then
@@ -1224,7 +1224,7 @@ openSub = {
end
elseif status == 401 then
setError("Request unauthorized")
-
+
response = parse_xmlrpc(responseStr)
if openSub.session.token ~= response.token then
setMessage("Session expired, retrying")
@@ -1232,22 +1232,22 @@ openSub = {
openSub.request(methodName)
end
return false
- elseif status == 503 then
+ elseif status == 503 then
setError("Server overloaded, please retry later")
return false
end
-
+
end,
getMethodBase = function(methodName, param)
if openSub.methods[methodName].methodName then
methodName = openSub.methods[methodName].methodName
end
-
+
local request = {
methodCall={
methodName=methodName,
params={ param=param }}}
-
+
return request
end,
methods = {
@@ -1258,7 +1258,7 @@ openSub = {
{ value={ string=openSub.option.os_username } },
{ value={ string=openSub.option.os_password } },
{ value={ string=openSub.movie.sublanguageid } },
- { value={ string=openSub.conf.useragent } }
+ { value={ string=openSub.conf.useragent } }
}
end,
callback = function(resp)
@@ -1271,7 +1271,7 @@ openSub = {
params = function()
openSub.actionLabel = lang["action_logout"]
return {
- { value={ string=openSub.session.token } }
+ { value={ string=openSub.session.token } }
}
end,
callback = function()
@@ -1282,7 +1282,7 @@ openSub = {
params = function()
openSub.actionLabel = lang["action_noop"]
return {
- { value={ string=openSub.session.token } }
+ { value={ string=openSub.session.token } }
}
end,
callback = function(resp)
@@ -1295,7 +1295,7 @@ openSub = {
openSub.actionLabel = lang["action_search"]
setMessage(openSub.actionLabel..": "..
progressBarContent(0))
-
+
return {
{ value={ string=openSub.session.token } },
{ value={
@@ -1304,13 +1304,13 @@ openSub = {
value={
struct={
member={
- { name="sublanguageid", value={
- string=openSub.movie.sublanguageid }
+ { name="sublanguageid", value={
+ string=openSub.movie.sublanguageid }
},
- { name="moviehash", value={
+ { name="moviehash", value={
string=openSub.file.hash } },
- { name="moviebytesize", value={
- double=openSub.file.bytesize } }
+ { name="moviebytesize", value={
+ double=openSub.file.bytesize } }
}}}}}}}
}
end,
@@ -1324,24 +1324,24 @@ openSub = {
openSub.actionLabel = lang["action_search"]
setMessage(openSub.actionLabel..": "..
progressBarContent(0))
-
+
local member = {
- { name="sublanguageid", value={
+ { name="sublanguageid", value={
string=openSub.movie.sublanguageid } },
- { name="query", value={
+ { name="query", value={
string=openSub.movie.title } } }
-
-
+
+
if openSub.movie.seasonNumber ~= nil then
- table.insert(member, { name="season", value={
+ table.insert(member, { name="season", value={
string=openSub.movie.seasonNumber } })
- end
-
+ end
+
if openSub.movie.episodeNumber ~= nil then
- table.insert(member, { name="episode", value={
+ table.insert(member, { name="episode", value={
string=openSub.movie.episodeNumber } })
- end
-
+ end
+
return {
{ value={ string=openSub.session.token } },
{ value={
@@ -1378,12 +1378,12 @@ openSub = {
file.uri = item:uri()
file.protocol = parsed_uri["protocol"]
file.path = parsed_uri["path"]
-
+
-- Corrections
-
+
-- For windows
file.path = string.match(file.path, "^/(%a:/.+)$") or file.path
-
+
-- For file in archive
local archive_path, name_in_archive = string.match(
file.path, '^([^!]+)!/([^!/]*)$')
@@ -1405,26 +1405,26 @@ openSub = {
file.dir, file.completeName = string.match(
file.path,
'^(.*/)([^/]*)$')
-
+
local file_stat = vlc.net.stat(file.path)
- if file_stat
+ if file_stat
then
file.stat = file_stat
end
-
+
file.is_archive = false
end
-
+
file.name, file.ext = string.match(
file.completeName,
'^([^/]-)%.?([^%.]*)$')
-
+
if file.ext == "part" then
file.name, file.ext = string.match(
file.name,
'^([^/]+)%.([^%.]+)$')
end
-
+
file.hasInput = true;
file.cleanName = string.gsub(
file.name,
@@ -1439,9 +1439,9 @@ openSub = {
openSub.movie.title = ""
openSub.movie.seasonNumber = ""
openSub.movie.episodeNumber = ""
- return false
+ return false
end
-
+
local showName, seasonNumber, episodeNumber = string.match(
openSub.file.cleanName,
"(.+)[sS](%d%d)[eE](%d%d).*")
@@ -1451,7 +1451,7 @@ openSub = {
openSub.file.cleanName,
"(.+)(%d)[xX](%d%d).*")
end
-
+
if showName then
openSub.movie.title = showName
openSub.movie.seasonNumber = seasonNumber
@@ -1468,37 +1468,37 @@ openSub = {
openSub.actionLabel = lang["action_hash"]
setMessage(openSub.actionLabel..": "..
progressBarContent(0))
-
+
local item = openSub.getInputItem()
-
+
if not item then
setError(lang["mess_no_input"])
return false
end
-
+
openSub.getFileInfo()
-
+
if not openSub.file.path then
setError(lang["mess_not_found"])
return false
end
-
+
local data_start = ""
local data_end = ""
local size
local chunk_size = 65536
-
+
-- Get data for hash calculation
if openSub.file.is_archive then
vlc.msg.dbg("[VLSub] Read hash data from stream")
-
+
local file = vlc.stream(openSub.file.uri)
local dataTmp1 = ""
local dataTmp2 = ""
size = chunk_size
-
+
data_start = file:read(chunk_size)
-
+
while data_end do
size = size + string.len(data_end)
dataTmp1 = dataTmp2
@@ -1507,31 +1507,31 @@ openSub = {
collectgarbage()
end
data_end = string.sub((dataTmp1..dataTmp2), -chunk_size)
- elseif not file_exist(openSub.file.path)
+ elseif not file_exist(openSub.file.path)
and openSub.file.stat then
vlc.msg.dbg("[VLSub] Read hash data from stream")
-
+
local file = vlc.stream(openSub.file.uri)
-
+
if not file then
vlc.msg.dbg("[VLSub] No stream")
return false
end
-
+
size = openSub.file.stat.size
local decal = size%chunk_size
-
+
data_start = file:read(chunk_size)
-
- -- "Seek" to the end
+
+ -- "Seek" to the end
file:read(decal)
-
+
for i = 1, math.floor(((size-decal)/chunk_size))-2 do
file:read(chunk_size)
end
-
+
data_end = file:read(chunk_size)
-
+
file = nil
else
vlc.msg.dbg("[VLSub] Read hash data from file")
@@ -1540,13 +1540,13 @@ openSub = {
vlc.msg.dbg("[VLSub] No stream")
return false
end
-
+
data_start = file:read(chunk_size)
size = file:seek("end", -chunk_size) + chunk_size
data_end = file:read(chunk_size)
file = nil
end
-
+
-- Hash calculation
local lo = size
local hi = 0
@@ -1554,24 +1554,24 @@ openSub = {
local hash_data = data_start..data_end
local max_size = 4294967296
local overflow
-
+
for i = 1, #hash_data, 8 do
a,b,c,d,e,f,g,h = hash_data:byte(i,i+7)
lo = lo + a + b*256 + c*65536 + d*16777216
hi = hi + e + f*256 + g*65536 + h*16777216
-
+
if lo > max_size then
overflow = math.floor(lo/max_size)
lo = lo-(overflow*max_size)
hi = hi+overflow
end
-
+
if hi > max_size then
overflow = math.floor(hi/max_size)
hi = hi-(overflow*max_size)
end
end
-
+
openSub.file.bytesize = size
openSub.file.hash = string.format("%08x%08x", hi,lo)
vlc.msg.dbg("[VLSub] Video hash: "..openSub.file.hash)
@@ -1580,7 +1580,7 @@ openSub = {
return true
end,
checkSession = function()
-
+
if openSub.session.token == "" then
openSub.request("LogIn")
else
@@ -1596,9 +1596,9 @@ function searchHash()
else
openSub.movie.sublanguageid = openSub.conf.languages[sel][1]
end
-
+
openSub.getMovieHash()
-
+
if openSub.file.hash then
openSub.checkSession()
openSub.request("SearchSubtitlesByHash")
@@ -1619,7 +1619,7 @@ function searchIMBD()
else
openSub.movie.sublanguageid = openSub.conf.languages[sel][1]
end
-
+
if openSub.movie.title ~= "" then
openSub.checkSession()
openSub.request("SearchSubtitles")
@@ -1630,12 +1630,12 @@ end
function display_subtitles()
local mainlist = input_table["mainlist"]
mainlist:clear()
-
- if openSub.itemStore == "0" then
+
+ if openSub.itemStore == "0" then
mainlist:add_value(lang["mess_no_res"], 1)
setMessage("<b>"..lang["mess_complete"]..":</b> "..
lang["mess_no_res"])
- elseif openSub.itemStore then
+ elseif openSub.itemStore then
for i, item in ipairs(openSub.itemStore) do
mainlist:add_value(
item.SubFileName..
@@ -1649,7 +1649,7 @@ end
function get_first_sel(list)
local selection = list:get_selection()
- for index, name in pairs(selection) do
+ for index, name in pairs(selection) do
return index
end
return 0
@@ -1672,19 +1672,19 @@ end
function download_subtitles()
local index = get_first_sel(input_table["mainlist"])
-
+
if index == 0 then
setMessage(lang["mess_no_selection"])
return false
end
-
- openSub.actionLabel = lang["mess_downloading"]
-
+
+ openSub.actionLabel = lang["mess_downloading"]
+
display_subtitles() -- reset selection
-
+
local item = openSub.itemStore[index]
-
- if openSub.option.downloadBehaviour == 'manual'
+
+ if openSub.option.downloadBehaviour == 'manual'
or not openSub.file.hasInput then
local link = "<span style='color:#181'>"
link = link.."<b>"..lang["mess_dowload_link"]..":</b>"
@@ -1692,27 +1692,27 @@ function download_subtitles()
link = link.."</span> <a href='"..
item.ZipDownloadLink.."'>"
link = link..item.MovieReleaseName.."</a>"
-
+
setMessage(link)
return false
end
-
+
local message = ""
local subfileName = openSub.file.name or ""
-
+
if openSub.option.langExt then
subfileName = subfileName.."."..item.SubLanguageID
end
-
+
subfileName = subfileName.."."..item.SubFormat
local tmp_dir
local file_target_access = true
-
+
if is_dir(openSub.file.dir) then
tmp_dir = openSub.file.dir
elseif openSub.conf.dirPath then
tmp_dir = openSub.conf.dirPath
-
+
message = "<br>"..warn_tag(lang["mess_save_warn"].." "..
"<a href='"..vlc.strings.make_uri(openSub.conf.dirPath).."'>"..
lang["mess_click_link"].."</a>")
@@ -1722,12 +1722,12 @@ function download_subtitles()
lang["mess_click_link"].."</a>")
return false
end
-
+
local tmpFileName = dump_zip(
- item.ZipDownloadLink,
- tmp_dir,
+ item.ZipDownloadLink,
+ tmp_dir,
item.SubFileName)
-
+
vlc.msg.dbg("[VLsub] tmpFileName: "..tmpFileName)
local subtitleMrl = find_subtitle_in_archive(tmpFileName, item.SubFormat)
@@ -1736,11 +1736,11 @@ function download_subtitles()
vlc.msg.err( "Failed to extract subtitle" )
return false
end
-
+
-- Determine if the path to the video file is accessible for writing
-
+
local target = openSub.file.dir..subfileName
-
+
if not file_touch(target) then
if openSub.conf.dirPath then
target = openSub.conf.dirPath..slash..subfileName
@@ -1756,37 +1756,37 @@ function download_subtitles()
return false
end
end
-
+
vlc.msg.dbg("[VLsub] Subtitles files: "..target)
-
- -- Unzipped data into file target
-
+
+ -- Unzipped data into file target
+
local stream = vlc.stream(subtitleMrl)
local data = ""
local subfile = io.open(target, "wb")
-
+
while data do
subfile:write(data)
data = stream:read(65536)
end
-
+
subfile:flush()
subfile:close()
-
+
stream = nil
collectgarbage()
-
+
if not os.remove(tmpFileName) then
vlc.msg.err("[VLsub] Unable to remove temp: "..tmpFileName)
end
-
+
-- load subtitles
- if add_sub(target) then
+ if add_sub(target) then
message = success_tag(lang["mess_loaded"]) .. message
else
message = error_tag(lang["mess_not_load"]) .. message
end
-
+
setMessage(message)
end
@@ -1794,18 +1794,18 @@ function dump_zip(url, dir, subfileName)
-- Dump zipped data in a temporary file
setMessage(openSub.actionLabel..": "..progressBarContent(0))
local resp = get(url)
-
- if not resp then
+
+ if not resp then
setError(lang["mess_no_response"])
- return false
+ return false
end
-
+
local tmpFileName = dir..subfileName..".gz"
if not file_touch(tmpFileName) then
return false
end
local tmpFile = assert(io.open(tmpFileName, "wb"))
-
+
tmpFile:write(resp)
tmpFile:flush()
tmpFile:close()
@@ -1868,18 +1868,18 @@ end
function get(url)
local host, path = parse_url(url)
local header = {
- "GET "..path.." HTTP/1.0",
- "Host: "..host,
+ "GET "..path.." HTTP/1.0",
+ "Host: "..host,
"User-Agent: "..openSub.conf.userAgentHTTP,
"",
""
}
local request = table.concat(header, "\r\n")
-
+
local response
local status, response = http_req(host, 80, request)
-
- if status == 200 then
+
+ if status == 200 then
return response
else
return false, status, response
@@ -1890,17 +1890,17 @@ function http_req(host, port, request)
local fd = vlc.net.connect_tcp(host, port)
if not fd then return false end
local pollfds = {}
-
+
pollfds[fd] = vlc.net.POLLIN
vlc.net.send(fd, request)
vlc.net.poll(pollfds)
-
+
local chunk = vlc.net.recv(fd, 2048)
local response = ""
local headerStr, header, body
local contentLength, status
local pct = 0
-
+
while chunk do
response = response..chunk
if not header then
@@ -1927,14 +1927,14 @@ function http_req(host, port, request)
end
vlc.net.close(fd)
-
- if status == 301
+
+ if status == 301
and header["Location"] then
local host, path = parse_url(trim(header["Location"]))
request = request
:gsub("^([^%s]+ )([^%s]+)", "%1"..path)
:gsub("(Host: )([^\n]*)", "%1"..host)
-
+
return http_req(host, port, request)
end
@@ -1943,23 +1943,23 @@ end
function parse_header(data)
local header = {}
-
+
for name, s, val in string.gmatch(
data,
"([^%s:]+)(:?)%s([^\n]+)\r?\n")
do
- if s == "" then
+ if s == "" then
header['statuscode'] = tonumber(string.sub(val, 1 , 3))
- else
+ else
header[name] = val
end
end
return header
-end
+end
function parse_url(url)
local url_parsed = vlc.strings.url_parse(url)
- return url_parsed["host"],
+ return url_parsed["host"],
url_parsed["path"],
url_parsed["option"]
end
@@ -1976,7 +1976,7 @@ function parse_xml(data)
local resolve_xml = vlc.strings.resolve_xml_special_chars
for op, tag, p, empty, val in string.gmatch(
- data,
+ data,
"[%s\r\n\t]*<(%/?)([%w:_]+)(.-)(%/?)>"..
"[%s\r\n\t]*([^<]*)[%s\r\n\t]*"
) do
@@ -2018,7 +2018,7 @@ function parse_xml(data)
end
end
end
-
+
collectgarbage()
return tree
end
@@ -2034,7 +2034,7 @@ function parse_xmlrpc(data)
table.insert(stack, tree)
for op, tag, p, empty, val in string.gmatch(
- data,
+ data,
"<(%/?)([%w:]+)(.-)(%/?)>[%s\r\n\t]*([^<]*)"
) do
if op=="/" then
@@ -2044,10 +2044,10 @@ function parse_xmlrpc(data)
table.remove(stack)
end
end
- elseif tag == "name" then
+ elseif tag == "name" then
level = level + 1
if val~= "" then tmpTag = resolve_xml(val) end
-
+
if type(stack[level][tmpTag]) == "nil" then
stack[level][tmpTag] = {}
table.insert(stack, stack[level][tmpTag])
@@ -2055,7 +2055,7 @@ function parse_xmlrpc(data)
tmp = nil
tmp = {}
table.insert(stack[level-1], tmp)
-
+
stack[level] = nil
stack[level] = tmp
table.insert(stack, tmp)
@@ -2071,7 +2071,7 @@ function parse_xmlrpc(data)
tmp = {}
table.insert(stack[level], tmp)
table.insert(stack, tmp)
- elseif val ~= "" then
+ elseif val ~= "" then
stack[level][tmpTag] = resolve_xml(val)
end
end
@@ -2084,21 +2084,21 @@ function dump_xml(data)
local stack = {}
local dump = ""
local convert_xml = vlc.strings.convert_xml_special_chars
-
+
local function parse(data, stack)
local data_index = {}
local k
local v
local i
local tb
-
+
for k,v in pairs(data) do
table.insert(data_index, {k, v})
table.sort(data_index, function(a, b)
- return a[1] < b[1]
+ return a[1] < b[1]
end)
end
-
+
for i,tb in pairs(data_index) do
k = tb[1]
v = tb[2]
@@ -2106,7 +2106,7 @@ function dump_xml(data)
dump = dump.."\r\n"..string.rep(
" ",
level)..
- "<"..k..">"
+ "<"..k..">"
table.insert(stack, k)
level = level + 1
elseif type(k)=="number" and k ~= 1 then
@@ -2115,7 +2115,7 @@ function dump_xml(data)
level-1)..
"<"..stack[level]..">"
end
-
+
if type(v)=="table" then
parse(v, stack)
elseif type(v)=="string" then
@@ -2125,7 +2125,7 @@ function dump_xml(data)
else
dump = dump..tostring(v)
end
-
+
if type(k)=="string" then
if type(v)=="table" then
dump = dump.."\r\n"..string.rep(
@@ -2137,7 +2137,7 @@ function dump_xml(data)
end
table.remove(stack)
level = level - 1
-
+
elseif type(k)=="number" and k ~= #data then
if type(v)=="table" then
dump = dump.."\r\n"..string.rep(
@@ -2163,9 +2163,9 @@ function make_uri(str)
local encode_uri = vlc.strings.encode_uri_component
local encodedPath = ""
for w in string.gmatch(str, "/([^/]+)") do
- encodedPath = encodedPath.."/"..encode_uri(w)
+ encodedPath = encodedPath.."/"..encode_uri(w)
end
-
+
if windowdrive then
return "file:///"..windowdrive..encodedPath
else
@@ -2174,38 +2174,38 @@ function make_uri(str)
end
function file_touch(name) -- test write ability
- if not name or trim(name) == ""
+ if not name or trim(name) == ""
then return false end
-
+
local f=io.open(name ,"w")
- if f~=nil then
- io.close(f)
- return true
- else
- return false
+ if f~=nil then
+ io.close(f)
+ return true
+ else
+ return false
end
end
function file_exist(name) -- test readability
- if not name or trim(name) == ""
+ if not name or trim(name) == ""
then return false end
local f=io.open(name ,"r")
- if f~=nil then
- io.close(f)
- return true
- else
- return false
+ if f~=nil then
+ io.close(f)
+ return true
+ else
+ return false
end
end
function is_dir(path)
- if not path or trim(path) == ""
+ if not path or trim(path) == ""
then return false end
-- Remove slash at the end or it won't work on Windows
path = string.gsub(path, "^(.-)[\\/]?$", "%1")
local f, _, code = io.open(path, "rb")
-
- if f then
+
+ if f then
_, _, code = f:read("*a")
f:close()
if code == 21 then
@@ -2214,23 +2214,23 @@ function is_dir(path)
elseif code == 13 then
return true
end
-
+
return false
end
function list_dir(path)
- if not path or trim(path) == ""
+ if not path or trim(path) == ""
then return false end
- local dir_list_cmd
+ local dir_list_cmd
local list = {}
if not is_dir(path) then return false end
-
+
if openSub.conf.os == "win" then
dir_list_cmd = io.popen('dir /b "'..path..'"')
elseif openSub.conf.os == "lin" then
dir_list_cmd = io.popen('ls -1 "'..path..'"')
end
-
+
if dir_list_cmd then
for filename in dir_list_cmd:lines() do
if string.match(filename, "^[^%s]+.+$") then
@@ -2244,7 +2244,7 @@ function list_dir(path)
end
function mkdir_p(path)
- if not path or trim(path) == ""
+ if not path or trim(path) == ""
then return false end
if openSub.conf.os == "win" then
os.execute('mkdir "' .. path..'"')
@@ -2263,12 +2263,12 @@ function is_window_path(path)
end
function is_win_safe(path)
- if not path or trim(path) == ""
+ if not path or trim(path) == ""
or not is_window_path(path)
then return false end
return string.match(path, "^%a?%:?[\\%w%p%s§¤]+$")
end
-
+
function trim(str)
if not str then return "" end
return string.gsub(str, "^[\r\n%s]*(.-)[\r\n%s]*$", "%1")
More information about the vlc-commits
mailing list