[vlc-commits] Add VLSub feature: Download multiple subtitles

Alon Sirota git at videolan.org
Mon Sep 14 09:30:03 CEST 2020


vlc | branch: master | Alon Sirota <sirotaalon at gmail.com> | Sun Sep  6 10:39:31 2020 +0300| [73ba0be8fac492b7fd91a6459c9c2f59d59d58b0] | committer: Hugo Beauzée-Luyssen

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 <hugo at beauzee.fr>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=73ba0be8fac492b7fd91a6459c9c2f59d59d58b0
---

 share/lua/extensions/VLSub.lua | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/share/lua/extensions/VLSub.lua b/share/lua/extensions/VLSub.lua
index 871a112b47..6dc67c0ff0 100644
--- a/share/lua/extensions/VLSub.lua
+++ b/share/lua/extensions/VLSub.lua
@@ -1429,12 +1429,13 @@ function display_subtitles()
     lang["mess_no_res"])
 end
 
-function get_first_sel(list)
+function get_all_sel(list)
   local selection = list:get_selection()
+  local indexes = {}
   for index, name in pairs(selection) do
-    return index
+    indexes[#indexes + 1] = index
   end
-  return 0
+  return indexes
 end
 
 function find_subtitle_in_archive(archivePath, subfileExt)
@@ -1444,7 +1445,7 @@ function find_subtitle_in_archive(archivePath, subfileExt)
     return nil
   end
   subfileExt = "." .. subfileExt
-  for _, item in pairs(items) do
+  for _, item in ipairs(items) do
     if string.sub(item:uri(), -string.len(subfileExt)) == subfileExt then
       return item:uri()
     end
@@ -1453,9 +1454,9 @@ function find_subtitle_in_archive(archivePath, subfileExt)
 end
 
 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"])
     return false
   end
@@ -1464,6 +1465,7 @@ function download_subtitles()
 
   display_subtitles() -- reset selection
 
+  for _, index in ipairs(indexes) do
   local item = openSub.itemStore[index]
 
   if openSub.option.downloadBehaviour == 'manual'
@@ -1580,6 +1582,7 @@ function download_subtitles()
   end
 
   setMessage(message)
+  end
 end
 
 function dump_zip(url, dir, subfileName)



More information about the vlc-commits mailing list