aboutsummaryrefslogtreecommitdiff
path: root/lib/util.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lib/util.lua')
-rw-r--r--lib/util.lua50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/util.lua b/lib/util.lua
index a1de817..2ea4708 100644
--- a/lib/util.lua
+++ b/lib/util.lua
@@ -72,11 +72,61 @@ local error = function (str)
end
end
+local opensubtitles_hash = function (fileName)
+ local fil = io.open(fileName, "rb")
+ if not fil then
+ return nil
+ end
+
+ local lo,hi = 0,0
+ for i = 1,8192 do
+ local a,b,c,d = fil:read(4):byte(1,4)
+ lo = lo + a + b*256 + c*65536 + d*16777216
+ a,b,c,d = fil:read(4):byte(1,4)
+ hi = hi + a + b*256 + c*65536 + d*16777216
+ while lo >= 4294967296 do
+ lo = lo - 4294967296
+ hi = hi + 1
+ end
+ while hi >= 4294967296 do
+ hi = hi - 4294967296
+ end
+ end
+
+ local size = fil:seek("end", -65536) + 65536
+ for i = 1,8192 do
+ local a,b,c,d = fil:read(4):byte(1,4)
+ lo = lo + a + b*256 + c*65536 + d*16777216
+ a,b,c,d = fil:read(4):byte(1,4)
+ hi = hi + a + b*256 + c*65536 + d*16777216
+ while lo >= 4294967296 do
+ lo = lo - 4294967296
+ hi = hi + 1
+ end
+ while hi >= 4294967296 do
+ hi = hi - 4294967296
+ end
+ end
+
+ lo = lo + size
+ while lo >= 4294967296 do
+ lo = lo - 4294967296
+ hi = hi + 1
+ end
+ while hi >= 4294967296 do
+ hi = hi - 4294967296
+ end
+
+ fil:close()
+ return string.format("%08x%08x", hi,lo), size
+end
+
return {
table_merge = table_merge,
table_print = table_print,
table_match_or_any = table_match_or_any,
zip_ext_first = zip_ext_first,
string_rm_vid_ext = string_rm_vid_ext,
+ opensubtitles_hash = opensubtitles_hash,
error = error,
}