Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/itv.py (Python)

Code before:
                    'id': 'browser'
                },
                'variantAvailability': {
                    'featureset': {
                        'min': featureset_video,
                        'max': featureset_video
                    },
                    'platformTag': platform_tag_video
                }
            }).encode(), headers=headers)
        video_data = try_get(ios_playlist, lambda x: x['Playlist']['Video'], dict) or {}
        ios_base_url = video_data.get('Base')
        hls_subs = {}
        formats = []
        for media_file in (video_data.get('MediaFiles') or []):
            href = media_file.get('Href')
            if not href:
                continue
            if ios_base_url:
                href = ios_base_url + href
            ext = determine_ext(href)
            if ext == 'm3u8':
                hls_formats, hls_subs = self._extract_m3u8_formats_and_subtitles(
                    href, video_id, 'mp4', entry_protocol='m3u8_native',
                    m3u8_id='hls', fatal=False)
                formats.extend(hls_formats)
            else:
                formats.append({
                    'url': href,
                })
        self._sort_formats(formats)

        subtitles = {}
        platform_tag_subs = None
        featureset_subs = None
        for platform_tag, featuresets in variants.items():
            for featureset in featuresets:
                if (isinstance(featureset, list) and len(featureset) >= 3
                        and featureset[2] == 'outband-webvtt'):
                    platform_tag_subs = platform_tag
                    featureset_subs = featureset
                    break
        if not platform_tag_subs or not featureset_subs:
            self.report_warning('No subtitles available', video_id)
        else:
            subs_playlist = self._download_json(
                ios_playlist_url, video_id, data=json.dumps({
                    'user': {
                        'itvUserId': '',
                        'entitlements': [],
                        'token': ''

Review comment (suggestion):
Are you sure there is only one m3u8? otherwise, the `hls_subs` of everything but the last one is discarded

Code after:
                'client': {
                    'version': '4.1',
                    'id': 'browser'
                },
                'variantAvailability': {
                    'featureset': {
                        'min': featureset,
                        'max': featureset
                    },
                    'platformTag': platform_tag
                }
            }).encode(), headers=headers, fatal=fatal)

    def _get_subtitles(self, video_id, variants, ios_playlist_url, headers, *args, **kwargs):
        subtitles = {}
        platform_tag_subs, featureset_subs = next(
            ((platform_tag, featureset)
             for platform_tag, featuresets in variants.items() for featureset in featuresets
             if try_get(featureset, lambda x: x[2]) == 'outband-webvtt'),
            (None, None))
        if platform_tag_subs or featureset_subs:
            subs_playlist = self._call_api(
                video_id, ios_playlist_url, headers, platform_tag_subs, featureset_subs, fatal=False)
            subs = try_get(subs_playlist, lambda x: x['Playlist']['Video']['Subtitles'], list) or []
            for sub in subs:
                if not isinstance(sub, dict):
                    continue
                href = url_or_none(sub.get('Href'))
                if not href:
                    continue
                subtitles.setdefault('en', []).append({'url': href})
        return subtitles

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        params = extract_attributes(self._search_regex(
            r'(?s)(<[^>]+id="video"[^>]*>)', webpage, 'params'))
        variants = self._parse_json(
            try_get(params, lambda x: x['data-video-variants'], compat_str) or '{}',
            video_id, fatal=False)
        platform_tag_video, featureset_video = next(
            ((platform_tag, featureset)
             for platform_tag, featuresets in variants.items() for featureset in featuresets
             if try_get(featureset, lambda x: x[:2]) == ['hls', 'aes']),
            (None, None))
        if not platform_tag_video or not featureset_video:
            raise ExtractorError('No downloads available', expected=True, video_id=video_id)

        ios_playlist_url = params.get('data-video-playlist') or params['data-video-id']
        headers = self._generate_api_headers(params['data-video-hmac'])