[vlc-devel] [PATCH 1/5] Add VLSub feature: Download multiple subtitles

Alon Sirota sirotaalon at gmail.com
Sun Sep 6 09:39:31 CEST 2020


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'.
---
 share/lua/extensions/VLSub.lua | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/share/lua/extensions/VLSub.lua b/share/lua/extensions/VLSub.lua
index 871a112..9ebc26f 100644
--- a/share/lua/extensions/VLSub.lua
+++ b/share/lua/extensions/VLSub.lua
@@ -1429,12 +1429,15 @@ 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 = {}
+    local i = 1 -- key counter
   for index, name in pairs(selection) do
-    return index
+      indexes[i] = index
+      i = i + 1
   end
-  return 0
+    return indexes
 end
 
 function find_subtitle_in_archive(archivePath, subfileExt)
@@ -1453,18 +1456,18 @@ function find_subtitle_in_archive(archivePath, subfileExt)
 end
 
 function download_subtitles()
-  local index = get_first_sel(input_table["mainlist"])
-
-  if index == 0 then
+    local indexes = get_all_sel(input_table["mainlist"])
+    if #indexes == 0 then -- if no subtitles selected
     setMessage(lang["mess_no_selection"])
     return false
   end
-
   openSub.actionLabel = lang["mess_downloading"]
 
   display_subtitles() -- reset selection
 
-  local item = openSub.itemStore[index]
+  -- for each subtitle index
+  for _, index in pairs(indexes) do
+    item = openSub.itemStore[index]
 
   if openSub.option.downloadBehaviour == 'manual'
   or not openSub.file.hasInput then
@@ -1581,6 +1584,7 @@ function download_subtitles()
 
   setMessage(message)
 end
+end
 
 function dump_zip(url, dir, subfileName)
   -- Dump zipped data in a temporary file
-- 
2.28.0



More information about the vlc-devel mailing list