Commit 73ba0be8 authored by Alon Sirota's avatar Alon Sirota Committed by Hugo Beauzée-Luyssen
Browse files

Add VLSub feature: Download multiple subtitles



All selected subtitles are now downloaded, instead of only one.

Change 'get_first_sel' function to return ALL selected subtitles
instead of only one, and refactored name to 'get_all_sel'.

Change 'download_subtitles' function to iterate over 'get_all_sel'
returned table instead of downloading the only subtitle from old
'get_first_sel'.

Signed-off-by: Hugo Beauzée-Luyssen's avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent 33226d20
...@@ -1429,12 +1429,13 @@ function display_subtitles() ...@@ -1429,12 +1429,13 @@ function display_subtitles()
lang["mess_no_res"]) lang["mess_no_res"])
end end
function get_first_sel(list) function get_all_sel(list)
local selection = list:get_selection() local selection = list:get_selection()
local indexes = {}
for index, name in pairs(selection) do for index, name in pairs(selection) do
return index indexes[#indexes + 1] = index
end end
return 0 return indexes
end end
function find_subtitle_in_archive(archivePath, subfileExt) function find_subtitle_in_archive(archivePath, subfileExt)
...@@ -1444,7 +1445,7 @@ function find_subtitle_in_archive(archivePath, subfileExt) ...@@ -1444,7 +1445,7 @@ function find_subtitle_in_archive(archivePath, subfileExt)
return nil return nil
end end
subfileExt = "." .. subfileExt subfileExt = "." .. subfileExt
for _, item in pairs(items) do for _, item in ipairs(items) do
if string.sub(item:uri(), -string.len(subfileExt)) == subfileExt then if string.sub(item:uri(), -string.len(subfileExt)) == subfileExt then
return item:uri() return item:uri()
end end
...@@ -1453,9 +1454,9 @@ function find_subtitle_in_archive(archivePath, subfileExt) ...@@ -1453,9 +1454,9 @@ function find_subtitle_in_archive(archivePath, subfileExt)
end end
function download_subtitles() function download_subtitles()
local index = get_first_sel(input_table["mainlist"]) local indexes = get_all_sel(input_table["mainlist"])
if index == 0 then if #indexes == 0 then -- if no subtitles selected
setMessage(lang["mess_no_selection"]) setMessage(lang["mess_no_selection"])
return false return false
end end
...@@ -1464,6 +1465,7 @@ function download_subtitles() ...@@ -1464,6 +1465,7 @@ function download_subtitles()
display_subtitles() -- reset selection display_subtitles() -- reset selection
for _, index in ipairs(indexes) do
local item = openSub.itemStore[index] local item = openSub.itemStore[index]
if openSub.option.downloadBehaviour == 'manual' if openSub.option.downloadBehaviour == 'manual'
...@@ -1580,6 +1582,7 @@ function download_subtitles() ...@@ -1580,6 +1582,7 @@ function download_subtitles()
end end
setMessage(message) setMessage(message)
end
end end
function dump_zip(url, dir, subfileName) function dump_zip(url, dir, subfileName)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment