[vlc-devel] [PATCH] VLSub: support for subtitles that SubFormat is different that subtitle estension Some subtitles in opensubtitles has attribute "SubFormat" different than the filename so they are not found in the downloaded archive. This patch checks for SubFileName first, so if proper subtitle is found, the "SubFormat" attribute is ignored. (srt=>sub, sub=>txt, mpl=>txt etc.)

Adrian Borkiet adrian.borkiet at gmail.com
Thu Aug 30 12:18:24 CEST 2018


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

diff --git a/share/lua/extensions/VLSub.lua b/share/lua/extensions/VLSub.lua
index ee9e5f84a9..b93a700c15 100644
--- a/share/lua/extensions/VLSub.lua
+++ b/share/lua/extensions/VLSub.lua
@@ -1437,12 +1437,17 @@ function get_first_sel(list)
   return 0
 end
 
-function find_subtitle_in_archive(archivePath, subfileExt)
+function find_subtitle_in_archive(archivePath, subfileExt, subFileName)
   local archive = vlc.directory_stream(vlc.strings.make_uri(archivePath))
   local items = archive:readdir()
   if not items then
     return nil
   end
+  for _, item in pairs(items) do
+    if string.sub(item:uri(), -string.len(subFileName)) == subFileName then
+      return item:uri()
+    end
+  end
   subfileExt = "." .. subfileExt
   for _, item in pairs(items) do
     if string.sub(item:uri(), -string.len(subfileExt)) == subfileExt then
@@ -1503,7 +1508,7 @@ function download_subtitles()
   end
   vlc.msg.dbg("[VLsub] tmpFileName: "..tmpFileName)
 
-  local subtitleMrl = find_subtitle_in_archive(tmpFileName, item.SubFormat)
+  local subtitleMrl = find_subtitle_in_archive(tmpFileName, item.SubFormat, item.SubFileName)
 
   if not subtitleMrl then
     setMessage( lang['mess_not_load'] )
-- 
2.17.1



More information about the vlc-devel mailing list