aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2023-10-02 16:20:37 +0530
committersinanmohd <sinan@sinanmohd.com>2023-10-02 16:20:37 +0530
commit18d923e2c36e0c901dc75e34c26b74bafa040e5c (patch)
tree1df0d0e5cd8cec33d630d497954ff3524e173a9a
parent50a50ffa59608838e21e63ba288f584be21a1c08 (diff)
repo: refactor error logging
-rw-r--r--lib/curl.lua15
-rw-r--r--server/opensubtitles.lua4
-rw-r--r--server/subscene.lua28
3 files changed, 33 insertions, 14 deletions
diff --git a/lib/curl.lua b/lib/curl.lua
index a152bd0..04ebf95 100644
--- a/lib/curl.lua
+++ b/lib/curl.lua
@@ -46,7 +46,7 @@ local get = function (url, headr, args)
end
local zip_link_to_file = function (url, headr, out, retries)
- local tries, hcode, zip, zcode
+ local tries, hcode, zip, rc
tries = 0
zip = os.tmpname()
@@ -54,14 +54,19 @@ local zip_link_to_file = function (url, headr, out, retries)
repeat
_, hcode = get(url, headr, { '-o'.. zip })
tries = tries + 1
- until hcode == 200 or tries > retries
+ until hcode == 200 or not hcode or tries > retries
+ rc = (hcode == 200)
- if hcode == 200 then
- zcode = util.zip_ext_first(zip, out)
+ if rc then
+ rc = util.zip_ext_first(zip, out)
end
os.remove(zip)
- return (hcode == 200) and zcode
+ if hcode and not rc then
+ util.error('curl: zip_link_to_file')
+ end
+
+ return rc
end
return {
diff --git a/server/opensubtitles.lua b/server/opensubtitles.lua
index 328e958..e9caf7b 100644
--- a/server/opensubtitles.lua
+++ b/server/opensubtitles.lua
@@ -129,6 +129,10 @@ local search_ohash = function (ohash)
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
diff --git a/server/subscene.lua b/server/subscene.lua
index 24ed4f8..27fc1df 100644
--- a/server/subscene.lua
+++ b/server/subscene.lua
@@ -90,7 +90,7 @@ local headr = {['Cookie'] = 'LanguageFilter=' ..languages[language]}
local retries = 10
local title_search = function (key)
- local url, args, fetch, hcode, tries, title
+ local url, args, fetch, hcode, tries, title, rc
url = domain .. '/subtitles/searchbytitle'
args = { '--data-raw', 'query=' .. key }
@@ -105,8 +105,13 @@ local title_search = function (key)
if title then
title = title:gsub('href="', domain)
end
+ rc = (hcode == 200 and title ~= nil)
- return title, (hcode == 200 and title ~= nil)
+ if hcode and not rc then
+ util.error('subscene: title_search')
+ end
+
+ return title, rc
end
local id_fetch = function (title)
@@ -139,23 +144,32 @@ local id_fetch = function (title)
end
end
+ if hcode and tab == {} then
+ util.error('subscene: id_fetch')
+ end
+
return tab
end
local link_fetch = function (id)
- local fetch, tries, hcode, link
+ local fetch, tries, hcode, link, rc
tries = 0
repeat
fetch, hcode = curl.get(id, headr, nil)
tries = tries + 1
until hcode == 200 or not hcode or tries > retries
+ rc = hcode == 200
- if hcode == 200 then
+ if rc then
link = domain .. fetch:match('/subtitles/[%l_-]*%-text/[^"]*')
end
- return link, (hcode == 200)
+ if hcode and not rc then
+ util.error('subscene: link_fetch')
+ end
+
+ return link, rc
end
local search = function (path, out)
@@ -164,26 +178,22 @@ local search = function (path, out)
key = util.string_vid_path_to_name(path)
title, rc = title_search(key)
if not rc then
- util.error('subscene: title_search')
return false
end
id = id_fetch(title)
id = util.table_match_or_any(id, key)
if not id then
- util.error('subscene: table_match_or_any')
return false
end
link, rc = link_fetch(id)
if not rc then
- util.error('subscene: link_fetch')
return false
end
rc = curl.zip_link_to_file(link, headr, out, retries)
if not rc then
- util.error('subscene: zip_link_to_file')
return false
end