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

Code before:
        properties = page_data.get('properties')
        query = {
            'mbr': 'true',
            'manifest': 'm3u',
        }

        has_releasePid = False
        video_player_count = 0
        try:
            for v in page_data['children']:
                if v['type'] == 'video-player':
                    releasePid = \
                        v['properties']['currentVideo']['meta']['releasePid']
                    tp_path = 'M_UwQC/' + releasePid
                    media_url = 'https://link.theplatform.com/s/' + tp_path
                    has_releasePid = True
                    video_player_count += 1
        except KeyError:
            pass
        if video_player_count > 1:
            self.report_warning('The JSON data has more than one video player.')
        # This extractor originally used videoPid instead of releasePid
        # but some of those resulting manifests have DRM.
        if not has_releasePid:
            tp_path = 'M_UwQC/media/' + properties['videoPid']
            media_url = 'https://link.theplatform.com/s/' + tp_path

        theplatform_metadata = self._download_theplatform_metadata(tp_path, display_id)
        info = self._parse_theplatform_metadata(theplatform_metadata)
        video_id = theplatform_metadata['pid']
        title = theplatform_metadata['title']
        rating = try_get(
            theplatform_metadata, lambda x: x['ratings'][0]['rating'])
        video_category = properties.get('videoCategory')
        if video_category and video_category.endswith('-Auth'):
            resource = self._get_mvpd_resource(
                requestor_id, title, video_id, rating)
            query['auth'] = self._extract_mvpd_auth(
                url, video_id, requestor_id, resource)
        media_url = update_url_query(media_url, query)
        formats, subtitles = self._extract_theplatform_smil(
            media_url, video_id)
        self._sort_formats(formats)

        thumbnails = []
        thumbnail_temp = []
        thumbnail_temp.append(info.get('thumbnail'))
        thumbnail_temp.append(properties.get('imageDesktop'))
        for thumbnail_url in thumbnail_temp:
            if not thumbnail_url:
                continue

Review comment (suggestion):
```suggestion
        media_url = None
        for v in (page_data.get('children') or {}):
            if not v.get('type') == 'video-player':
                continue
            releasePid = try_get(
                v, lambda x: x['properties']['currentVideo']['meta']['releasePid'])
            if not releasePid:
                break
            if media_url:
                self.report_warning('The JSON data has more than one video player. Only the first video will be downloaded')
                break
            tp_path = 'M_UwQC/' + releasePid
            media_url = 'https://link.theplatform.com/s/' + tp_path
        # Fallback to videoPid which may have DRM
        if not media_url:
            tp_path = 'M_UwQC/media/' + properties['videoPid']
            media_url = 'https://link.theplatform.com/s/' + tp_path
```

Untested. Removes unnecessary variables and try block

Code after:
        properties = page_data.get('properties') or {}
        query = {
            'mbr': 'true',
            'manifest': 'm3u',
        }

        video_player_count = 0
        try:
            for v in page_data['children']:
                if v.get('type') == 'video-player':
                    releasePid = v['properties']['currentVideo']['meta']['releasePid']
                    tp_path = 'M_UwQC/' + releasePid
                    media_url = 'https://link.theplatform.com/s/' + tp_path
                    video_player_count += 1
        except KeyError:
            pass
        if video_player_count > 1:
            self.report_warning(
                'The JSON data has %d video players. Only one will be extracted' % video_player_count)

        # Fall back to videoPid if releasePid not found.
        # TODO: Fall back to videoPid if releasePid manifest uses DRM.
        if not video_player_count:
            tp_path = 'M_UwQC/media/' + properties['videoPid']
            media_url = 'https://link.theplatform.com/s/' + tp_path

        theplatform_metadata = self._download_theplatform_metadata(tp_path, display_id)
        info = self._parse_theplatform_metadata(theplatform_metadata)
        video_id = theplatform_metadata['pid']
        title = theplatform_metadata['title']
        rating = try_get(
            theplatform_metadata, lambda x: x['ratings'][0]['rating'])
        video_category = properties.get('videoCategory')
        if video_category and video_category.endswith('-Auth'):
            resource = self._get_mvpd_resource(
                requestor_id, title, video_id, rating)
            query['auth'] = self._extract_mvpd_auth(
                url, video_id, requestor_id, resource)
        media_url = update_url_query(media_url, query)
        formats, subtitles = self._extract_theplatform_smil(
            media_url, video_id)
        self._sort_formats(formats)

        thumbnails = []
        thumbnail_urls = [properties.get('imageDesktop')]
        if 'thumbnail' in info:
            thumbnail_urls.append(info.pop('thumbnail'))
        for thumbnail_url in thumbnail_urls:
            if not thumbnail_url:
                continue
            mobj = re.search(r'(\d+)x(\d+)', thumbnail_url)