Skip to content

Commit

Permalink
[service.languagepreferencemanager] 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rockrider69 committed Nov 12, 2023
1 parent 4f14f07 commit 755a244
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
4 changes: 3 additions & 1 deletion service.languagepreferencemanager/addon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<addon
id="service.languagepreferencemanager"
name="Language Preference Manager"
version="1.0.1"
version="1.0.2"
provider-name="ace20022/scott967/rockrider69"
>
<requires>
Expand All @@ -24,6 +24,8 @@
0.1.7BETA : New Keywords Blacklist to ignore chosen subtitles tracks based on name content.
1.0.0 : Mandatory clean-up to propose as candidate version for Kodi.tv addons repository.
1.0.1 : Initial version for main Kodi.tv addons repository
1.0.2 : Fix 10sec latency on subs display and possible few lines lost - at video start or when switching audio.
Forced sub tracks : check also subtitle field "isforced" in case field "name" is empty or misspelled.

</news>
<assets>
Expand Down
5 changes: 5 additions & 0 deletions service.languagepreferencemanager/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
--- Version 1.0.2

- Fix 10sec latency on subs display and possible few lines lost - at video start or when switching audio.
- Forced sub tracks : check also subtitle field "isforced" in case field "name" is empty or misspelled.

--- Version 1.0.1

- Initial version for main Kodi.tv addons repository
Expand Down
23 changes: 18 additions & 5 deletions service.languagepreferencemanager/resources/lib/prefutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ def evalPrefs(self):
log(LOG_DEBUG, 'Subtitle: enabling subs' )
self.showSubtitles(True)

# Workaround to an old Kodi bug creating 10-15 sec latency when activating a subtitle track.
# Force very short rewind to avoid 10-15sec delay and first few subtitles lines potentially lost
# but if we are very close to beginning, then restart from time 0
if (self.getTime() <= 10):
self.seekTime(0)
else:
self.seekTime(self.getTime()-1)

def evalFilenamePrefs(self):
log(LOG_DEBUG, 'Evaluating filename preferences' )
audio = -1
Expand Down Expand Up @@ -225,7 +233,7 @@ def evalSubPrefs(self, sub_prefs):
continue
if (self.selected_sub and
'language' in self.selected_sub and
((code == self.selected_sub['language'] or name == self.selected_sub['language']) and self.testForcedFlag(forced, self.selected_sub['name']))):
((code == self.selected_sub['language'] or name == self.selected_sub['language']) and self.testForcedFlag(forced, self.selected_sub['name'], self.selected_sub['isforced']))):
log(LOG_INFO, 'Selected subtitle language matches preference {0} ({1})'.format(i, name) )
return -1
else:
Expand All @@ -236,7 +244,7 @@ def evalSubPrefs(self, sub_prefs):
if (settings.ignore_signs_on and self.isSignsSub(sub['name'])):
log(LOG_INFO,'SubPrefs : ignore_signs toggle is on and one such subtitle track is found. Skipping it.')
continue
if ((code == sub['language'] or name == sub['language']) and self.testForcedFlag(forced, sub['name'])):
if ((code == sub['language'] or name == sub['language']) and self.testForcedFlag(forced, sub['name'], sub['isforced'])):
log(LOG_INFO, 'Subtitle language of subtitle {0} matches preference {1} ({2})'.format((sub['index']+1), i, name) )
return sub['index']
log(LOG_INFO, 'Subtitle: preference {0} ({1}:{2}) not available'.format(i, name, code) )
Expand Down Expand Up @@ -278,7 +286,7 @@ def evalCondSubPrefs(self, condsub_prefs):
log(LOG_DEBUG, 'Looping subtitles...')
if ((audio_code == sub['language']) or (audio_name == sub['language'])):
log(LOG_DEBUG, 'One potential match found...')
if (self.testForcedFlag(forced, sub['name'])):
if (self.testForcedFlag(forced, sub['name'], sub['isforced'])):
log(LOG_DEBUG, 'One forced match found...')
log(LOG_INFO, 'Language of subtitle {0} matches audio preference {1} ({2}:{3}) with forced overriding rule {4}'.format((sub['index']+1), i, audio_name, sub_name, forced) )
return sub['index']
Expand All @@ -293,7 +301,7 @@ def evalCondSubPrefs(self, condsub_prefs):
log(LOG_INFO,'CondSubs : ignore_signs toggle is on and one such subtitle track is found. Skipping it.')
continue
if ((sub_code == sub['language']) or (sub_name == sub['language'])):
if (self.testForcedFlag(forced, sub['name'])):
if (self.testForcedFlag(forced, sub['name'], sub['isforced'])):
log(LOG_INFO, 'Language of subtitle {0} matches conditional preference {1} ({2}:{3}) forced {4}'.format((sub['index']+1), i, audio_name, sub_name, forced) )
return sub['index']
log(LOG_INFO, 'Conditional subtitle: no match found for preference {0} ({1}:{2})'.format(i, audio_name, sub_name) )
Expand All @@ -305,10 +313,15 @@ def isSignsSub(self, subName):
matches = ['signs']
return any(x in test for x in matches)

def testForcedFlag(self, forced, subName):
def testForcedFlag(self, forced, subName, subForcedTag):
test = subName.lower()
matches = ['forced', 'forcés']
found = any(x in test for x in matches)
# Only when looking for forced subs :
# in case the sub name is plain empty or not well documented,
# check also the sub isforced tag and consider it a match if set
if (forced and not found and subForcedTag):
found = True
return ((forced == 'false') and not found) or ((forced == 'true') and found)

def isExternalSub(self, subName):
Expand Down

0 comments on commit 755a244

Please sign in to comment.