aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/opensubtitles.lua12
-rw-r--r--server/subscene.lua32
2 files changed, 14 insertions, 30 deletions
diff --git a/server/opensubtitles.lua b/server/opensubtitles.lua
index e9caf7b..0bace8b 100644
--- a/server/opensubtitles.lua
+++ b/server/opensubtitles.lua
@@ -111,18 +111,14 @@ local languages = {
local language = 'english'
local domain = 'https://www.opensubtitles.org'
-local retries = 10
+local tries = 10
local search_ohash = function (ohash)
- local fetch, tries, hcode, url, id
+ local fetch, hcode, url, id
url = domain .. '/en' .. '/search/sublanguageid-' ..
languages[language] .. '/moviehash-' .. ohash
- tries = 0
- repeat
- fetch, hcode = curl.get(url, nil, nil)
- tries = tries + 1
- until hcode == 200 or not hcode or tries > retries
+ fetch, hcode = curl.get(url, nil, nil, tries)
id = fetch:match('/en/subtitleserve/sub/[^\n]*\n[^\n]*iduser%-0')
if id then
@@ -144,7 +140,7 @@ local search = function (path, out)
ohash = util.opensubtitles_hash(path)
link = search_ohash(ohash)
if link then
- return curl.zip_link_to_file(link, nil, out, retries)
+ return curl.zip_link_to_file(link, nil, out, tries)
end
end
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