From 5bd7f31ef5f57c4ef79c2e42f0a3e50a1e499f14 Mon Sep 17 00:00:00 2001 From: rockrider69 Date: Mon, 4 Dec 2023 17:55:11 +0100 Subject: [PATCH] New Keywords Blacklist for Audio tracks 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. --- addon.xml | 3 +- changelog.txt | 4 ++ .../resource.language.en_gb/strings.po | 16 ++++++- resources/lib/prefsettings.py | 20 ++++++--- resources/lib/prefutils.py | 45 +++++++++++++++---- resources/settings.xml | 41 ++++++++++++++--- 6 files changed, 107 insertions(+), 22 deletions(-) diff --git a/addon.xml b/addon.xml index add4216..2a86793 100644 --- a/addon.xml +++ b/addon.xml @@ -2,7 +2,7 @@ @@ -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, ...) diff --git a/changelog.txt b/changelog.txt index 12b3964..8683e27 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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>... diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 252509d..1548e88 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -114,7 +114,7 @@ msgid "Ignore all Signs and Songs subtitles tracks" msgstr "" msgctxt "#30125" -msgid "Enable Keyword Blacklist" +msgid "Enable Subtitle Keyword Blacklist" msgstr " msgctxt "#30126" @@ -122,7 +122,19 @@ 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" diff --git a/resources/lib/prefsettings.py b/resources/lib/prefsettings.py index 26fbced..a6404d2 100644 --- a/resources/lib/prefsettings.py +++ b/resources/lib/prefsettings.py @@ -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): @@ -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: diff --git a/resources/lib/prefutils.py b/resources/lib/prefutils.py index 410f2a9..4b888e4 100644 --- a/resources/lib/prefutils.py +++ b/resources/lib/prefutils.py @@ -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 @@ -200,13 +201,19 @@ 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 @@ -214,7 +221,7 @@ def evalAudioPrefs(self, audio_prefs): 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 @@ -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.') @@ -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)) @@ -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.') @@ -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'] diff --git a/resources/settings.xml b/resources/settings.xml index ce13671..b60bcf6 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -57,11 +57,11 @@ - + false - + true @@ -71,10 +71,10 @@ false - true + true - + true @@ -83,7 +83,38 @@ 30127 - true + true + + + + + + false + + + + + + true + + + 30129 + + false + + true + + + + + + true + + + 30130 + + + true