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

Code before:
from .common import InfoExtractor
from ..utils import (
    int_or_none,
    join_nonempty,
    merge_dicts,
    parse_count,
    url_or_none,
)
from ..utils.traversal import traverse_obj


class NFBBaseIE(InfoExtractor):
    _VALID_URL_BASE = r'https?://(?:www\.)?(?P<site>nfb|onf)\.ca'
    _GEO_COUNTRIES = ['CA']

    def _extract_ep_data(self, webpage, video_id, fatal=False):
        return self._search_json(
            r'episodesData\s*:', webpage, 'episode data', video_id,
            contains_pattern=r'\s*{(?s:.+)}\s*', fatal=fatal) or []

    def _extract_ep_info(self, data, video_id, slug=None):
        info = traverse_obj(data, (lambda _, v: video_id in v['embed_url'], {
            'description': ('description', {str}),
            'thumbnail': ('thumbnail_url', {url_or_none}),
            'uploader': ('data_layer', 'episodeMaker', {str}),
            'release_year': ('data_layer', 'episodeYear', {int_or_none}),
            'episode': ('data_layer', 'episodeTitle', {str}),
            'season': ('data_layer', 'seasonTitle', {str}),
            'season_number': ('data_layer', 'seasonTitle', {parse_count}),
            'series': ('data_layer', 'seriesTitle', {str}),
        }), get_all=False)

        return {
            **info,
            'id': video_id,
            'title': join_nonempty('series', 'episode', from_dict=info, delim=' - '),
            'episode_number': int_or_none(self._search_regex(
                r'[/-]e(?:pisode)?-?(\d+)(?:[/-]|$)', slug or video_id, 'episode number', default=None)),
        }


class NFBIE(NFBBaseIE):
    IE_NAME = 'nfb'
    IE_DESC = 'nfb.ca and onf.ca films and episodes'

Review comment (refactor):
we can simplify this now
```suggestion
            r'episodesData\s*:', webpage, 'episode data', video_id, fatal=fatal) or {}
```

Code after:
from .common import InfoExtractor
from ..utils import (
    int_or_none,
    join_nonempty,
    merge_dicts,
    parse_count,
    url_or_none,
)
from ..utils.traversal import traverse_obj


class NFBBaseIE(InfoExtractor):
    _VALID_URL_BASE = r'https?://(?:www\.)?(?P<site>nfb|onf)\.ca'
    _GEO_COUNTRIES = ['CA']

    def _extract_ep_data(self, webpage, video_id, fatal=False):
        return self._search_json(
            r'episodesData\s*:', webpage, 'episode data', video_id, fatal=fatal) or {}

    def _extract_ep_info(self, data, video_id, slug=None):
        info = traverse_obj(data, (lambda _, v: video_id in v['embed_url'], {
            'description': ('description', {str}),
            'thumbnail': ('thumbnail_url', {url_or_none}),
            'uploader': ('data_layer', 'episodeMaker', {str}),
            'release_year': ('data_layer', 'episodeYear', {int_or_none}),
            'episode': ('data_layer', 'episodeTitle', {str}),
            'season': ('data_layer', 'seasonTitle', {str}),
            'season_number': ('data_layer', 'seasonTitle', {parse_count}),
            'series': ('data_layer', 'seriesTitle', {str}),
        }), get_all=False)

        return {
            **info,
            'id': video_id,
            'title': join_nonempty('series', 'episode', from_dict=info, delim=' - '),
            'episode_number': int_or_none(self._search_regex(
                r'[/-]e(?:pisode)?-?(\d+)(?:[/-]|$)', slug or video_id, 'episode number', default=None)),
        }


class NFBIE(NFBBaseIE):
    IE_NAME = 'nfb'
    IE_DESC = 'nfb.ca and onf.ca films and episodes'
    _VALID_URL = [