vlc | branch: master | Hugo Beauzée-Luyssen <h...@beauzee.fr> | Mon Apr 16 
17:17:27 2018 +0200| [c11a6535cc6915dc81a79daead0dd65654bf3336] | committer: 
Hugo Beauzée-Luyssen

VLSub: Clean & simplify hash calculation

Don't attempt to generate the hash by downloading the entire media in
case the stream isn't seekable.

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

 share/lua/extensions/VLSub.lua | 71 +++++++-----------------------------------
 1 file changed, 12 insertions(+), 59 deletions(-)

diff --git a/share/lua/extensions/VLSub.lua b/share/lua/extensions/VLSub.lua
index 79567d0153..c853d2a856 100644
--- a/share/lua/extensions/VLSub.lua
+++ b/share/lua/extensions/VLSub.lua
@@ -1334,74 +1334,27 @@ openSub = {
 
     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
-        dataTmp2 = data_end
-        data_end = file:read(chunk_size)
-        collectgarbage()
-      end
-      data_end = string.sub((dataTmp1..dataTmp2), -chunk_size)
-    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)
+    vlc.msg.dbg("[VLSub] Read hash data from stream")
 
-      -- "Seek" to the end
-      file:read(decal)
+    local file = vlc.stream(openSub.file.uri)
 
-      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")
-      local file = vlc.io.open(openSub.file.path, "rb")
-      if not file then
-        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
+    size = file:getsize()
+    data_start = file:read(chunk_size)
+    if not size then
+      vlc.msg.warn("[VLSub] Failed to get stream size")
+      return false
+    end
+    if not file:seek( size - chunk_size ) then
+      vlc.msg.warn("[VLSub] Failed to seek to the end of the stream")
+      return false
     end
+    data_end = file:read(chunk_size)
 
   -- Hash calculation
     local lo = size

_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to