diff --git a/script.copacetic.helper/README.md b/script.copacetic.helper/README.md index f8200b593..77adc7c56 100644 --- a/script.copacetic.helper/README.md +++ b/script.copacetic.helper/README.md @@ -13,6 +13,9 @@ All code contained in this project is licensed under GPL 3.0. * __jurialmunkey__ for all the best-practice code examples from [plugin.video.themoviedb.helper](https://github.com/jurialmunkey/plugin.video.themoviedb.helper) and forum support. ### Changelog +**1.0.18** +- Added subtitle_limiter() script, which sets subtitles to the first stream in the desired language if it's available and then toggles between this subtitle stream and 'off'. If the preferred language stream is not available it will toggle through all available subtitles instead. + **1.0.17** - Parse args for script actions to enable values with special characters to be properly escaped from Kodi using '"$INFO[ListItem.Title]"' diff --git a/script.copacetic.helper/addon.xml b/script.copacetic.helper/addon.xml index f12d59bf0..0c0880ca8 100644 --- a/script.copacetic.helper/addon.xml +++ b/script.copacetic.helper/addon.xml @@ -1,5 +1,5 @@ - + diff --git a/script.copacetic.helper/resources/lib/script/actions.py b/script.copacetic.helper/resources/lib/script/actions.py index 5aa493477..e0efada79 100644 --- a/script.copacetic.helper/resources/lib/script/actions.py +++ b/script.copacetic.helper/resources/lib/script/actions.py @@ -239,6 +239,28 @@ def shuffle_artist(**kwargs): parent='shuffle_artist') +def subtitle_limiter(lang,**kwargs): + if condition('VideoPlayer.HasSubtitles'): + player = xbmc.Player() + subtitles = [] + current_subtitle = player.getSubtitles() + subtitles = player.getAvailableSubtitleStreams() + if lang not in current_subtitle or condition('!VideoPlayer.SubtitlesEnabled'): + try: + index = subtitles.index(lang) + except ValueError as error: + log( + f'Subtitle Limiter: Error - Preferred subtitle stream ({lang}) not available, toggling through available streams instead --> {error}', force=True) + log_and_execute('Action(NextSubtitle)') + else: + player.setSubtitleStream(index) + log(f'Subtitle Limiter: Switching to subtitle stream {index} in preferred language: {lang}', force=True) + elif condition('VideoPlayer.SubtitlesEnabled'): + log_and_execute('Action(ShowSubtitles)') + else: + log('Subtitle Limiter: Error - Playing video has no subtitles', force=True) + + def toggle_addon(id, **kwargs): if condition(f'System.AddonIsEnabled({id})'): json_call('Addons.SetAddonEnabled',