aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/util.lua10
-rw-r--r--server/subscene.lua16
-rwxr-xr-xtests.lua5
3 files changed, 25 insertions, 6 deletions
diff --git a/lib/util.lua b/lib/util.lua
index 15221dd..a1de817 100644
--- a/lib/util.lua
+++ b/lib/util.lua
@@ -63,10 +63,20 @@ local string_rm_vid_ext = function (str)
return str
end
+local error = function (str)
+ str = 'error: ' .. str
+ if mp then
+ mp.msg.warn(str)
+ else
+ print(str)
+ end
+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,
+ error = error,
}
diff --git a/server/subscene.lua b/server/subscene.lua
index 70ec3c8..ccd4d9a 100644
--- a/server/subscene.lua
+++ b/server/subscene.lua
@@ -183,22 +183,30 @@ local search = function (key, out)
key = util.string_rm_vid_ext(key)
title, rc = title_search(key)
if not rc then
- return nil
+ util.error('err: subscene: title_search')
+ return false
end
id = id_fetch(title)
id = util.table_match_or_any(id, key)
if not id then
- return nil
+ util.error('subscene: table_match_or_any')
+ return false
end
link, rc = link_fetch(id)
if not rc then
- return nil
+ util.error('subscene: link_fetch')
+ return false
end
rc = sub_fetch(link, out)
- return rc
+ if not rc then
+ util.error('subscene: sub_fetch')
+ return false
+ end
+
+ return true
end
return {
diff --git a/tests.lua b/tests.lua
index d6ad81d..8033acb 100755
--- a/tests.lua
+++ b/tests.lua
@@ -1,6 +1,7 @@
#!/usr/bin/env lua
local subscene = require 'server/subscene'
+local util = require 'lib/util'
local errs = 0
@@ -17,12 +18,12 @@ local test_subscene = function ()
sha256 = 'fe88e2c1345a7daed82cb570952c13fae6a6867449f7dd5e719ea0a0c1e2e242'
if not subscene.search(name, out) then
- print('err: subscene: failed to fetch subtitles')
+ util.error('subscene: fetch failed')
errs = errs + 1
end
if not file_hash_verify(out, sha256) then
- print('err: subscene: subtitle hash mismatch')
+ util.error('subscene: hash mismatch')
errs = errs + 1
end