]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/nfb.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / nfb.py
1 from .common import InfoExtractor
2 from ..utils import int_or_none
3
4
5 class NFBIE(InfoExtractor):
6 _VALID_URL = r'https?://(?:www\.)?nfb\.ca/film/(?P<id>[^/?#&]+)'
7 _TESTS = [{
8 'url': 'https://www.nfb.ca/film/trafficopter/',
9 'info_dict': {
10 'id': 'trafficopter',
11 'ext': 'mp4',
12 'title': 'Trafficopter',
13 'description': 'md5:060228455eb85cf88785c41656776bc0',
14 'thumbnail': r're:^https?://.*\.jpg$',
15 'uploader': 'Barrie Howells',
16 'release_year': 1972,
17 },
18 }]
19
20 def _real_extract(self, url):
21 video_id = self._match_id(url)
22
23 webpage = self._download_webpage('https://www.nfb.ca/film/%s/' % video_id, video_id)
24
25 iframe = self._html_search_regex(
26 r'<[^>]+\bid=["\']player-iframe["\'][^>]*src=["\']([^"\']+)',
27 webpage, 'iframe', default=None, fatal=True)
28 if iframe.startswith('/'):
29 iframe = f'https://www.nfb.ca{iframe}'
30
31 player = self._download_webpage(iframe, video_id)
32
33 source = self._html_search_regex(
34 r'source:\s*\'([^\']+)',
35 player, 'source', default=None, fatal=True)
36
37 formats, subtitles = self._extract_m3u8_formats_and_subtitles(source, video_id, ext='mp4')
38
39 return {
40 'id': video_id,
41 'title': self._html_search_regex(
42 r'<[^>]+\bid=["\']titleHeader["\'][^>]*>\s*<h1[^>]*>\s*([^<]+?)\s*</h1>',
43 webpage, 'title', default=None),
44 'description': self._html_search_regex(
45 r'<[^>]+\bid=["\']tabSynopsis["\'][^>]*>\s*<p[^>]*>\s*([^<]+)',
46 webpage, 'description', default=None),
47 'thumbnail': self._html_search_regex(
48 r'poster:\s*\'([^\']+)',
49 player, 'thumbnail', default=None),
50 'uploader': self._html_search_regex(
51 r'<[^>]+\bitemprop=["\']name["\'][^>]*>([^<]+)',
52 webpage, 'uploader', default=None),
53 'release_year': int_or_none(self._html_search_regex(
54 r'<[^>]+\bitemprop=["\']datePublished["\'][^>]*>([^<]+)',
55 webpage, 'release_year', default=None)),
56 'formats': formats,
57 'subtitles': subtitles,
58 }