From 31aaa823e80308cb5877e0abd8581ad2c23906f1 Mon Sep 17 00:00:00 2001 From: newt-sc <47229722+newt-sc@users.noreply.github.com> Date: Sun, 17 Nov 2024 18:08:04 +0200 Subject: [PATCH] release: v3.19.0 (#89) --- CHANGELOG.md | 5 +++++ a4kSubtitles/download.py | 6 +++++- a4kSubtitles/lib/request.py | 8 ++++++++ a4kSubtitles/lib/utils.py | 1 - a4kSubtitles/services/opensubtitles.py | 7 +++++-- a4kSubtitles/services/podnadpisi.py | 10 +++++++++- addon.xml | 7 ++++++- packages/addons.xml | 7 ++++++- packages/addons.xml.crc | 2 +- tests/test_suite.py | 9 +++++++++ 10 files changed, 54 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eac5fd8..3712846 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +* [v3.19.0](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-3.19.0): + * Lower OpenSubtitles token cache from 7 days to 1 day + * Fix auto download stopping after first failed subtitle download + * Fix wrong language set for results when multiple languages are configured (Thanks to @peno64) + * [v3.18.3](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-3.18.3): * Auto Download: Fix selecting incorrect episode in archive file diff --git a/a4kSubtitles/download.py b/a4kSubtitles/download.py index c80c31e..b6e1277 100644 --- a/a4kSubtitles/download.py +++ b/a4kSubtitles/download.py @@ -5,7 +5,11 @@ def __download(core, filepath, request): request['stream'] = True - with core.request.execute(core, request) as r: + response = core.request.execute(core, request) + if response.status_code >= 400: + raise Exception('Failed to download subtitle (HTTP: %s)' % response.status_code) + + with response as r: with open(filepath, 'wb') as f: core.shutil.copyfileobj(r.raw, f) diff --git a/a4kSubtitles/lib/request.py b/a4kSubtitles/lib/request.py index 7162aab..cd35335 100644 --- a/a4kSubtitles/lib/request.py +++ b/a4kSubtitles/lib/request.py @@ -48,6 +48,7 @@ def execute(core, request, progress=True, session=None): core.progress_dialog.open() next = request.pop('next', None) + error = request.pop('error', None) cfscrape = 'cfscrape' in request request.pop('cfscrape', None) @@ -103,4 +104,11 @@ def execute(core, request, progress=True, session=None): else: return None + if error and response.status_code >= 400: + next_request = error(response) + if next_request: + return execute(core, next_request, progress, session) + else: + return None + return response diff --git a/a4kSubtitles/lib/utils.py b/a4kSubtitles/lib/utils.py index 89fa033..0c8602e 100644 --- a/a4kSubtitles/lib/utils.py +++ b/a4kSubtitles/lib/utils.py @@ -97,7 +97,6 @@ def get_lang_ids(languages, lang_format=kodi.xbmc.ISO_639_2): if lang_id is not None: lang_ids.append(lang_id) - lang_ids.sort() return lang_ids except: return [] diff --git a/a4kSubtitles/services/opensubtitles.py b/a4kSubtitles/services/opensubtitles.py index ae02067..039b33b 100644 --- a/a4kSubtitles/services/opensubtitles.py +++ b/a4kSubtitles/services/opensubtitles.py @@ -8,7 +8,7 @@ __date_format = '%Y-%m-%d %H:%M:%S' def __set_api_headers(core, service_name, request, token_cache=None): - if token_cache is None: + if core.os.getenv('A4KSUBTITLES_TESTRUN') != 'true' and token_cache is None: cache = core.cache.get_tokens_cache() token_cache = cache.get(service_name, None) @@ -23,6 +23,9 @@ def __set_api_headers(core, service_name, request, token_cache=None): 'Content-Type': __content_type, }) + if core.os.getenv('A4KSUBTITLES_TESTRUN') == 'true': + return + if token_cache and 'token' in token_cache: request['headers']['Authorization'] = 'Bearer %s' % token_cache['token'] @@ -84,7 +87,7 @@ def parse_auth_response(core, service_name, response): token_cache = { 'token': token, 'base_url': base_url, - 'ttl': (core.datetime.now() + core.timedelta(days=7)).strftime(__date_format), + 'ttl': (core.datetime.now() + core.timedelta(days=1)).strftime(__date_format), } cache = core.cache.get_tokens_cache() diff --git a/a4kSubtitles/services/podnadpisi.py b/a4kSubtitles/services/podnadpisi.py index 0483373..c3d6a7e 100644 --- a/a4kSubtitles/services/podnadpisi.py +++ b/a4kSubtitles/services/podnadpisi.py @@ -81,9 +81,17 @@ def map_result(result): return list(map(map_result, results['data'])) def build_download_request(core, service_name, args): + def retry_download(response): + if response.status_code >= 500: + return { + 'method': 'GET', + 'url': args['url'] + } + request = { 'method': 'GET', - 'url': args['url'] + 'url': args['url'], + 'error': lambda r: retry_download(r), } return request diff --git a/addon.xml b/addon.xml index b75e8bf..a88db54 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ @@ -27,6 +27,11 @@ Supports: OpenSubtitles, BSPlayer, Podnadpisi.NET, SubDL, Addic7ed screenshot-03.png +[v3.19.0]: + * Lower OpenSubtitles token cache from 7 days to 1 day + * Fix auto download stopping after first failed subtitle download + * Fix wrong language set for results when multiple languages are configured (Thanks to @peno64) + [v3.18.3]: * Auto Download: Fix selecting incorrect episode in archive file diff --git a/packages/addons.xml b/packages/addons.xml index 804fb42..f56f541 100644 --- a/packages/addons.xml +++ b/packages/addons.xml @@ -4,7 +4,7 @@ @@ -30,6 +30,11 @@ Supports: OpenSubtitles, BSPlayer, Podnadpisi.NET, SubDL, Addic7ed screenshot-03.png +[v3.19.0]: + * Lower OpenSubtitles token cache from 7 days to 1 day + * Fix auto download stopping after first failed subtitle download + * Fix wrong language set for results when multiple languages are configured (Thanks to @peno64) + [v3.18.3]: * Auto Download: Fix selecting incorrect episode in archive file diff --git a/packages/addons.xml.crc b/packages/addons.xml.crc index e0b1062..e3f4143 100644 --- a/packages/addons.xml.crc +++ b/packages/addons.xml.crc @@ -1 +1 @@ -3d2a720b8944f1f1fe6b871888c89d0e4ba9141e +e4653147dbc1dd8b73199a37582b3db43aaf016b \ No newline at end of file diff --git a/tests/test_suite.py b/tests/test_suite.py index 40784ff..731a4b8 100644 --- a/tests/test_suite.py +++ b/tests/test_suite.py @@ -268,6 +268,9 @@ def test_opensubtitles(): assert len(search.results) == 20 + if a4ksubtitles_api.core.os.getenv('A4KSUBTITLES_TESTRUN') == 'true': + return + # download item = search.results[0] @@ -306,6 +309,9 @@ def test_opensubtitles_tvshow(): 'action_args': item['action_args'] } + if a4ksubtitles_api.core.os.getenv('A4KSUBTITLES_TESTRUN') == 'true': + return + filepath = a4ksubtitles_api.download(params, search.settings) assert filepath != '' @@ -329,6 +335,9 @@ def test_opensubtitles_unicode_tvshow(): 'action_args': item['action_args'] } + if a4ksubtitles_api.core.os.getenv('A4KSUBTITLES_TESTRUN') == 'true': + return + filepath = a4ksubtitles_api.download(params, search.settings) assert filepath != ''