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

Code before:
            'title': 'Afterlife',
            'description': 'md5:84951394f594f1fb1e62d9c43242fdf5',
            'release_year': 1978,
            'duration': 420.0,
            'uploader': 'Ishu Patel',
            'thumbnail': r're:^https?://.*\.jpg$',
        },
        'params': {'skip_download': 'm3u8'},
    }]

    def _real_extract(self, url):
        site, type_, slug = self._match_valid_url(url).group('site', 'type', 'id')
        # Need to construct the URL since we match /embed/player/ URLs as well
        webpage, urlh = self._download_webpage_handle(f'https://www.{site}.ca/{type_}/{slug}/', slug)
        # type_ can change from film to serie(s) after redirect; new slug may have episode number
        type_, slug = self._match_valid_url(urlh.url).group('type', 'id')

        embed_url = urljoin(f'https://www.{site}.ca', self._html_search_regex(
            r'<[^>]+\bid=["\']player-iframe["\'][^>]*\bsrc=["\']([^"\']+)', webpage, 'embed url'))
        video_id = self._match_id(embed_url)  # embed url has unique slug
        player = self._download_webpage(embed_url, video_id, 'Downloading player page')
        if 'MESSAGE_GEOBLOCKED' in player:
            self.raise_geo_restricted(countries=self._GEO_COUNTRIES)

        source = self._html_search_regex(r'source:\s*\'([^\']+)', player, 'source')
        formats, subtitles = self._extract_m3u8_formats_and_subtitles(source, video_id, 'mp4')

        info = {
            'id': video_id,
            'title': self._html_search_regex(
                r'<[^>]+\bid=["\']titleHeader["\'][^>]*>\s*<h1[^>]*>\s*([^<]+?)\s*</h1>',
                webpage, 'title', default=None),
            'description': self._html_search_regex(
                r'<[^>]+\bid=["\']tabSynopsis["\'][^>]*>\s*<p[^>]*>\s*([^<]+)',
                webpage, 'description', default=None),
            'thumbnail': self._html_search_regex(
                r'poster:\s*\'([^\']+)', player, 'thumbnail', default=None),
            'uploader': self._html_search_regex(
                r'<[^>]+\bitemprop=["\']name["\'][^>]*>([^<]+)', webpage, 'uploader', default=None),
            'release_year': int_or_none(self._html_search_regex(
                r'<[^>]+\bitemprop=["\']datePublished["\'][^>]*>([^<]+)',
                webpage, 'release_year', default=None)),
        } if type_ == 'film' else self._extract_ep_info(self._extract_ep_data(webpage, video_id, slug), video_id)

        return merge_dicts({
            'formats': formats,
            'subtitles': subtitles,
        }, info, self._search_json_ld(webpage, video_id, default={}))


class NFBSeriesIE(NFBBaseIE):

Review comment (refactor):
DV sources (described video) can also be extracted:
```suggestion
        formats, subtitles = self._extract_m3u8_formats_and_subtitles(
            self._html_search_regex(r'source:\s*\'([^\']+)', player, 'm3u8 url'),
            video_id, 'mp4', m3u8_id='hls')
        
        if dv_source := self._html_search_regex(r'dvSource:\s*\'([^\']+)', player, 'dv', default=None):
            fmts, subs = self._extract_m3u8_formats_and_subtitles(
                dv_source, video_id, 'mp4', m3u8_id='dv', preference=-2, fatal=False)
            for fmt in fmts:
                fmt['format_note'] = 'described video'
            formats.extend(fmts)
            self._merge_subtitles(subs, target=subtitles)
```
Here is an example: https://www.nfb.ca/film/lay-down-your-heart/

Code after:
            'title': 'Afterlife',
            'description': 'md5:84951394f594f1fb1e62d9c43242fdf5',
            'release_year': 1978,
            'duration': 420.0,
            'uploader': 'Ishu Patel',
            'thumbnail': r're:^https?://.*\.jpg$',
        },
        'params': {'skip_download': 'm3u8'},
    }]

    def _real_extract(self, url):
        site, type_, slug = self._match_valid_url(url).group('site', 'type', 'id')
        # Need to construct the URL since we match /embed/player/ URLs as well
        webpage, urlh = self._download_webpage_handle(f'https://www.{site}.ca/{type_}/{slug}/', slug)
        # type_ can change from film to serie(s) after redirect; new slug may have episode number
        type_, slug = self._match_valid_url(urlh.url).group('type', 'id')

        embed_url = urljoin(f'https://www.{site}.ca', self._html_search_regex(
            r'<[^>]+\bid=["\']player-iframe["\'][^>]*\bsrc=["\']([^"\']+)', webpage, 'embed url'))
        video_id = self._match_id(embed_url)  # embed url has unique slug
        player = self._download_webpage(embed_url, video_id, 'Downloading player page')
        if 'MESSAGE_GEOBLOCKED' in player:
            self.raise_geo_restricted(countries=self._GEO_COUNTRIES)

        formats, subtitles = self._extract_m3u8_formats_and_subtitles(
            self._html_search_regex(r'source:\s*\'([^\']+)', player, 'm3u8 url'),
            video_id, 'mp4', m3u8_id='hls')

        if dv_source := self._html_search_regex(r'dvSource:\s*\'([^\']+)', player, 'dv', default=None):
            fmts, subs = self._extract_m3u8_formats_and_subtitles(
                dv_source, video_id, 'mp4', m3u8_id='dv', preference=-2, fatal=False)
            for fmt in fmts:
                fmt['format_note'] = 'described video'
            formats.extend(fmts)
            self._merge_subtitles(subs, target=subtitles)

        info = {
            'id': video_id,
            'title': self._html_search_regex(
                r'<[^>]+\bid=["\']titleHeader["\'][^>]*>\s*<h1[^>]*>\s*([^<]+?)\s*</h1>',
                webpage, 'title', default=None),
            'description': self._html_search_regex(
                r'<[^>]+\bid=["\']tabSynopsis["\'][^>]*>\s*<p[^>]*>\s*([^<]+)',
                webpage, 'description', default=None),
            'thumbnail': self._html_search_regex(
                r'poster:\s*\'([^\']+)', player, 'thumbnail', default=None),
            'uploader': self._html_search_regex(
                r'<[^>]+\bitemprop=["\']name["\'][^>]*>([^<]+)', webpage, 'uploader', default=None),
            'release_year': int_or_none(self._html_search_regex(
                r'<[^>]+\bitemprop=["\']datePublished["\'][^>]*>([^<]+)',
                webpage, 'release_year', default=None)),