Skip to content

Commit

Permalink
[script.copacetic.helper] 1.0.18
Browse files Browse the repository at this point in the history
subtitle_limiter() function added
  • Loading branch information
realcopacetic committed May 31, 2024
1 parent 0095a22 commit df854e4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions script.copacetic.helper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]"'

Expand Down
2 changes: 1 addition & 1 deletion script.copacetic.helper/addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<addon id="script.copacetic.helper" name="Copacetic Helper" version="1.0.17" provider-name="realcopacetic">
<addon id="script.copacetic.helper" name="Copacetic Helper" version="1.0.18" provider-name="realcopacetic">
<requires>
<import addon="xbmc.python" version="3.0.1" />
<import addon="script.module.pil" version="5.1.0" />
Expand Down
22 changes: 22 additions & 0 deletions script.copacetic.helper/resources/lib/script/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit df854e4

Please sign in to comment.