]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/nfb.py
[embedthumbnail] Fix thumbnail name in mp3 (#5163)
[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 self._sort_formats(formats)
39
40 return {
41 'id': video_id,
42 'title': self._html_search_regex(
43 r'<[^>]+\bid=["\']titleHeader["\'][^>]*>\s*<h1[^>]*>\s*([^<]+?)\s*</h1>',
44 webpage, 'title', default=None),
45 'description': self._html_search_regex(
46 r'<[^>]+\bid=["\']tabSynopsis["\'][^>]*>\s*<p[^>]*>\s*([^<]+)',
47 webpage, 'description', default=None),
48 'thumbnail': self._html_search_regex(
49 r'poster:\s*\'([^\']+)',
50 player, 'thumbnail', default=None),
51 'uploader': self._html_search_regex(
52 r'<[^>]+\bitemprop=["\']name["\'][^>]*>([^<]+)',
53 webpage, 'uploader', default=None),
54 'release_year': int_or_none(self._html_search_regex(
55 r'<[^>]+\bitemprop=["\']datePublished["\'][^>]*>([^<]+)',
56 webpage, 'release_year', default=None)),
57 'formats': formats,
58 'subtitles': subtitles,
59 }