Skip to content

Commit

Permalink
release: v3.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
newt-sc committed Dec 30, 2023
1 parent ced12a8 commit 3a02343
Show file tree
Hide file tree
Showing 47 changed files with 10,076 additions and 125 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
if: "!startsWith(needs.validate.outputs.commit, 'chore:')"
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.8.8

- name: install
if: "!startsWith(needs.validate.outputs.commit, 'chore:')"
Expand All @@ -47,6 +47,9 @@ jobs:
- name: test
if: "!startsWith(needs.validate.outputs.commit, 'chore:')"
env:
A4KSUBTITLES_OPENSUBTITLES_USERNAME: ${{ secrets.A4KSUBTITLES_OPENSUBTITLES_USERNAME }}
A4KSUBTITLES_OPENSUBTITLES_PASSWORD: ${{ secrets.A4KSUBTITLES_OPENSUBTITLES_PASSWORD }}
run: |
coverage run -m pytest -v
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cron-tests-addic7ed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.8.8

- name: install
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cron-tests-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.8.8

- name: install
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cron-tests-bsplayer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.8.8

- name: install
run: |
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/cron-tests-opensubtitles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ jobs:
- name: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.8.8

- name: install
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
- name: test
env:
A4KSUBTITLES_OPENSUBTITLES_USERNAME: ${{ secrets.A4KSUBTITLES_OPENSUBTITLES_USERNAME }}
A4KSUBTITLES_OPENSUBTITLES_PASSWORD: ${{ secrets.A4KSUBTITLES_OPENSUBTITLES_PASSWORD }}
run: |
pytest -v -k 'test_opensubtitles' ./tests/test_suite.py
2 changes: 1 addition & 1 deletion .github/workflows/cron-tests-podnadpisi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.8.8

- name: install
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cron-tests-search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.8.8

- name: install
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cron-tests-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.8.8

- name: install
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cron-tests-subscene.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.8.8

- name: install
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cron-tests-tvshow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.8.8

- name: install
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cron-update-data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.8.8

- name: install
run: |
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* [v3.8.0](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-3.8.0):
* Switch to new OpenSubtitles API.
Note: username and password are now mandatory for using OpenSubtitles.
* Fixes for Brazilian Portuguese language codes handling.

* [v3.7.0](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-3.7.0):
* New option to auto select and enable embedded subtitles (was previously always enabled)
* New option to prefer forced subtitles on auto selection (was previously always enabled)
Expand Down
2 changes: 1 addition & 1 deletion a4kSubtitles/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import hashlib
import re
import zipfile
from datetime import datetime
from datetime import datetime, timedelta
from base64 import b64encode
from xml.etree import ElementTree
from io import BytesIO
Expand Down
6 changes: 3 additions & 3 deletions a4kSubtitles/data/addic7ed/languages.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Cantonese": "64",
"Català": "12",
"Chinese (Simplified)": "41",
"Chinese (Traditional)": "24",
"Chinese": "24",
"Croatian": "31",
"Czech": "14",
"Danish": "30",
Expand Down Expand Up @@ -44,11 +44,11 @@
"Persian": "43",
"Polish": "21",
"Portuguese": "9",
"Portuguese (Brazilian)": "10",
"Portuguese (Brazil)": "10",
"Romanian": "26",
"Russian": "19",
"Serbian (Cyrillic)": "39",
"Serbian (Latin)": "36",
"Serbian": "36",
"Sinhala": "60",
"Slovak": "25",
"Slovenian": "22",
Expand Down
4 changes: 2 additions & 2 deletions a4kSubtitles/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __postprocess(core, filepath, lang_code):
encoding = ''
if core.utils.py3:
detection = core.utils.chardet.detect(text_bytes)
detected_lang_code = core.kodi.xbmc.convertLanguage(detection['language'], core.kodi.xbmc.ISO_639_2)
detected_lang_code = core.utils.get_lang_id(detection['language'], core.kodi.xbmc.ISO_639_2)
if detection['confidence'] == 1.0 or detected_lang_code == lang_code:
encoding = detection['encoding']

Expand Down Expand Up @@ -118,7 +118,7 @@ def download(core, params):
core.kodi.xbmcvfs.mkdirs(core.utils.temp_dir)

actions_args = params['action_args']
lang_code = core.kodi.xbmc.convertLanguage(actions_args['lang'], core.kodi.xbmc.ISO_639_2)
lang_code = core.utils.get_lang_id(actions_args['lang'], core.kodi.xbmc.ISO_639_2)
filename = __insert_lang_code_in_filename(core, actions_args['filename'], lang_code)
archivepath = core.os.path.join(core.utils.temp_dir, 'sub.zip')

Expand Down
7 changes: 7 additions & 0 deletions a4kSubtitles/lib/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
__meta_cache_filepath = os.path.join(kodi.addon_profile, 'last_meta.json')
__tvshow_years_cache_filepath = os.path.join(kodi.addon_profile, 'tvshow_years_cache.json')
__imdb_id_cache_filepath = os.path.join(kodi.addon_profile, 'imdb_id_cache.json')
__tokens_cache_filepath = os.path.join(kodi.addon_profile, 'tokens_cache.json')
results_filepath = os.path.join(kodi.addon_profile, 'last_results.json')

def __get_cache(filepath):
Expand Down Expand Up @@ -58,3 +59,9 @@ def get_imdb_id_cache():

def save_imdb_id_cache(data):
return __save_cache(__imdb_id_cache_filepath, data)

def get_tokens_cache():
return __get_cache(__tokens_cache_filepath)

def save_tokens_cache(data):
return __save_cache(__tokens_cache_filepath, data)
3 changes: 0 additions & 3 deletions a4kSubtitles/lib/kodi.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ def parse_language(language): # pragma: no cover
return language

def create_listitem(item): # pragma: no cover
if item['lang'] == 'Brazilian':
item['lang'] = 'Portuguese (Brazil)'

(item_name, item_ext) = os.path.splitext(item['name'])
item_name = item_name.replace('.', ' ')
item_ext = item_ext.upper()[1:]
Expand Down
8 changes: 5 additions & 3 deletions a4kSubtitles/lib/kodi_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from zipfile import ZipFile
from xml.etree import ElementTree
from .third_party import iso639

try: # pragma: no cover
from urlparse import unquote
Expand All @@ -21,9 +22,10 @@
xbmc.getCleanMovieTitle = lambda t: t
xbmc.getCondVisibility = lambda _: False

xbmc.convertLanguage = lambda l, f: l[:f].lower()
xbmc.ISO_639_1 = 2
xbmc.ISO_639_2 = 3
xbmc.convertLanguage = lambda l, f: iso639.Lang(l).asdict()[f]
xbmc.ISO_639_1 = 'pt1'
xbmc.ISO_639_2 = 'pt2t'
xbmc.ENGLISH_NAME = 'name'

__player = lambda: None
__player.getPlayingFile = lambda: ''
Expand Down
4 changes: 3 additions & 1 deletion a4kSubtitles/lib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ def __retry(core, request, response, next, cfscrape, retry=0):
if retry > 5:
return None

if response.status_code in [503, 429, 403]:
if response.status_code in [503, 429, 409, 403]:
if response.status_code == 503:
core.time.sleep(2)
retry = 5
if response.status_code == 429:
core.time.sleep(3)
if response.status_code == 409:
core.time.sleep(3)

retry += 1
request['validate'] = lambda response: __retry(core, request, response, next, cfscrape, retry)
Expand Down
21 changes: 21 additions & 0 deletions a4kSubtitles/lib/third_party/iso639/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 L.Beaudoux

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 19 additions & 0 deletions a4kSubtitles/lib/third_party/iso639/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from typing import Iterator

from .datafile import load_langs
from .iso639 import Lang

Lang = Lang


def iter_langs() -> Iterator[Lang]:
"""Iterate through all not deprecated ISO 639 languages
Yields
-------
Lang
Lang instances ordered alphabetically by name
"""
sorted_langs = load_langs()

return iter(sorted_langs)

0 comments on commit 3a02343

Please sign in to comment.