Guest User

modified getMovieHash() displaying is_win flag value

a guest
May 13th, 2014
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.34 KB | None | 0 0
  1. getMovieHash = function()
  2.     -- Calculate movie hash
  3.         openSub.actionLabel = lang["action_hash"]
  4.         setMessage(openSub.actionLabel..": "..progressBarContent(0))
  5.        
  6.         local item = openSub.getInputItem()
  7.        
  8.         if not item then
  9.             setError(lang["mess_no_input"])
  10.             return false
  11.         end
  12.        
  13.         openSub.getFileInfo()
  14.            
  15.         if not openSub.file.path then
  16.             setError(lang["mess_not_found"])
  17.             return false
  18.         end
  19.        
  20.         local data_start = ""
  21.         local data_end = ""
  22.         local size
  23.         local chunk_size = 65536
  24.         local is_win = is_window_path(openSub.file.path)
  25. -- modified from here
  26.         if(is_win) then
  27.           vlc.msg.dbg("[VLSub] is_win true")
  28.         else
  29.           vlc.msg.dbg("[VLSub] is_win false")
  30.         end
  31. -- to here
  32.         local stat_size  = 0
  33.        
  34.         if openSub.file.stat then
  35.             stat_size = openSub.file.stat.size or 0
  36.         end
  37.                
  38.         -- Get data for hash calculation
  39.         if openSub.file.is_archive
  40.         or (is_win and stat_size > 2147483647)
  41.         then
  42.             vlc.msg.dbg("[VLSub] Read hash data from stream")
  43.        
  44.             local file = vlc.stream(openSub.file.uri)
  45.             local dataTmp1 = ""
  46.             local dataTmp2 = ""
  47.             size = chunk_size
  48.            
  49.             data_start = file:read(chunk_size)
  50.            
  51.             while data_end do
  52.                 size = size + string.len(data_end)
  53.                 dataTmp1 = dataTmp2
  54.                 dataTmp2 = data_end
  55.                 data_end = file:read(chunk_size)
  56.                 collectgarbage()
  57.             end
  58.             data_end = string.sub((dataTmp1..dataTmp2), -chunk_size)
  59.         elseif not file_exist(openSub.file.path)
  60.         and stat_size > 0 then
  61.             vlc.msg.dbg("[VLSub] Read hash data from stream")
  62.            
  63.             local file = vlc.stream(openSub.file.uri)
  64.            
  65.             if not file then
  66.                 vlc.msg.dbg("[VLSub] No stream")
  67.                 return false
  68.             end
  69.            
  70.             size = openSub.file.stat.size
  71.             local decal = size%chunk_size
  72.            
  73.             data_start = file:read(chunk_size)
  74.            
  75.             -- "Seek" to the end
  76.             file:read(decal)
  77.            
  78.             for i = 1, math.floor(((size-decal)/chunk_size))-2 do
  79.                 file:read(chunk_size)
  80.             end
  81.            
  82.             data_end = file:read(chunk_size)
  83.                
  84.             file = nil
  85.         else
  86.             vlc.msg.dbg("[VLSub] Read hash data from file (version 0.9.11b)")
  87.             local file = io.open( openSub.file.path, "rb")
  88.             if not file then
  89.                 vlc.msg.dbg("[VLSub] No stream")
  90.                 return false
  91.             end
  92.            
  93.             data_start = file:read(chunk_size)
  94.             size = file:seek("end", -chunk_size) + chunk_size
  95.             data_end = file:read(chunk_size)
  96.             file = nil
  97.         end
  98.        
  99.     -- Hash calculation
  100.         local lo = size
  101.         local hi = 0
  102.         local o,a,b,c,d,e,f,g,h
  103.         local hash_data = data_start..data_end
  104.         local max_size = 4294967296
  105.         local overflow
  106.        
  107.         for i = 1,  #hash_data, 8 do
  108.             a,b,c,d,e,f,g,h = hash_data:byte(i,i+7)
  109.             lo = lo + a + b*256 + c*65536 + d*16777216
  110.             hi = hi + e + f*256 + g*65536 + h*16777216
  111.            
  112.             if lo > max_size then
  113.                 overflow = math.floor(lo/max_size)
  114.                 lo = lo-(overflow*max_size)
  115.                 hi = hi+overflow
  116.             end
  117.            
  118.             if hi > max_size then
  119.                 overflow = math.floor(hi/max_size)
  120.                 hi = hi-(overflow*max_size)
  121.             end
  122.         end
  123.        
  124.         openSub.file.bytesize = size
  125.         openSub.file.hash = string.format("%08x%08x", hi,lo)
  126.         vlc.msg.dbg("[VLSub] Video hash: "..openSub.file.hash)
  127.         vlc.msg.dbg("[VLSub] Video bytesize: "..size)
  128.         vlc.msg.dbg("[VLSub] Video bytesize(stat_size): "..stat_size)
  129.         collectgarbage()
  130.         return true
  131.     end,
Add Comment
Please, Sign In to add comment