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

Code before:
        # info['title'] is often incomplete (e.g. 'Full Episode', 'Episode 5', etc)
        # Try turning it to 'program - title' naming scheme if possible
        alt_title = info.get('program', {}).get('title')
        if alt_title:
            info['title'] = alt_title + ' - ' + re.sub(r'^' + alt_title + r'[\s\-:]+', '', info['title'])

        description = info.get('description') or info.get(
            'program', {}).get('description') or description

        return {
            'id': video_id,
            'display_id': display_id,
            'title': info['title'],
            'description': description,
            'thumbnail': info.get('image_url'),
            'duration': int_or_none(info.get('duration')),
            'age_limit': age_limit,
            'upload_date': upload_date,
            'formats': formats,
            'subtitles': subtitles,
            'chapters': chapters,
        }


class PBSKidsIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?pbskids\.org/video/(?P<channel>[\w-]+)/(?P<id>\d+)'
    _TESTS = [
        {
            'url': 'https://pbskids.org/video/molly-of-denali/3030407927',
            'md5': '1ded20a017cc6b53446238f1804ce4c7',
            'info_dict': {
                'id': '3030407927',
                'title': 'Bird in the Hand/Bye-Bye Birdie',
                'channel': 'molly-of-denali',
                'duration': 1540,
                'ext': 'mp4',
                'series': 'Molly of Denali',
                'description': 'md5:d006b2211633685d8ebc8d03b6d5611e',
                'categories': ['Episode'],
                'upload_date': '20190718',
            }
        },
        {
            'url': 'https://pbskids.org/video/plum-landing/2365205059',
            'md5': '92e5d189851a64ae1d0237a965be71f5',
            'info_dict': {
                'id': '2365205059',
                'title': 'Cooper\'s Favorite Place in Nature',
                'channel': 'plum-landing',
                'duration': 67,
                'ext': 'mp4',

Review comment (refactor):
we are capturing `channel` and then not doing anything with it

we could extract the value

```py
    def _real_extract(self, url):
        video_id, channel = self._match_valid_url(url).group('id', 'channel')
```

and then use it as a `channel` fallback in case traversal doesn't return one

```py
        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            'channel': channel,
            **traverse_obj(meta, {
```

&nbsp;
or you could just remove the capture group from `_VALID_URL`

Code after:
        # info['title'] is often incomplete (e.g. 'Full Episode', 'Episode 5', etc)
        # Try turning it to 'program - title' naming scheme if possible
        alt_title = info.get('program', {}).get('title')
        if alt_title:
            info['title'] = alt_title + ' - ' + re.sub(r'^' + alt_title + r'[\s\-:]+', '', info['title'])

        description = info.get('description') or info.get(
            'program', {}).get('description') or description

        return {
            'id': video_id,
            'display_id': display_id,
            'title': info['title'],
            'description': description,
            'thumbnail': info.get('image_url'),
            'duration': int_or_none(info.get('duration')),
            'age_limit': age_limit,
            'upload_date': upload_date,
            'formats': formats,
            'subtitles': subtitles,
            'chapters': chapters,
        }


class PBSKidsIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?pbskids\.org/video/[\w-]+/(?P<id>\d+)'
    _TESTS = [
        {
            'url': 'https://pbskids.org/video/molly-of-denali/3030407927',
            'md5': '1ded20a017cc6b53446238f1804ce4c7',
            'info_dict': {
                'id': '3030407927',
                'title': 'Bird in the Hand/Bye-Bye Birdie',
                'channel': 'molly-of-denali',
                'duration': 1540,
                'ext': 'mp4',
                'series': 'Molly of Denali',
                'description': 'md5:d006b2211633685d8ebc8d03b6d5611e',
                'categories': ['Episode'],
                'upload_date': '20190718',
            }
        },
        {
            'url': 'https://pbskids.org/video/plum-landing/2365205059',
            'md5': '92e5d189851a64ae1d0237a965be71f5',
            'info_dict': {
                'id': '2365205059',
                'title': 'Cooper\'s Favorite Place in Nature',
                'channel': 'plum-landing',
                'duration': 67,
                'ext': 'mp4',