aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/util.lua5
-rw-r--r--main.lua8
-rw-r--r--server/subscene.lua5
-rwxr-xr-xtests.lua6
4 files changed, 13 insertions, 11 deletions
diff --git a/lib/util.lua b/lib/util.lua
index 2ea4708..f3632f2 100644
--- a/lib/util.lua
+++ b/lib/util.lua
@@ -43,7 +43,7 @@ local zip_ext_first = function (zip, out)
return rc
end
-local string_rm_vid_ext = function (str)
+local string_vid_path_to_name = function (str)
local extensions = {
"mkv",
"mp4",
@@ -56,6 +56,7 @@ local string_rm_vid_ext = function (str)
"3gp"
}
+ str = str:match('[^/]*$')
for _, ext in ipairs(extensions) do
str = str:gsub('.' .. ext, '')
end
@@ -126,7 +127,7 @@ return {
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,
+ string_vid_path_to_name = string_vid_path_to_name,
opensubtitles_hash = opensubtitles_hash,
error = error,
}
diff --git a/main.lua b/main.lua
index 5b84e9e..f0ddf70 100644
--- a/main.lua
+++ b/main.lua
@@ -41,7 +41,7 @@ local sub_needed = function ()
end
local sub_setup = function ()
- local out, name
+ local out, name, path
mp.osd_message('fetching subtitle')
@@ -54,11 +54,11 @@ local sub_setup = function ()
end
mkdir(out)
- name = mp.get_property_native('path'):match('[^/]*$')
- name = util.string_rm_vid_ext(name)
+ path = mp.get_property_native('path')
+ name = util.string_vid_path_to_name(path)
out = out .. '/' .. name .. '.srt'
- if subscene.search(name, out) then
+ if subscene.search(path, out) then
mp.commandv('rescan_external_files')
mp.osd_message('fetch success')
else
diff --git a/server/subscene.lua b/server/subscene.lua
index 027f15a..9daad3b 100644
--- a/server/subscene.lua
+++ b/server/subscene.lua
@@ -177,9 +177,10 @@ local sub_fetch = function(link, out)
return (hcode == 200) and zcode
end
-local search = function (key, out)
- local title, id, link, rc
+local search = function (path, out)
+ local title, id, link, rc, key
+ key = util.string_vid_path_to_name(path)
title, rc = title_search(key)
if not rc then
util.error('err: subscene: title_search')
diff --git a/tests.lua b/tests.lua
index 76417d3..962a8c3 100755
--- a/tests.lua
+++ b/tests.lua
@@ -6,13 +6,13 @@ local util = require 'lib/util'
local errs = 0
local test_subscene = function ()
- local out, ohash, name, rc
+ local out, ohash, path, rc
out = os.tmpname()
- name = util.string_rm_vid_ext('Fight Club (1999) (1080p BluRay x265 10bit Tigole) [QxR].mp4')
+ path = './dir/Fight Club (1999) (1080p BluRay x265 10bit Tigole) [QxR].mp4'
ohash = 'ffec132e13e08f4c'
- rc = subscene.search(name, out)
+ rc = subscene.search(path, out)
if not rc then
util.error('subscene: fetch failed')
errs = errs + 1