Skip to content

Commit

Permalink
Replace preferred language subtitle option with preferred language + …
Browse files Browse the repository at this point in the history
…fallback + no ASR option anxdpanic#992
  • Loading branch information
MoojMidge committed Nov 21, 2024
1 parent dc54c38 commit 559fdd0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
5 changes: 3 additions & 2 deletions resources/lib/youtube_plugin/kodion/script_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ def _config_actions(context, action, *_args):
fallback = ('ASR' if preferred[0].startswith('en') else
context.get_language_name('en'))
preferred = '/'.join(map(context.get_language_name, preferred))
preferred_no_asr = '%s (%s)' % (preferred, localize('subtitles.no_asr'))

sub_opts = [
localize('none'),
localize('select'),
localize('subtitles.with_fallback') % (preferred, fallback),
preferred,
'%s (%s)' % (preferred, localize('subtitles.no_asr')),
localize('subtitles.with_fallback') % (preferred_no_asr, fallback),
preferred_no_asr,
]

if settings.use_mpd_videos():
Expand Down
51 changes: 38 additions & 13 deletions resources/lib/youtube_plugin/youtube/helper/subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,37 @@
from ...kodion.utils import make_dirs


class Subtitles(object):
LANG_NONE = 0
LANG_PROMPT = 1
LANG_CURR_FALLBACK = 2
LANG_CURR = 3
LANG_CURR_NO_ASR = 4
LANG_ALL = 5
SUBTITLE_OPTIONS = {
'none': 0,
'prompt': 1,
'preferred': 2,
'fallback': 4,
'no_asr': 8,
'all': 16,
}


SUBTITLE_SELECTIONS = {
0: SUBTITLE_OPTIONS['none'],
1: SUBTITLE_OPTIONS['all']
+ SUBTITLE_OPTIONS['prompt'],
2: SUBTITLE_OPTIONS['preferred']
+ SUBTITLE_OPTIONS['fallback'],
3: SUBTITLE_OPTIONS['preferred']
+ SUBTITLE_OPTIONS['fallback']
+ SUBTITLE_OPTIONS['no_asr'],
4: SUBTITLE_OPTIONS['preferred']
+ SUBTITLE_OPTIONS['no_asr'],
5: SUBTITLE_OPTIONS['all'],
'none': 0,
'prompt': 1,
'preferred_fallback_asr': 2,
'preferred_fallback': 3,
'preferred': 4,
'all': 5,
}

class Subtitles(object):
BASE_PATH = make_dirs(TEMP_PATH)

FORMATS = {
Expand Down Expand Up @@ -180,19 +203,21 @@ def get_lang_details(self):

def get_subtitles(self):
if self.prompt_override:
selection = self.LANG_PROMPT
selection = SUBTITLE_SELECTIONS['select']
else:
selection = self.sub_selection

if selection == self.LANG_NONE:
if selection == SUBTITLE_SELECTIONS['none']:
return None

if selection == self.LANG_ALL:
if selection == SUBTITLE_SELECTIONS['all']:
return self.get_all()

if selection == self.LANG_PROMPT:
if selection == SUBTITLE_SELECTIONS['select']:
return self._prompt()

selected_options = SUBTITLE_SELECTIONS[selection]

preferred_lang = self.preferred_lang
original_lang = self.defaults['original_lang']

Expand All @@ -203,9 +228,9 @@ def get_subtitles(self):
allowed_langs.append(lang.partition('-')[0])

use_asr = None
if selection == self.LANG_CURR_NO_ASR:
if selected_options & SUBTITLE_OPTIONS['no_asr']:
use_asr = False
elif selection == self.LANG_CURR_FALLBACK:
if selected_options & SUBTITLE_OPTIONS['fallback']:
for lang in (original_lang, 'en', 'en-US', 'en-GB', 'ASR'):
if lang not in preferred_lang:
allowed_langs.append(lang)
Expand Down

0 comments on commit 559fdd0

Please sign in to comment.