diff options
author | sinanmohd <sinan@sinanmohd.com> | 2023-10-07 19:18:20 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2023-10-07 19:18:20 +0530 |
commit | 5f5adabdeec7f2bf0897ef81fbc7e04dfed4b015 (patch) | |
tree | f408219d5ba3b46ba29efadea158405f76357be8 | |
parent | 048496da427917056c3331e3482590e59955b685 (diff) |
lib/util: init file_exists
-rw-r--r-- | lib/util.lua | 5 | ||||
-rw-r--r-- | main.lua | 6 | ||||
-rw-r--r-- | server/opensubtitles.lua | 11 |
3 files changed, 16 insertions, 6 deletions
diff --git a/lib/util.lua b/lib/util.lua index a4d3034..d52922d 100644 --- a/lib/util.lua +++ b/lib/util.lua @@ -11,6 +11,10 @@ local table_to_cmd = function (t) return str end +local file_exists = function (path) + return io.open(path, 'r') and true or false +end + local run = function (args) local sig, rc, stdout, cmd @@ -185,6 +189,7 @@ return { zip_ext_first = zip_ext_first, string_vid_path_to_name = string_vid_path_to_name, opensubtitles_hash = opensubtitles_hash, + file_exists = file_exists, run = run, error = error, } @@ -58,11 +58,11 @@ local sub_setup = function () path = mp.get_property_native('path') out = out .. '/' .. util.string_vid_path_to_name(path) .. '.srt' - if path:find('https?://') then + if not util.file_exists(path) then name = mp.get_property_native('media-title') - else - rc = opensubtitles.search(path, out) end + + rc = opensubtitles.search(path, out, name) if not rc then rc = subscene.search(path, out, name) end diff --git a/server/opensubtitles.lua b/server/opensubtitles.lua index 0bace8b..b797f44 100644 --- a/server/opensubtitles.lua +++ b/server/opensubtitles.lua @@ -134,11 +134,16 @@ local search_ohash = function (ohash) end end -local search = function (path, out) +local search = function (path, out, name) local ohash, link - ohash = util.opensubtitles_hash(path) - link = search_ohash(ohash) + if util.file_exists(path) then + ohash = util.opensubtitles_hash(path) + link = search_ohash(ohash) + else + name = name or util.string_vid_path_to_name(path) + end + if link then return curl.zip_link_to_file(link, nil, out, tries) end |