Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getMovieHash = function()
- -- Calculate movie hash
- openSub.actionLabel = lang["action_hash"]
- setMessage(openSub.actionLabel..": "..progressBarContent(0))
- local item = openSub.getInputItem()
- if not item then
- setError(lang["mess_no_input"])
- return false
- end
- 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
- local is_win = is_window_path(openSub.file.path)
- -- modified from here
- if(is_win) then
- vlc.msg.dbg("[VLSub] is_win true")
- else
- vlc.msg.dbg("[VLSub] is_win false")
- end
- -- to here
- local stat_size = 0
- if openSub.file.stat then
- stat_size = openSub.file.stat.size or 0
- end
- -- Get data for hash calculation
- if openSub.file.is_archive
- or (is_win and stat_size > 2147483647)
- 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 stat_size > 0 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)
- -- "Seek" to the end
- file:read(decal)
- 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 (version 0.9.11b)")
- local file = 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
- end
- -- Hash calculation
- local lo = size
- local hi = 0
- local o,a,b,c,d,e,f,g,h
- local hash_data = data_start..data_end
- local max_size = 4294967296
- local overflow
- for i = 1, #hash_data, 8 do
- a,b,c,d,e,f,g,h = hash_data:byte(i,i+7)
- lo = lo + a + b*256 + c*65536 + d*16777216
- hi = hi + e + f*256 + g*65536 + h*16777216
- if lo > max_size then
- overflow = math.floor(lo/max_size)
- lo = lo-(overflow*max_size)
- hi = hi+overflow
- end
- if hi > max_size then
- overflow = math.floor(hi/max_size)
- hi = hi-(overflow*max_size)
- end
- end
- openSub.file.bytesize = size
- openSub.file.hash = string.format("%08x%08x", hi,lo)
- vlc.msg.dbg("[VLSub] Video hash: "..openSub.file.hash)
- vlc.msg.dbg("[VLSub] Video bytesize: "..size)
- vlc.msg.dbg("[VLSub] Video bytesize(stat_size): "..stat_size)
- collectgarbage()
- return true
- end,
Add Comment
Please, Sign In to add comment