aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/curl.lua20
-rw-r--r--server/opensubtitles.lua21
-rw-r--r--server/subscene.lua22
3 files changed, 22 insertions, 41 deletions
diff --git a/lib/curl.lua b/lib/curl.lua
index 0728def..a832461 100644
--- a/lib/curl.lua
+++ b/lib/curl.lua
@@ -34,6 +34,26 @@ local get = function (url, headr, args)
return fetch, tonumber(scode)
end
+local zip_to_local_file = function (url, headr, out, retries)
+ local tries, hcode, zip, zcode
+
+ tries = 0
+ zip = os.tmpname()
+
+ repeat
+ _, hcode = get(url, headr, '-o ' .. zip)
+ tries = tries + 1
+ until hcode == 200 or tries > retries
+
+ if hcode == 200 then
+ zcode = util.zip_ext_first(zip, out)
+ end
+ os.remove(zip)
+
+ return (hcode == 200) and zcode
+end
+
return {
get = get,
+ zip_to_local_file = zip_to_local_file,
}
diff --git a/server/opensubtitles.lua b/server/opensubtitles.lua
index 9a5def4..a9f2199 100644
--- a/server/opensubtitles.lua
+++ b/server/opensubtitles.lua
@@ -134,32 +134,13 @@ local search_ohash = function (ohash)
end
end
-local sub_fetch = function(link, out)
- local tries, hcode, zip, zcode
-
- tries = 0
- zip = os.tmpname()
-
- repeat
- _, hcode = curl.get(link, nil, '-o ' .. zip)
- tries = tries + 1
- until hcode == 200 or tries > retries
-
- if hcode == 200 then
- zcode = util.zip_ext_first(zip, out)
- end
- os.remove(zip)
-
- return (hcode == 200) and zcode
-end
-
local search = function (path, out)
local ohash, link
ohash = util.opensubtitles_hash(path)
link = search_ohash(ohash)
if link then
- return sub_fetch(link, out)
+ return curl.zip_to_local_file(link, nil, out, retries)
end
end
diff --git a/server/subscene.lua b/server/subscene.lua
index 9daad3b..6f52d53 100644
--- a/server/subscene.lua
+++ b/server/subscene.lua
@@ -158,25 +158,6 @@ local link_fetch = function (id)
return link, (hcode == 200)
end
-local sub_fetch = function(link, out)
- local tries, hcode, zip, zcode
-
- tries = 0
- zip = os.tmpname()
-
- repeat
- _, hcode = curl.get(link, headr, '-o ' .. zip)
- tries = tries + 1
- until hcode == 200 or tries > retries
-
- if hcode == 200 then
- zcode = util.zip_ext_first(zip, out)
- end
- os.remove(zip)
-
- return (hcode == 200) and zcode
-end
-
local search = function (path, out)
local title, id, link, rc, key
@@ -200,7 +181,7 @@ local search = function (path, out)
return false
end
- rc = sub_fetch(link, out)
+ rc = curl.zip_to_local_file(link, headr, out, retries)
if not rc then
util.error('subscene: sub_fetch')
return false
@@ -213,6 +194,5 @@ return {
title_search = title_search,
id_fetch = id_fetch,
link_fetch = link_fetch,
- sub_fetch = sub_fetch,
search = search,
}