From 55e49cb31744c2fef297f2531fa914bd1b402ccf Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Mon, 4 Mar 2024 11:15:04 +0530 Subject: server/subscene: retire unreliable server and poor database --- README.md | 2 +- main.lua | 4 -- server/subscene.lua | 196 ---------------------------------------------------- tests.lua | 23 ------ 4 files changed, 1 insertion(+), 224 deletions(-) delete mode 100644 server/subscene.lua diff --git a/README.md b/README.md index a2c5c16..c30694e 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Dependencies TODO ---- - [ ] use language from slang and fall back to english -- [ ] deprecate subscene (unreliable servers and poor db) +- [x] deprecate subscene (unreliable servers and poor db) - [ ] add key binding to force subtitle lookup - [ ] implement text search on all severs - [ ] remove the default retries diff --git a/main.lua b/main.lua index 86abc4e..2609b65 100644 --- a/main.lua +++ b/main.lua @@ -1,6 +1,5 @@ local mutil = require 'mp.utils' local util = require 'lib.util' -local subscene = require 'server.subscene' local opensubtitles = require 'server.opensubtitles' local mkdir = function (path) @@ -64,9 +63,6 @@ local sub_setup = function () name = name, filesize = filesize }) - if not rc then - rc = subscene.search(path, out, name) - end if rc then mp.commandv('rescan_external_files') diff --git a/server/subscene.lua b/server/subscene.lua deleted file mode 100644 index b0692ff..0000000 --- a/server/subscene.lua +++ /dev/null @@ -1,196 +0,0 @@ -#!/usr/bin/env lua - -local curl = require 'lib.curl' -local util = require 'lib.util' -local attr = require 'lib.attr' - --- [[ languages supported by subscene ]] -- -local languages = { - ['arabic'] = 2, - ['bengali'] = 54, - ['brazillian-portuguese'] = 4, - ['chinese-bg-code'] = 7, - ['czech'] = 9, - ['danish'] = 10, - ['dutch'] = 11, - ['english'] = 13, - ['farsipersian'] = 46, - ['finnish'] = 17, - ['french'] = 18, - ['german'] = 19, - ['greek'] = 21, - ['hebrew'] = 22, - ['indonesian'] = 44, - ['italian'] = 26, - ['japanese'] = 27, - ['korean'] = 28, - ['malay'] = 50, - ['norwegian'] = 30, - ['polish'] = 31, - ['portuguese'] = 32, - ['romanian'] = 33, - ['spanish'] = 38, - ['swedish'] = 39, - ['thai'] = 40, - ['turkish'] = 41, - ['vietnamese'] = 45, - ['albanian'] = 1, - ['armenian'] = 73, - ['azerbaijani'] = 55, - ['basque'] = 74, - ['belarusian'] = 68, - ['big-5-code'] = 3, - ['bosnian'] = 60, - ['bulgarian'] = 5, - ['bulgarian_english'] = 6, - ['burmese'] = 61, - ['cambodian_khmer'] = 79, - ['catalan'] = 49, - ['croatian'] = 8, - ['dutch_english'] = 12, - ['english_german'] = 15, - ['esperanto'] = 47, - ['estonian'] = 16, - ['georgian'] = 62, - ['greenlandic'] = 57, - ['hindi'] = 51, - ['hungarian'] = 23, - ['hungarian_english'] = 24, - ['icelandic'] = 25, - ['kannada'] = 78, - ['kinyarwanda'] = 81, - ['kurdish'] = 52, - ['latvian'] = 29, - ['lithuanian'] = 43, - ['macedonian'] = 48, - ['malayalam'] = 64, - ['manipuri'] = 65, - ['mongolian'] = 72, - ['nepali'] = 80, - ['pashto'] = 67, - ['punjabi'] = 66, - ['russian'] = 34, - ['serbian'] = 35, - ['sinhala'] = 58, - ['slovak'] = 36, - ['slovenian'] = 37, - ['somali'] = 70, - ['sundanese'] = 76, - ['swahili'] = 75, - ['tagalog'] = 53, - ['tamil'] = 59, - ['telugu'] = 63, - ['ukrainian'] = 56, - ['urdu'] = 42, - ['yoruba'] = 71, -} - -local language = 'english' -local domain = 'https://subscene.com' -local headr = {['Cookie'] = 'LanguageFilter=' ..languages[language]} -local tries = 10 - -local title_search = function (key) - local url, args, fetch, hcode, title, rc - - url = domain .. '/subtitles/searchbytitle' - args = { '--data-raw', 'query=' .. key } - - fetch, hcode = curl.get(url, headr, args, tries) - title = fetch:match('href="/subtitles/[^"]*') - - if title then - title = title:gsub('href="', domain) - end - rc = (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) - local tab, id, name, fetch, hcode, iter, line - - fetch, hcode = curl.get(title, headr, nil, tries) - - tab = {} - iter = fetch:gmatch('[^\n\r]+') - while true do - line = iter() - if not line then - break - end - - id = line:match('/subtitles/[^/]*/[^/]*/%d*') - if id then - iter() - iter() - iter() - iter() - - name = iter():match('%S[^\n\r]*%S') - tab[name] = domain .. id - id = nil - end - end - - if hcode and tab == {} then - util.error('subscene: id_fetch') - end - - return tab -end - -local link_fetch = function (id) - local fetch, hcode, link, rc - - fetch, hcode = curl.get(id, headr, nil, tries) - - rc = (hcode == 200) - if rc then - link = domain .. fetch:match('/subtitles/[%l_-]*%-text/[^"]*') - end - - if hcode and not rc then - util.error('subscene: link_fetch') - end - - return link, rc -end - -local search = function (path, out, name) - local title, id, link, rc - - name = name or util.string_vid_path_to_name(path) - title, rc = title_search(name) - if not rc then - return false - end - - id = attr.fuzzy(name, id_fetch(title)) - if not id then - return false - end - - link, rc = link_fetch(id) - if not rc then - return false - end - - rc = curl.zip_link_to_file(link, headr, out, tries) - if not rc then - return false - end - - return true -end - -return { - title_search = title_search, - id_fetch = id_fetch, - link_fetch = link_fetch, - search = search, -} diff --git a/tests.lua b/tests.lua index 99aadcb..a9803f8 100755 --- a/tests.lua +++ b/tests.lua @@ -1,32 +1,10 @@ #!/usr/bin/env lua -local subscene = require 'server.subscene' local opensubtitles = require 'server.opensubtitles' local util = require 'lib.util' local errs = 0 -local test_subscene = function () - local out, ohash, path, rc - - out = os.tmpname() - path = './dir/Fight Club (1999) (1080p BluRay x265 10bit Tigole) [QxR].mp4' - ohash = 'ffec132e13e08f4c' - - rc = subscene.search(path, out) - if not rc then - util.error('subscene: fetch failed') - errs = errs + 1 - end - - if rc and ohash ~= util.opensubtitles_hash(out) then - util.error('subscene: hash mismatch') - errs = errs + 1 - end - - os.remove(out) -end - local test_opensubtitles = function () local ohash, name, id, new_id @@ -44,7 +22,6 @@ local test_opensubtitles = function () end end -test_subscene() test_opensubtitles() if errs == 0 then -- cgit v1.2.3