Skip to content

Commit

Permalink
New Keywords Blacklist for Audio tracks
Browse files Browse the repository at this point in the history
Keywords Blacklist for Audio tracks. Same principle as for Subtitles, based on track name, to skip some when evaluating Audio preferences (ex. Commentary, ...).
Previous Keywords Backlist limited to subtitles is renamed to be consistent, and require to reenter your keywords list.
  • Loading branch information
rockrider69 committed Dec 4, 2023
1 parent b8343ec commit 5bd7f31
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 22 deletions.
3 changes: 2 additions & 1 deletion 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.3BETA1"
version="1.0.3BETA2"
provider-name="ace20022/scott967/rockrider69"
>
<requires>
Expand All @@ -28,6 +28,7 @@
Forced sub tracks : check also subtitle field "isforced" in case field "name" is empty or misspelled.
1.0.3BETA1: Option to prioritize 'SignsSongs' tracks via custom conditional sub preferences. Syntax is ...>Eng:Eng-ss>...
Overrides general 'Ignore Signs and Songs toggle' or 'Blacklisting Signs via keyword', if ever used.
1.0.3BETA2: Keywords Blacklist for Audio tracks. Same principle as for Subtitles, based on track name, to skip some (ex. Commentary, ...)

</news>
<assets>
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
--- Version 1.0.3BETA2

- Keywords Blacklist for Audio tracks. Same principle as for Subtitles, based on track name, skip some (ex. Commentary, ...)

--- Version 1.0.3BETA1

- Option to prioritize 'SignsSongs' tracks via custom conditional sub preferences. Syntax is ...>Eng:Eng-ss>...
Expand Down
16 changes: 14 additions & 2 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,27 @@ msgid "Ignore all Signs and Songs subtitles tracks"
msgstr ""

msgctxt "#30125"
msgid "Enable Keyword Blacklist"
msgid "Enable Subtitle Keyword Blacklist"
msgstr "
msgctxt "#30126"
msgid "Enter a comma-separated list of keywords to blacklist in subtitle names"
msgstr "
msgctxt "#30127"
msgid "Keyword List:"
msgid "Subtitle Keyword List:"
msgstr "
msgctxt "#30128"
msgid "Enable Audio Keyword Blacklist"
msgstr "
msgctxt "#30129"
msgid "Enter a comma-separated list of keywords to blacklist in audio names"
msgstr "
msgctxt "#30130"
msgid "Audio Keyword List:"
msgstr "
msgctxt "#30201"
Expand Down
20 changes: 14 additions & 6 deletions resources/lib/prefsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def readSettings(self):
self.useFilename, self.filenameRegex, self.at_least_one_pref_on,
self.AudioPrefs, self.SubtitlePrefs, self.CondSubtitlePrefs,
self.custom_audio, self.custom_subs, self.custom_condsub, self.ignore_signs_on,
','.join(self.keyword_blacklist))
','.join(self.subtitle_keyword_blacklist),
','.join(self.audio_keyword_blacklist)
)
)

def readPrefs(self):
Expand All @@ -79,12 +81,18 @@ def readPrefs(self):
self.turn_subs_on = addon.getSetting('turnSubsOn') == 'true'
self.turn_subs_off = addon.getSetting('turnSubsOff') == 'true'
self.ignore_signs_on = addon.getSetting('signs') == 'true'
self.keyword_blacklist_enabled = addon.getSetting('enableKeywordBlacklist') == 'true'
self.keyword_blacklist = addon.getSetting('KeywordBlacklist')
if self.keyword_blacklist and self.keyword_blacklist_enabled:
self.keyword_blacklist = self.keyword_blacklist.lower().split(',')
self.subtitle_keyword_blacklist_enabled = addon.getSetting('enableSubtitleKeywordBlacklist') == 'true'
self.subtitle_keyword_blacklist = addon.getSetting('SubtitleKeywordBlacklist')
if self.subtitle_keyword_blacklist and self.subtitle_keyword_blacklist_enabled:
self.subtitle_keyword_blacklist = self.subtitle_keyword_blacklist.lower().split(',')
else:
self.keyword_blacklist = []
self.subtitle_keyword_blacklist = []
self.audio_keyword_blacklist_enabled = addon.getSetting('enableAudioKeywordBlacklist') == 'true'
self.audio_keyword_blacklist = addon.getSetting('AudioKeywordBlacklist')
if self.audio_keyword_blacklist and self.audio_keyword_blacklist_enabled:
self.audio_keyword_blacklist = self.audio_keyword_blacklist.lower().split(',')
else:
self.audio_keyword_blacklist = []
self.useFilename = addon.getSetting('useFilename') == 'true'
self.filenameRegex = addon.getSetting('filenameRegex')
if self.useFilename:
Expand Down
45 changes: 37 additions & 8 deletions resources/lib/prefutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def evalFilenamePrefs(self):

def evalAudioPrefs(self, audio_prefs):
log(LOG_DEBUG, 'Evaluating audio preferences' )
log(LOG_DEBUG, 'Audio names containing the following keywords are blacklisted: {0}'.format(','.join(settings.audio_keyword_blacklist)))
i = 0
for pref in audio_prefs:
i += 1
Expand All @@ -200,21 +201,27 @@ def evalAudioPrefs(self, audio_prefs):
continue
if (self.selected_audio_stream and
'language' in self.selected_audio_stream and
# filter out audio tracks matching Keyword Blacklist
not self.isInBlacklist(self.selected_audio_stream['name'],'Audio') and
(code == self.selected_audio_stream['language'] or name == self.selected_audio_stream['language'])):
log(LOG_INFO, 'Selected audio language matches preference {0} ({1})'.format(i, name) )
return -1
else:
for stream in self.audiostreams:
# filter out audio tracks matching Keyword Blacklist
if (self.isInBlacklist(stream['name'],'Audio')):
log(LOG_INFO,'Audio: one audio track is found matching Keyword Blacklist : {0}. Skipping it.'.format(','.join(settings.audio_keyword_blacklist)))
continue
if ((code == stream['language']) or (name == stream['language'])):
log(LOG_INFO, 'Audio language of stream {0} matches preference {1} ({2})'.format(stream['index'], i, name) )
log(LOG_INFO, 'Language of Audio track {0} matches preference {1} ({2})'.format((stream['index']+1), i, name) )
return stream['index']
log(LOG_INFO, 'Audio: preference {0} ({1}:{2}) not available'.format(i, name, code) )
i += 1
return -2

def evalSubPrefs(self, sub_prefs):
log(LOG_DEBUG, 'Evaluating subtitle preferences' )
log(LOG_DEBUG, 'Subtitle names containing the following keywords are blacklisted: {0}'.format(','.join(settings.keyword_blacklist)))
log(LOG_DEBUG, 'Subtitle names containing the following keywords are blacklisted: {0}'.format(','.join(settings.subtitle_keyword_blacklist)))
i = 0
for pref in sub_prefs:
i += 1
Expand All @@ -233,13 +240,17 @@ def evalSubPrefs(self, sub_prefs):
continue
if (self.selected_sub and
'language' in self.selected_sub and
# filter out subtitles to be ignored via Signs&Songs Toggle or matching Keywords Blacklist
not self.isInBlacklist(self.selected_sub['name'],'Subtitle') and
not (settings.ignore_signs_on and self.isSignsSub(self.selected_sub['name'])) and
((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:
for sub in self.subtitles:
if (settings.keyword_blacklist_enabled and any(keyword in sub['name'].lower() for keyword in settings.keyword_blacklist)):
log(LOG_INFO,'SubPrefs : one subtitle track is found matching Keyword Blacklist : {0}. Skipping it.'.format(','.join(settings.keyword_blacklist)))
# filter out subtitles to be ignored via Signs&Songs Toggle or matching Keywords Blacklist
if self.isInBlacklist(sub['name'], 'Subtitle'):
log(LOG_INFO,'SubPrefs : one subtitle track is found matching Keyword Blacklist : {0}. Skipping it.'.format(','.join(settings.subtitle_keyword_blacklist)))
continue
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.')
Expand All @@ -253,7 +264,7 @@ def evalSubPrefs(self, sub_prefs):

def evalCondSubPrefs(self, condsub_prefs):
log(LOG_DEBUG, 'Evaluating conditional subtitle preferences' )
log(LOG_DEBUG, 'Subtitle names containing the following keywords are blacklisted: {0}'.format(','.join(settings.keyword_blacklist)))
log(LOG_DEBUG, 'Subtitle names containing the following keywords are blacklisted: {0}'.format(','.join(settings.subtitle_keyword_blacklist)))
# if the audio track has been changed wait some time
if (self.audio_changed and settings.delay > 0):
log(LOG_DEBUG, "Delaying preferences evaluation by {0} ms".format(4*settings.delay))
Expand Down Expand Up @@ -284,22 +295,31 @@ def evalCondSubPrefs(self, condsub_prefs):
log(LOG_INFO, 'Subtitle condition is None but forced is true, searching a forced subtitle matching selected audio...')
for sub in self.subtitles:
log(LOG_DEBUG, 'Looping subtitles...')
# filter out subtitles to be ignored via Signs&Songs Toggle or matching Keywords Blacklist
if self.isInBlacklist(sub['name'], 'Subtitle'):
log(LOG_INFO,'CondSubs : one subtitle track is found matching Keyword Blacklist : {0}. Skipping it.'.format(','.join(settings.subtitle_keyword_blacklist)))
continue
if (settings.ignore_signs_on and self.isSignsSub(sub['name'])):
log(LOG_INFO,'CondSubs : ignore_signs toggle is on and one such subtitle track is found. Skipping it.')
continue
if ((audio_code == sub['language']) or (audio_name == sub['language'])):
log(LOG_DEBUG, 'One potential match found...')
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']
log(LOG_INFO, 'Conditional subtitle: no match found for preference {0} ({1}:{2}) with forced overriding rule {3}'.format(i, audio_name, sub_name, forced) )
log(LOG_INFO, 'Conditional subtitle: no match found for preference {0} ({1}:{2}) with forced overriding rule {3}'.format(i, audio_name, sub_name, forced))
return -1
else:
for sub in self.subtitles:
# take into account -ss tag to prioritize specific Signs&Songs subtitles track
if ((sub_code == sub['language']) or (sub_name == sub['language'])):
if (ss_tag == 'true' and self.isSignsSub(sub['name'])):
log(LOG_INFO, 'Language of subtitle {0} matches conditional preference {1} ({2}:{3}) SubTag {4}'.format((sub['index']+1), i, audio_name, sub_name, ss_tag) )
return sub['index']
if (settings.keyword_blacklist_enabled and any(keyword in sub['name'].lower() for keyword in settings.keyword_blacklist)):
log(LOG_INFO,'CondSubs : one subtitle track is found matching Keyword Blacklist : {0}. Skipping it.'.format(','.join(settings.keyword_blacklist)))
# filter out subtitles to be ignored via Signs&Songs Toggle or matching Keywords Blacklist
if self.isInBlacklist(sub['name'], 'Subtitle'):
log(LOG_INFO,'CondSubs : one subtitle track is found matching Keyword Blacklist : {0}. Skipping it.'.format(','.join(settings.subtitle_keyword_blacklist)))
continue
if (settings.ignore_signs_on and self.isSignsSub(sub['name'])):
log(LOG_INFO,'CondSubs : ignore_signs toggle is on and one such subtitle track is found. Skipping it.')
Expand All @@ -312,6 +332,15 @@ def evalCondSubPrefs(self, condsub_prefs):
i += 1
return -2

def isInBlacklist(self, TrackName, TrackType):
found = False
test = TrackName.lower()
if (TrackType == 'Subtitle' and settings.subtitle_keyword_blacklist_enabled and any(keyword in test for keyword in settings.subtitle_keyword_blacklist)):
found = True
elif (TrackType == 'Audio' and settings.audio_keyword_blacklist_enabled and any(keyword in test for keyword in settings.audio_keyword_blacklist)):
found = True
return found

def isSignsSub(self, subName):
test = subName.lower()
matches = ['signs']
Expand Down
41 changes: 36 additions & 5 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
</setting>
</group>
<group id="3">
<setting id="enableKeywordBlacklist" label="30125" type="boolean">
<setting id="enableSubtitleKeywordBlacklist" label="30125" type="boolean">
<default>false</default>
<control type="toggle" />
</setting>
<setting label="30126" type="string" id="KeywordBlacklistLabel">
<setting label="30126" type="string" id="SubtitleKeywordBlacklistLabel">
<default></default>
<constraints>
<allowempty>true</allowempty>
Expand All @@ -71,10 +71,10 @@
</control>
<enable>false</enable>
<dependencies>
<dependency type="visible" setting="enableKeywordBlacklist" operator="is">true</dependency>
<dependency type="visible" setting="enableSubtitleKeywordBlacklist" operator="is">true</dependency>
</dependencies>
</setting>
<setting label="30127" type="string" id="KeywordBlacklist">
<setting label="30127" type="string" id="SubtitleKeywordBlacklist">
<default></default>
<constraints>
<allowempty>true</allowempty>
Expand All @@ -83,7 +83,38 @@
<heading>30127</heading>
</control>
<dependencies>
<dependency type="visible" setting="enableKeywordBlacklist" operator="is">true</dependency>
<dependency type="visible" setting="enableSubtitleKeywordBlacklist" operator="is">true</dependency>
</dependencies>
</setting>
</group>
<group id="4">
<setting id="enableAudioKeywordBlacklist" label="30128" type="boolean">
<default>false</default>
<control type="toggle" />
</setting>
<setting label="30129" type="string" id="AudioKeywordBlacklistLabel">
<default></default>
<constraints>
<allowempty>true</allowempty>
</constraints>
<control type="edit" format="string">
<heading>30129</heading>
</control>
<enable>false</enable>
<dependencies>
<dependency type="visible" setting="enableAudioKeywordBlacklist" operator="is">true</dependency>
</dependencies>
</setting>
<setting label="30130" type="string" id="AudioKeywordBlacklist">
<default></default>
<constraints>
<allowempty>true</allowempty>
</constraints>
<control type="edit" format="string">
<heading>30130</heading>
</control>
<dependencies>
<dependency type="visible" setting="enableAudioKeywordBlacklist" operator="is">true</dependency>
</dependencies>
</setting>
</group>
Expand Down

0 comments on commit 5bd7f31

Please sign in to comment.