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

Code before:
            for component in traverse_obj(morph_payload, (
                    'body', 'components', lambda _, v: v['props']['leadMedia']['identifiers'])):
                lead_media = component['props']['leadMedia']
                programme_id = traverse_obj(lead_media['identifiers'], 'vpid', 'playablePid', expected_type=str)
                if not programme_id:
                    continue
                title = lead_media.get('title') or self._og_search_title(webpage)
                formats, subtitles = self._download_media_selector(programme_id)
                return {
                    'id': programme_id,
                    'title': title,
                    **traverse_obj(lead_media, {
                        'description': ('summary', {str}),
                        'duration': ('duration', ('rawDuration', 'formattedDuration', 'spokenDuration'), {parse_duration}),
                        'uploader': ('masterBrand', {str}),
                        'uploader_id': ('mid', {str}),
                    }),
                    'formats': formats,
                    'subtitles': subtitles,
                }
            body = traverse_obj(morph_payload, (
                'body', 'content', 'article', 'body',
                {lambda s: self._parse_json(s, playlist_id, fatal=False)}))
            added = False
            for video_data in traverse_obj(body, (Ellipsis, 'videoData', {lambda v: v.get('pid') and v})):
                if video_data.get('vpid'):
                    video_id = video_data['vpid']
                    formats, subtitles = self._download_media_selector(video_id)
                    entry = {
                        'id': video_id,
                        'formats': formats,
                        'subtitles': subtitles,
                    }
                else:
                    video_id = video_data['pid']
                    entry = self.url_result(
                        'https://www.bbc.co.uk/programmes/%s' % video_id, BBCCoUkIE.ie_key(),
                        video_id, url_transparent=True)
                entry = merge_dicts(
                    traverse_obj(morph_payload, (
                        'body', 'content', 'article', {
                            'timestamp': ('dateTimeInfo', 'dateTime', {parse_iso8601}),
                        })), traverse_obj(video_data, {
                            'thumbnail': (('iChefImage', 'image'), {url_or_none}, any),
                            'title': (('title', 'caption'), {str}, any),
                            'duration': ('duration', {parse_duration}),
                        }), entry)
                if video_data.get('isLead') and not self._yes_playlist(playlist_id, video_id):
                    return entry
                entries.append(entry)
                added = True

Review comment (suggestion):
```suggestion
            for video_data in traverse_obj(body, (lambda _, v: v['videoData']['pid'], 'videoData')):
                if video_data.get('vpid'):
```

Code after:
            for lead_media in traverse_obj(morph_payload, (
                    'body', 'components', ..., 'props', 'leadMedia', {dict})):
                programme_id = traverse_obj(lead_media, ('identifiers', ('vpid', 'playablePid'), {str}, any))
                if not programme_id:
                    continue
                formats, subtitles = self._download_media_selector(programme_id)
                return {
                    'id': programme_id,
                    'title': lead_media.get('title') or self._og_search_title(webpage),
                    **traverse_obj(lead_media, {
                        'description': ('summary', {str}),
                        'duration': ('duration', ('rawDuration', 'formattedDuration', 'spokenDuration'), {parse_duration}),
                        'uploader': ('masterBrand', {str}),
                        'uploader_id': ('mid', {str}),
                    }),
                    'formats': formats,
                    'subtitles': subtitles,
                }
            body = self._parse_json(traverse_obj(morph_payload, (
                'body', 'content', 'article', 'body')), playlist_id, fatal=False)
            for video_data in traverse_obj(body, (lambda _, v: v['videoData']['pid'], 'videoData')):
                if video_data.get('vpid'):
                    video_id = video_data['vpid']
                    formats, subtitles = self._download_media_selector(video_id)
                    entry = {
                        'id': video_id,
                        'formats': formats,
                        'subtitles': subtitles,
                    }
                else:
                    video_id = video_data['pid']
                    entry = self.url_result(
                        f'https://www.bbc.co.uk/programmes/{video_id}', BBCCoUkIE,
                        video_id, url_transparent=True)
                entry.update({
                    'timestamp': traverse_obj(morph_payload, (
                        'body', 'content', 'article', 'dateTimeInfo', 'dateTime', {parse_iso8601})
                    ),
                    **traverse_obj(video_data, {
                        'thumbnail': (('iChefImage', 'image'), {url_or_none}, any),
                        'title': (('title', 'caption'), {str}, any),
                        'duration': ('duration', {parse_duration}),
                    }),
                })
                if video_data.get('isLead') and not self._yes_playlist(playlist_id, video_id):
                    return entry
                entries.append(entry)
            if entries:
                playlist_title = traverse_obj(morph_payload, (
                    'body', 'content', 'article', 'headline', {str})) or playlist_title
                return self.playlist_result(