mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-03-11 17:09:00 +00:00
fix(dl): avoid selecting all variants when multiple audio codecs requested
When --a-lang is specific (not best/all) and multiple codecs are requested via -a/--acodec, select only the best-bitrate track per codec per language (plus descriptive if --audio-description).
Blame: regression introduced by 939ca25 (fix(dl): keep descriptive and standard audio for requested langs).
This commit is contained in:
@@ -1484,7 +1484,36 @@ class dl:
|
|||||||
selected_audio.append(max(base_candidates, key=lambda x: x.bitrate or 0))
|
selected_audio.append(max(base_candidates, key=lambda x: x.bitrate or 0))
|
||||||
title.tracks.audio = selected_audio
|
title.tracks.audio = selected_audio
|
||||||
elif "all" not in processed_lang:
|
elif "all" not in processed_lang:
|
||||||
per_language = 0 if acodec and len(acodec) > 1 else 1
|
# If multiple codecs were explicitly requested, pick the best track per codec per
|
||||||
|
# requested language instead of selecting *all* bitrate variants of a codec.
|
||||||
|
if acodec and len(acodec) > 1:
|
||||||
|
selected_audio: list[Audio] = []
|
||||||
|
|
||||||
|
for language in processed_lang:
|
||||||
|
for codec in acodec:
|
||||||
|
codec_tracks = [a for a in title.tracks.audio if a.codec == codec]
|
||||||
|
if not codec_tracks:
|
||||||
|
continue
|
||||||
|
|
||||||
|
candidates = title.tracks.by_language(
|
||||||
|
codec_tracks, [language], per_language=0, exact_match=exact_lang
|
||||||
|
)
|
||||||
|
if not candidates:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if audio_description:
|
||||||
|
standards = [t for t in candidates if not t.descriptive]
|
||||||
|
if standards:
|
||||||
|
selected_audio.append(max(standards, key=lambda x: x.bitrate or 0))
|
||||||
|
descs = [t for t in candidates if t.descriptive]
|
||||||
|
if descs:
|
||||||
|
selected_audio.append(max(descs, key=lambda x: x.bitrate or 0))
|
||||||
|
else:
|
||||||
|
selected_audio.append(max(candidates, key=lambda x: x.bitrate or 0))
|
||||||
|
|
||||||
|
title.tracks.audio = selected_audio
|
||||||
|
else:
|
||||||
|
per_language = 1
|
||||||
if audio_description:
|
if audio_description:
|
||||||
standard_audio = [a for a in title.tracks.audio if not a.descriptive]
|
standard_audio = [a for a in title.tracks.audio if not a.descriptive]
|
||||||
selected_standards = title.tracks.by_language(
|
selected_standards = title.tracks.by_language(
|
||||||
@@ -1498,7 +1527,10 @@ class dl:
|
|||||||
title.tracks.audio = selected_standards + selected_descs
|
title.tracks.audio = selected_standards + selected_descs
|
||||||
else:
|
else:
|
||||||
title.tracks.audio = title.tracks.by_language(
|
title.tracks.audio = title.tracks.by_language(
|
||||||
title.tracks.audio, processed_lang, per_language=per_language, exact_match=exact_lang
|
title.tracks.audio,
|
||||||
|
processed_lang,
|
||||||
|
per_language=per_language,
|
||||||
|
exact_match=exact_lang,
|
||||||
)
|
)
|
||||||
if not title.tracks.audio:
|
if not title.tracks.audio:
|
||||||
self.log.error(f"There's no {processed_lang} Audio Track, cannot continue...")
|
self.log.error(f"There's no {processed_lang} Audio Track, cannot continue...")
|
||||||
|
|||||||
Reference in New Issue
Block a user