From b1447eb14b3f88599641beb5dff7365defee8caa Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 16 Mar 2026 14:09:05 -0600 Subject: [PATCH] fix(dl): filter CC subtitle languages with --s-lang and extract all manifest CCs Fixes issues introduced in 15acaea where CC extraction only used the first manifest entry and ignored --s-lang filtering entirely. Now all CC languages from the HLS manifest are iterated and filtered against --s-lang using the same match logic as regular subtitle selection. --- unshackle/commands/dl.py | 64 +++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/unshackle/commands/dl.py b/unshackle/commands/dl.py index 60e361a..6de2bf2 100644 --- a/unshackle/commands/dl.py +++ b/unshackle/commands/dl.py @@ -62,7 +62,7 @@ from unshackle.core.tracks import Audio, Subtitle, Tracks, Video from unshackle.core.tracks.attachment import Attachment from unshackle.core.tracks.hybrid import Hybrid from unshackle.core.utilities import (find_font_with_fallbacks, get_debug_logger, get_system_fonts, init_debug_logger, - is_close_match, suggest_font_packages, time_elapsed_since) + is_close_match, is_exact_match, suggest_font_packages, time_elapsed_since) from unshackle.core.utils import tags from unshackle.core.utils.click_types import (AUDIO_CODEC_LIST, LANGUAGE_RANGE, QUALITY_LIST, SEASON_RANGE, ContextData, MultipleChoice, MultipleVideoCodecChoice, @@ -1712,8 +1712,6 @@ class dl: f"Required languages found ({', '.join(require_subs)}), downloading all available subtitles" ) elif s_lang and "all" not in s_lang: - from unshackle.core.utilities import is_exact_match - match_func = is_exact_match if exact_lang else is_close_match missing_langs = [ @@ -2105,6 +2103,7 @@ class dl: and not video_only and not no_video ): + match_func = is_exact_match if exact_lang else is_close_match for video_track_n, video_track in enumerate(title.tracks.videos): has_manifest_cc = bool(getattr(video_track, "closed_captions", None)) has_eia_cc = ( @@ -2118,31 +2117,48 @@ class dl: if not has_manifest_cc and not has_eia_cc: continue + # Build list of CC entries to extract + if has_manifest_cc: + cc_entries = video_track.closed_captions + # Filter CC languages against --s-lang if specified + if s_lang and "all" not in s_lang: + cc_entries = [ + entry for entry in cc_entries + if entry.get("language") + and match_func(Language.get(entry["language"]), s_lang) + ] + if not cc_entries: + continue + else: + # EIA fallback: single entry with unknown language + cc_entries = [{}] + with console.status(f"Checking Video track {video_track_n + 1} for Closed Captions..."): try: - cc_lang = ( - Language.get(video_track.closed_captions[0]["language"]) - if has_manifest_cc and video_track.closed_captions[0].get("language") - else title.language or video_track.language - ) - track_id = f"ccextractor-{video_track.id}" - cc = video_track.ccextractor( - track_id=track_id, - out_path=config.directories.temp - / config.filenames.subtitle.format(id=track_id, language=cc_lang), - language=cc_lang, - original=False, - ) - if cc: - cc.cc = True - title.tracks.add(cc) - self.log.info( - f"Extracted a Closed Caption from Video track {video_track_n + 1}" + for cc_idx, cc_entry in enumerate(cc_entries): + cc_lang = ( + Language.get(cc_entry["language"]) + if cc_entry.get("language") + else title.language or video_track.language ) - else: - self.log.info( - f"No Closed Captions were found in Video track {video_track_n + 1}" + track_id = f"ccextractor-{video_track.id}-{cc_idx}" + cc = video_track.ccextractor( + track_id=track_id, + out_path=config.directories.temp + / config.filenames.subtitle.format(id=track_id, language=cc_lang), + language=cc_lang, + original=False, ) + if cc: + cc.cc = True + title.tracks.add(cc) + self.log.info( + f"Extracted a Closed Caption ({cc_lang}) from Video track {video_track_n + 1}" + ) + else: + self.log.info( + f"No Closed Captions were found in Video track {video_track_n + 1}" + ) except EnvironmentError: self.log.error( "Cannot extract Closed Captions as the ccextractor executable was not found..."