aboutsummaryrefslogtreecommitdiff
path: root/server/subscene.lua
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2023-10-04 08:54:28 +0530
committersinanmohd <sinan@sinanmohd.com>2023-10-04 08:54:28 +0530
commitf0d0eded1f9b7f2a244d414d09ad97e197601fab (patch)
tree49bf5024b16adb0140c6c30af9504306bbd55efd /server/subscene.lua
parent71f7b25ab3c8302972998714e98a5126cf1259e5 (diff)
lib/curl: move retry logic to curl from server
Diffstat (limited to 'server/subscene.lua')
-rw-r--r--server/subscene.lua32
1 files changed, 10 insertions, 22 deletions
diff --git a/server/subscene.lua b/server/subscene.lua
index 27fc1df..4c99e8a 100644
--- a/server/subscene.lua
+++ b/server/subscene.lua
@@ -87,21 +87,17 @@ local languages = {
local language = 'english'
local domain = 'https://subscene.com'
local headr = {['Cookie'] = 'LanguageFilter=' ..languages[language]}
-local retries = 10
+local tries = 10
local title_search = function (key)
- local url, args, fetch, hcode, tries, title, rc
+ local url, args, fetch, hcode, title, rc
url = domain .. '/subtitles/searchbytitle'
args = { '--data-raw', 'query=' .. key }
- tries = 0
- repeat
- fetch, hcode = curl.get(url, headr, args)
- tries = tries + 1
- until hcode == 200 or not hcode or tries > retries
-
+ fetch, hcode = curl.get(url, headr, args, tries)
title = fetch:match('href="/subtitles/[^"]*')
+
if title then
title = title:gsub('href="', domain)
end
@@ -115,13 +111,9 @@ local title_search = function (key)
end
local id_fetch = function (title)
- local tab, id, name, fetch, hcode, tries, iter, line
+ local tab, id, name, fetch, hcode, iter, line
- tries = 0
- repeat
- fetch, hcode = curl.get(title, headr, nil)
- tries = tries + 1
- until hcode == 200 or not hcode or tries > retries
+ fetch, hcode = curl.get(title, headr, nil, tries)
tab = {}
iter = fetch:gmatch('[^\n\r]+')
@@ -152,15 +144,11 @@ local id_fetch = function (title)
end
local link_fetch = function (id)
- local fetch, tries, hcode, link, rc
+ local fetch, 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
+ fetch, hcode = curl.get(id, headr, nil, tries)
+ rc = (hcode == 200)
if rc then
link = domain .. fetch:match('/subtitles/[%l_-]*%-text/[^"]*')
end
@@ -192,7 +180,7 @@ local search = function (path, out)
return false
end
- rc = curl.zip_link_to_file(link, headr, out, retries)
+ rc = curl.zip_link_to_file(link, headr, out, tries)
if not rc then
return false
end