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

Code before:
        for q in TP_SMIL_QUERY:
            q.update(query)
            m_url = update_url_query(smil_url, q)
            m_url = self._sign_url(m_url, self._THEPLATFORM_KEY, self._THEPLATFORM_SECRET)
            try:
                tp_formats, tp_subtitles = self._extract_theplatform_smil(
                    m_url, video_id, 'Downloading %s SMIL data' % (q.get('switch') or q['assetTypes']))
            except ExtractorError as e:
                if isinstance(e, GeoRestrictedError):
                    raise
                last_e = e
                continue
            formats.extend(tp_formats)
            subtitles = self._merge_subtitles(subtitles, tp_subtitles)
        if last_e and not formats:
            raise last_e
        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
        }

    def _extract_aetn_info(self, domain, filter_key, filter_value, url):
        requestor_id, brand, software_statement = self._DOMAIN_MAP[domain]
        graphql_video_id = (self._search_regex(
            r'<meta[^>]+content="[^"]*tpid/(\d+)"|<meta[^>]*name="videoId"[^>]*content="(\d+)"',
            self._download_webpage(url, filter_value), 'video ID') if filter_key == 'canonical' else filter_value)
        result = self._download_json(
            'https://yoga.appsvcs.aetnd.com/', graphql_video_id,
            query={'brand': brand, 'mode': 'live', 'platform': 'web'},
            data=json.dumps({'operationName': 'getUserVideo', 'variables': {'videoId': graphql_video_id},
                             'query': 'query getUserVideo($videoId: ID!) { video(id: $videoId) { title publicUrl programId tvSeasonNumber tvSeasonEpisodeNumber series { title } } }'}).encode(),
            headers={'Content-Type': 'application/json'})
        result = traverse_obj(result, ('data', 'video'), default={})
        if not result or not result.get('publicUrl'):
            raise ExtractorError('Show not found in A&E feed (too new?)', expected=True,
                                 video_id=remove_start(filter_value, '/'))
        title = result['title']
        video_id = result['programId']
        media_url = result['publicUrl']
        theplatform_metadata = self._download_theplatform_metadata(self._search_regex(
            r'https?://link\.theplatform\.com/s/([^?]+)', media_url, 'theplatform_path'), video_id)
        info = self._parse_theplatform_metadata(theplatform_metadata)
        auth = None
        if theplatform_metadata.get('AETN$isBehindWall'):
            resource = self._get_mvpd_resource(
                requestor_id, theplatform_metadata['title'],
                theplatform_metadata.get('AETN$PPL_pplProgramId') or theplatform_metadata.get('AETN$PPL_pplProgramId_OLD'),
                traverse_obj(theplatform_metadata, ('ratings', 0, 'rating')))
            auth = self._extract_mvpd_auth(
                url, video_id, requestor_id, resource, software_statement)

Review comment (suggestion):
Simpler? But also consider if you could use `_html_search_meta()`.
```suggestion
            r'<meta\s[^>]*(?:content="[^"]*tpid/(\d+)"|name="videoId"[^>]+content="(\d+)")',
```
THe proposed pattern works because of a little-known feature (that I don't remember seeing used before) of `_search_regex()` where the first matched group if no group(s) is specified.

Code after:
        }
        if auth:
            query['auth'] = auth
        TP_SMIL_QUERY = [{
            'assetTypes': 'high_video_ak',
            'switch': 'hls_high_ak',
        }, {
            'assetTypes': 'high_video_s3',
        }, {
            'assetTypes': 'high_video_s3',
            'switch': 'hls_high_fastly',
        }]
        formats = []
        subtitles = {}
        last_e = None
        for q in TP_SMIL_QUERY:
            q.update(query)
            m_url = update_url_query(smil_url, q)
            m_url = self._sign_url(m_url, self._THEPLATFORM_KEY, self._THEPLATFORM_SECRET)
            try:
                tp_formats, tp_subtitles = self._extract_theplatform_smil(
                    m_url, video_id, 'Downloading %s SMIL data' % (q.get('switch') or q['assetTypes']))
            except ExtractorError as e:
                if isinstance(e, GeoRestrictedError):
                    raise
                last_e = e
                continue
            formats.extend(tp_formats)
            subtitles = self._merge_subtitles(subtitles, tp_subtitles)
        if last_e and not formats:
            raise last_e
        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
        }

    def _extract_aetn_info(self, domain, filter_key, filter_value, url):
        requestor_id, brand, software_statement = self._DOMAIN_MAP[domain]
        if filter_key == 'canonical':
            webpage = self._download_webpage(url, filter_value)
            graphql_video_id = self._search_regex(
                r'<meta\b[^>]+\bcontent="[^"]*\btpid/(\d+)"', webpage,
                'id') or self._html_search_meta('videoId', webpage, 'GraphQL video ID', fatal=True)
        else:
            graphql_video_id = filter_value

        result = self._download_json(
            'https://yoga.appsvcs.aetnd.com/', graphql_video_id,
            query={
                'brand': brand,