Skip to content

Commit

Permalink
Merge b1c2715 into 1dedf0a
Browse files Browse the repository at this point in the history
  • Loading branch information
newt-sc committed Jan 2, 2024
2 parents 1dedf0a + b1c2715 commit 8c63a91
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* [v3.11.0](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-3.11.0):
* Fix auto-selection and add debug logs.

* [v3.10.0](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-3.10.0):
* Small fix in SDH vs Forced flags checking.

Expand Down
75 changes: 47 additions & 28 deletions a4kSubtitles/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,49 +40,68 @@ def update_sub_stream():
sub_langs = [core.utils.get_lang_id(s, core.kodi.xbmc.ISO_639_2) for s in core.kodi.xbmc.Player().getAvailableSubtitleStreams()]

preferedlang_sub_indexes = [i for i, s in enumerate(sub_langs) if preferredlang_code == s]
core.logger.debug('player_props: %s' % player_props)
core.logger.debug('prefer_sdh: %s' % prefer_sdh)
core.logger.debug('prefer_forced: %s' % prefer_forced)
core.logger.debug('preferredlang_code: %s' % preferredlang_code)
core.logger.debug('sub_langs: %s' % sub_langs)
core.logger.debug('preferedlang_sub_indexes: %s' % preferedlang_sub_indexes)

if len(preferedlang_sub_indexes) == 0:
core.logger.debug('no subtitles found for %s' % preferredlang)
return

select_index = -1
def find_sub_index():
if 'subtitles' in player_props:
if 'subtitles' not in player_props:
return None

sub_index = None
for sub in player_props['subtitles']:
subname = sub['name'].lower()
if sub['language'] != preferredlang_code:
continue
if prefer_sdh and (sub['isimpaired'] or 'sdh' in subname or 'captions' in subname or 'honorific' in subname):
core.logger.debug('found SDH subtitles: %s' % subname)
sub_index = sub['index']
break
if prefer_forced and (sub['isforced'] or 'forced' in subname):
core.logger.debug('found forced subtitles: %s' % subname)
sub_index = sub['index']
break

if sub_index == -1:
for sub in player_props['subtitles']:
subname = sub['name'].lower()
if sub['language'] != preferredlang_code:
continue
if prefer_sdh and (sub['isimpaired'] or 'sdh' in subname or 'honorific' in subname):
select_index = sub['index']
break
if prefer_forced and (sub['isforced'] or 'forced' in subname):
select_index = sub['index']
if sub['isdefault'] or ('forced' not in subname and 'songs' not in subname):
core.logger.debug('found default subtitles: %s' % subname)
sub_index = sub['index']
break

if select_index == -1:
for sub in player_props['subtitles']:
subname = sub['name'].lower()
if sub['isdefault'] or ('forced' not in subname and 'songs' not in subname):
select_index = sub['index']
break
return sub_index

find_sub_index()
if select_index == -1 and preferredlang_code == 'pob':
sub_index = find_sub_index()
if sub_index is None and preferredlang_code == 'pob':
core.logger.debug('no subtitles found for %s, trying por' % preferredlang)
preferredlang_code = 'por'
find_sub_index()
sub_index = find_sub_index()

if select_index == -1:
if sub_index is None:
if prefer_sdh:
select_index = preferedlang_sub_indexes[-1]
if select_index == -1 and not prefer_forced and len(preferedlang_sub_indexes) > 1:
select_index = preferedlang_sub_indexes[1]
if select_index == -1:
select_index = preferedlang_sub_indexes[0]

core.kodi.xbmc.Player().setSubtitleStream(select_index)
core.logger.debug('no SDH subtitles found for %s, fallback to last index from matched langs' % preferredlang)
sub_index = preferedlang_sub_indexes[-1]
elif not prefer_forced and len(preferedlang_sub_indexes) > 1:
core.logger.debug('no subtitles found for %s, fallback to second index from matched langs' % preferredlang)
sub_index = preferedlang_sub_indexes[1]
else:
core.logger.debug('no subtitles found for %s, fallback to first index from matched langs' % preferredlang)
sub_index = preferedlang_sub_indexes[0]

core.kodi.xbmc.Player().setSubtitleStream(sub_index)
return True

has_subtitles = update_sub_stream()
except:
pass
except Exception as e:
core.logger.debug('Error on update_sub_stream: %s' % e)

if has_subtitles:
continue
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.10.0"
version="3.11.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.11.0]:
* Fix auto-selection and add debug logs.

[v3.10.0]:
* Small fix in SDH vs Forced flags checking.

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.10.0"
version="3.11.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.11.0]:
* Fix auto-selection and add debug logs.

[v3.10.0]:
* Small fix in SDH vs Forced flags checking.

Expand Down
2 changes: 1 addition & 1 deletion packages/addons.xml.crc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ca69f2639d18af6217c1ba22a035da181608040c
e71401b7c44e6bf99cdf8534835afa8d9ae20049

0 comments on commit 8c63a91

Please sign in to comment.