Improve audio track selection with scoring system
Some checks failed
Build JellyCon / build (py2) (push) Has been cancelled
Build JellyCon / build (py3) (push) Has been cancelled
CodeQL Analysis / analyze (python, 3.9) (push) Has been cancelled
Release Drafter / Update release draft (push) Has been cancelled
Test JellyCon / test (3.9) (push) Has been cancelled

- Add intelligent scoring for multiple audio tracks in same language
- Score based on: default flag (+50), channel count (+5-40),
  codec quality (+10-30), and exclude commentary (-100)
- Prevents selecting commentary or low-quality tracks when better
  options are available in the same language
- Prioritizes default track while considering quality factors
This commit is contained in:
mani
2026-01-06 00:15:46 +01:00
parent 7d26589cf6
commit 238d30ab94

View File

@@ -858,24 +858,57 @@ def audio_subs_pref(url, list_item, media_source, item_id, audio_stream_index, s
# Auto-select audio track based on preferences
if select_audio_index is None and len(audio_streams_data) > 0:
auto_selected = None
best_score = -1
# Try to match preferred language
# Try to match preferred language with scoring
if preferred_audio_lang:
for stream in audio_streams_data:
score = 0
stream_lang = stream.get('Language', '').lower()
# Match against common variations (ger, deu, de, german)
if preferred_audio_lang in stream_lang or stream_lang.startswith(preferred_audio_lang[:3]):
auto_selected = stream['Index']
log.debug("Auto-selected audio by language: {0} (index {1})".format(stream_lang, auto_selected))
break
score += 100 # Language match
# Fall back to default audio if enabled
# Bonus for default track
if stream.get('IsDefault', False):
score += 50
# Bonus based on channel count (more channels = better quality)
channels = stream.get('Channels', 2)
score += min(channels * 5, 40) # Max +40 for 8 channels
# Bonus for high-quality codecs
codec = stream.get('Codec', '').lower()
if 'truehd' in codec or 'dts-hd' in codec or 'dts-ma' in codec:
score += 30
elif 'dts' in codec:
score += 20
elif 'ac3' in codec or 'eac3' in codec:
score += 10
# Penalty for commentary tracks
title = stream.get('Title', '').lower()
display_title = stream.get('DisplayTitle', '').lower()
if 'commentary' in title or 'kommentar' in title or 'commentary' in display_title:
score -= 100 # Effectively exclude commentary
log.debug("Audio score for {0} ({1}): {2} (channels={3}, codec={4}, default={5})".format(
stream_lang, stream['Index'], score, channels, codec, stream.get('IsDefault', False)))
if score > best_score:
best_score = score
auto_selected = stream['Index']
# Fall back to default audio if enabled and no language match
if auto_selected is None and auto_select_default_audio:
auto_selected = default_audio
log.debug("Auto-selected default audio (index {0})".format(auto_selected))
if auto_selected is not None:
select_audio_index = auto_selected
if best_score > 0:
log.debug("Auto-selected audio (index {0}, score {1})".format(auto_selected, best_score))
# Auto-select subtitle track based on preferences
if select_subs_index is None and len(subtitle_streams_data) > 0: