1 from __future__ import unicode_literals
5 from .common import InfoExtractor
12 class NFBIE(InfoExtractor):
14 IE_DESC = 'National Film Board of Canada'
15 _VALID_URL = r'https?://(?:www\.)?(nfb|onf)\.ca/film/(?P<id>[\da-z_-]+)'
18 'url': 'https://www.nfb.ca/film/qallunaat_why_white_people_are_funny',
20 'id': 'qallunaat_why_white_people_are_funny',
22 'title': 'Qallunaat! Why White People Are Funny ',
23 'description': 'md5:836d8aff55e087d04d9f6df554d4e038',
25 'uploader': 'Mark Sandiford',
26 'uploader_id': 'mark-sandiford',
30 'skip_download': True,
34 def _real_extract(self, url):
35 mobj = re.match(self._VALID_URL, url)
36 video_id = mobj.group('id')
38 page = self._download_webpage('https://www.nfb.ca/film/%s' % video_id, video_id, 'Downloading film page')
40 uploader_id = self._html_search_regex(r'<a class="director-link" href="/explore-all-directors/([^/]+)/"',
41 page, 'director id', fatal=False)
42 uploader = self._html_search_regex(r'<em class="director-name" itemprop="name">([^<]+)</em>',
43 page, 'director name', fatal=False)
45 request = compat_urllib_request.Request('https://www.nfb.ca/film/%s/player_config' % video_id,
46 compat_urllib_parse.urlencode({'getConfig': 'true'}).encode('ascii'))
47 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
48 request.add_header('X-NFB-Referer', 'http://www.nfb.ca/medias/flash/NFBVideoPlayer.swf')
50 config = self._download_xml(request, video_id, 'Downloading player config XML')
52 thumbnail = config.find("./player/stream/media[@type='posterImage']/assets/asset[@quality='high']/default/url").text
53 video = config.find("./player/stream/media[@type='video']")
54 duration = int(video.get('duration'))
55 title = video.find('title').text
56 description = video.find('description').text
58 # It seems assets always go from lower to better quality, so no need to sort
60 'url': x.find('default/streamerURI').text + '/',
61 'play_path': x.find('default/url').text,
64 'format_id': x.get('quality'),
65 } for x in video.findall('assets/asset')]
70 'description': description,
71 'thumbnail': thumbnail,
74 'uploader_id': uploader_id,