]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nfb.py
1 from __future__
import unicode_literals
3 from .common
import InfoExtractor
10 class NFBIE(InfoExtractor
):
12 IE_DESC
= 'National Film Board of Canada'
13 _VALID_URL
= r
'https?://(?:www\.)?(?:nfb|onf)\.ca/film/(?P<id>[\da-z_-]+)'
16 'url': 'https://www.nfb.ca/film/qallunaat_why_white_people_are_funny',
18 'id': 'qallunaat_why_white_people_are_funny',
20 'title': 'Qallunaat! Why White People Are Funny ',
21 'description': 'md5:836d8aff55e087d04d9f6df554d4e038',
23 'uploader': 'Mark Sandiford',
24 'uploader_id': 'mark-sandiford',
28 'skip_download': True,
32 def _real_extract(self
, url
):
33 video_id
= self
._match
_id
(url
)
34 page
= self
._download
_webpage
(
35 'https://www.nfb.ca/film/%s' % video_id
, video_id
,
36 'Downloading film page')
38 uploader_id
= self
._html
_search
_regex
(r
'<a class="director-link" href="/explore-all-directors/([^/]+)/"',
39 page
, 'director id', fatal
=False)
40 uploader
= self
._html
_search
_regex
(r
'<em class="director-name" itemprop="name">([^<]+)</em>',
41 page
, 'director name', fatal
=False)
43 request
= compat_urllib_request
.Request('https://www.nfb.ca/film/%s/player_config' % video_id
,
44 compat_urllib_parse
.urlencode({'getConfig': 'true'}).encode('ascii'))
45 request
.add_header('Content-Type', 'application/x-www-form-urlencoded')
46 request
.add_header('X-NFB-Referer', 'http://www.nfb.ca/medias/flash/NFBVideoPlayer.swf')
48 config
= self
._download
_xml
(request
, video_id
, 'Downloading player config XML')
56 def extract_thumbnail(media
):
58 for asset
in media
.findall('assets/asset'):
59 thumbnails
[asset
.get('quality')] = asset
.find('default/url').text
62 if 'high' in thumbnails
:
63 return thumbnails
['high']
64 return list(thumbnails
.values())[0]
66 for media
in config
.findall('./player/stream/media'):
67 if media
.get('type') == 'posterImage':
68 thumbnail
= extract_thumbnail(media
)
69 elif media
.get('type') == 'video':
70 duration
= int(media
.get('duration'))
71 title
= media
.find('title').text
72 description
= media
.find('description').text
73 # It seems assets always go from lower to better quality, so no need to sort
74 for asset
in media
.findall('assets/asset'):
77 'url': x
.find('streamerURI').text
,
78 'app': x
.find('streamerURI').text
.split('/', 3)[3],
79 'play_path': x
.find('url').text
,
82 'format_id': '%s-%s' % (x
.tag
, asset
.get('quality')),
88 'description': description
,
89 'thumbnail': thumbnail
,
92 'uploader_id': uploader_id
,