Skip to content

Commit

Permalink
Merge 463fe83 into 6810b5a
Browse files Browse the repository at this point in the history
  • Loading branch information
newt-sc committed Apr 8, 2022
2 parents 6810b5a + 463fe83 commit 0de7c8b
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* [v3.2.0](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-3.2.0):
* Option to disable subs encoding detection

* [v3.1.0](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-3.1.0):
* Force proper embedded subs selection based on preferred language overriding KODI
* Subs encoding fallback to predefined list in case auto detection fails
Expand Down
25 changes: 14 additions & 11 deletions a4kSubtitles/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,20 @@ def __postprocess(core, filepath, lang_code):
with open(filepath, 'rb') as f:
text_bytes = f.read()

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)
if detection['confidence'] == 1.0 or detected_lang_code == lang_code:
encoding = detection['encoding']

if not encoding:
encoding = core.utils.code_pages.get(lang_code, core.utils.default_encoding)

text = text_bytes.decode(encoding)
if core.kodi.get_bool_setting('general.use_chardet'):
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)
if detection['confidence'] == 1.0 or detected_lang_code == lang_code:
encoding = detection['encoding']

if not encoding:
encoding = core.utils.code_pages.get(lang_code, core.utils.default_encoding)

text = text_bytes.decode(encoding)
else:
text = text_bytes.decode(core.utils.default_encoding)

try:
if all(ch in text for ch in core.utils.cp1251_garbled):
Expand Down
1 change: 0 additions & 1 deletion a4kSubtitles/lib/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def __set_size_and_hash(core, meta, filepath):
__sum_64k_bytes(f, result)

meta.filehash = "%016x" % result.filehash
logger.notice(meta.filehash)
finally:
f.close()

Expand Down
2 changes: 1 addition & 1 deletion a4kSubtitles/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __query_service(core, service_name, meta, request, results):
core.logger.debug(lambda: core.json.dumps({
'url': request['url'],
'count': len(service_results),
'status_code': response.status_code
'status_code': response.status_code if response else 'N/A'
}, indent=2))
finally:
core.progress_text = core.progress_text.replace(service.display_name, '')
Expand Down
5 changes: 4 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.1.0"
version="3.2.0"
provider-name="Unknown">
<requires>
<import addon="script.module.requests"/>
Expand All @@ -27,6 +27,9 @@ Supports: OpenSubtitles, BSPlayer, Podnadpisi.NET, Subscene, Addic7ed
<screenshot>screenshot-03.png</screenshot>
</assets>
<news>
[v3.2.0]:
* Option to disable subs encoding detection

[v3.1.0]:
* Force proper embedded subs selection based on preferred language overriding KODI
* Subs encoding fallback to predefined list in case auto detection fails
Expand Down
5 changes: 4 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.1.0"
version="3.2.0"
provider-name="Unknown">
<requires>
<import addon="script.module.requests"/>
Expand All @@ -30,6 +30,9 @@ Supports: OpenSubtitles, BSPlayer, Podnadpisi.NET, Subscene, Addic7ed
<screenshot>screenshot-03.png</screenshot>
</assets>
<news>
[v3.2.0]:
* Option to disable subs encoding detection

[v3.1.0]:
* Force proper embedded subs selection based on preferred language overriding KODI
* Subs encoding fallback to predefined list in case auto detection fails
Expand Down
2 changes: 1 addition & 1 deletion packages/addons.xml.crc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fb5e52c161a624e3a552853ba87732e2a74f1939
6baf7dad65ef3a17be84eac6b4e44116e6c36dd4
4 changes: 4 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ msgctxt "#33104"
msgid "Auto download first subtitle silently"
msgstr ""

msgctxt "#33105"
msgid "Auto detect subs encoding"
msgstr ""

# Services
msgctxt "#33201"
msgid "OpenSubtitles"
Expand Down
1 change: 1 addition & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<setting id="general.results_limit" label="33102" type="slider" default="20" option="int" range="10,100"/>
<setting id="general.auto_search" label="33103" type="bool" default="false"/>
<setting id="general.auto_download" label="33104" type="bool" default="false" enable="eq(-1,true)"/>
<setting id="general.use_chardet" label="33105" type="bool" default="true" />
</category>
<!-- Services -->
<category label="33002">
Expand Down

0 comments on commit 0de7c8b

Please sign in to comment.