Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: v3.19.0 #89

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 5 additions & 1 deletion a4kSubtitles/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions a4kSubtitles/lib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion a4kSubtitles/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down
7 changes: 5 additions & 2 deletions a4kSubtitles/services/opensubtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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']

Expand Down Expand Up @@ -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()
Expand Down
10 changes: 9 additions & 1 deletion a4kSubtitles/services/podnadpisi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="service.subtitles.a4ksubtitles"
name="a4kSubtitles"
version="3.18.3"
version="3.19.0"
provider-name="Unknown">
<requires>
<import addon="script.module.requests"/>
Expand All @@ -27,6 +27,11 @@ Supports: OpenSubtitles, BSPlayer, Podnadpisi.NET, SubDL, Addic7ed
<screenshot>screenshot-03.png</screenshot>
</assets>
<news>
[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

Expand Down
7 changes: 6 additions & 1 deletion packages/addons.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<addons>
<addon id="service.subtitles.a4ksubtitles"
name="a4kSubtitles"
version="3.18.3"
version="3.19.0"
provider-name="Unknown">
<requires>
<import addon="script.module.requests"/>
Expand All @@ -30,6 +30,11 @@ Supports: OpenSubtitles, BSPlayer, Podnadpisi.NET, SubDL, Addic7ed
<screenshot>screenshot-03.png</screenshot>
</assets>
<news>
[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

Expand Down
2 changes: 1 addition & 1 deletion packages/addons.xml.crc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3d2a720b8944f1f1fe6b871888c89d0e4ba9141e
e4653147dbc1dd8b73199a37582b3db43aaf016b
9 changes: 9 additions & 0 deletions tests/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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 != ''
Expand All @@ -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 != ''
Expand Down