aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2023-10-08 14:36:33 +0530
committersinanmohd <sinan@sinanmohd.com>2023-10-08 14:36:33 +0530
commitf04e77faa68095bfe7fbe8883aad59aff157da02 (patch)
tree4baabb13b078bcc09d368cf4f53db92a1619fc4c
parent48700c12403ea1fc77d4fa6bd84ce1a208b876b0 (diff)
server/opensubtitles/search_ohash: use the new fuzzy search algorithm
-rw-r--r--lib/attr.lua22
-rw-r--r--server/opensubtitles.lua46
-rwxr-xr-xtests.lua5
3 files changed, 36 insertions, 37 deletions
diff --git a/lib/attr.lua b/lib/attr.lua
index 8c1613a..565f4c1 100644
--- a/lib/attr.lua
+++ b/lib/attr.lua
@@ -32,6 +32,8 @@ local build_dlim = function (name, attrs)
}
local series = {
'[Ss]%d%d?' .. dlim .. '[Ee]%d%d?',
+ '[Ss]%d%d?' .. dlim .. '[Ee][Pp]' .. dlim .. '%d%d?',
+ 'Season' .. dlim .. '%d%d?' .. dlim .. 'Episode' .. dlim .. '%d%d?'
}
local sizes = {
'%d%d%d' .. dlim .. '[Mm][Bb]',
@@ -171,9 +173,9 @@ local weigh = function (a1, a2)
local key_score, score
key_score = {
- name = 10,
- season = 10,
- episode = 10,
+ season = 15,
+ episode = 15,
+ title = 10,
source = 7,
scene = 5,
vcodec = 3,
@@ -184,16 +186,20 @@ local weigh = function (a1, a2)
score = 0
for k, v in pairs(a1) do
- if not a2[k] then
+ if not a2[k] or k == 'episode' then
goto continue
end
- if k == 'name' then
- for _, name in pairs(v) do
- if util.array_search(a2.name, name) then
- score = score + key_score.name
+ if k == 'title' then
+ for _, title in pairs(v) do
+ if util.array_search(a2.title, title) then
+ score = score + key_score.title
end
end
+ elseif k == 'season' then
+ if a1.season == a2.season and a1.episode == a2.episode then
+ score = score + key_score.season + key_score.episode
+ end
else
if v == a2[k] then
score = score + (key_score[k] or key_score.default)
diff --git a/server/opensubtitles.lua b/server/opensubtitles.lua
index f0c6195..d5b36e4 100644
--- a/server/opensubtitles.lua
+++ b/server/opensubtitles.lua
@@ -114,27 +114,6 @@ local language = 'english'
local domain = 'https://www.opensubtitles.org'
local tries = 10
-local search_ohash = function (ohash)
- local fetch, hcode, url, id
-
- url = domain .. '/en' .. '/search/sublanguageid-' ..
- languages[language] .. '/moviehash-' .. ohash
- fetch, hcode = curl.get(url, nil, nil, tries)
-
- id = fetch:match('/en/subtitleserve/sub/[^\n]*\n[^\n]*iduser%-0')
- if id then
- id = id:match('/en/subtitleserve/sub/%d*')
- end
-
- if hcode and not id then
- util.error('opensubtitles: search_ohash')
- end
-
- if id then
- return domain .. id
- end
-end
-
local ids_fetch = function (page)
local iter, no_name, line, id, name, tab
@@ -187,6 +166,23 @@ local ids_fetch = function (page)
return tab
end
+local search_ohash = function (ohash, name)
+ local fetch, hcode, url, id
+
+ url = domain .. '/en' .. '/search/sublanguageid-' ..
+ languages[language] .. '/moviehash-' .. ohash
+ fetch, hcode = curl.get(url, nil, nil, tries)
+
+ id = attr.fuzzy(name, ids_fetch(fetch))
+ if hcode and not id then
+ util.error('opensubtitles: search_ohash')
+ end
+
+ if id then
+ return domain .. '/en/subtitleserve/sub/' .. id
+ end
+end
+
local search_filesize = function (filesize, name)
local fetch, hcode, url, id, a
@@ -203,11 +199,8 @@ local search_filesize = function (filesize, name)
return nil
end
- print(url)
- util.table_print(ids_fetch(fetch))
id = attr.fuzzy(name, ids_fetch(fetch))
if id then
- print(domain .. '/en/subtitleserve/sub/' .. id)
return domain .. '/en/subtitleserve/sub/' .. id
end
end
@@ -215,13 +208,12 @@ end
local search = function (path, out, info)
local ohash, link, name
+ name = info.name or util.string_vid_path_to_name(path)
if util.file_exists(path) then
ohash = util.opensubtitles_hash(path)
- link = search_ohash(ohash)
+ link = search_ohash(ohash, name)
end
-
if not link then
- name = info.name or util.string_vid_path_to_name(path)
link = search_filesize(info.filesize, name)
end
diff --git a/tests.lua b/tests.lua
index f519964..cffcfc9 100755
--- a/tests.lua
+++ b/tests.lua
@@ -28,11 +28,12 @@ local test_subscene = function ()
end
local test_opensubtitles = function ()
- local ohash, id, new_id
+ local ohash, name, id, new_id
ohash = '395787dbe5b42001'
+ name = 'Fight.Club.1999.REMASTERED.720p.BRRip.XviD.AC3-RARBG'
id = '5449593'
- new_id = opensubtitles.search_ohash(ohash)
+ new_id = opensubtitles.search_ohash(ohash, name)
if new_id then
new_id = new_id:match('%d*$')
end