You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.8 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_urllib_request,
  6. compat_urllib_parse,
  7. )
  8. class NFBIE(InfoExtractor):
  9. IE_NAME = 'nfb'
  10. IE_DESC = 'National Film Board of Canada'
  11. _VALID_URL = r'https?://(?:www\.)?nfb\.ca/film/(?P<id>[\da-z_-]+)'
  12. _TEST = {
  13. 'url': 'https://www.nfb.ca/film/qallunaat_why_white_people_are_funny',
  14. 'info_dict': {
  15. 'id': 'qallunaat_why_white_people_are_funny',
  16. 'ext': 'mp4',
  17. 'title': 'Qallunaat! Why White People Are Funny ',
  18. 'description': 'md5:836d8aff55e087d04d9f6df554d4e038',
  19. 'duration': 3128,
  20. 'uploader': 'Mark Sandiford',
  21. 'uploader_id': 'mark-sandiford',
  22. },
  23. 'params': {
  24. # rtmp download
  25. 'skip_download': True,
  26. }
  27. }
  28. def _real_extract(self, url):
  29. mobj = re.match(self._VALID_URL, url)
  30. video_id = mobj.group('id')
  31. page = self._download_webpage(url, video_id, 'Downloading film page')
  32. uploader_id = self._html_search_regex(r'<a class="director-link" href="/explore-all-directors/([^/]+)/"',
  33. page, 'director id', fatal=False)
  34. uploader = self._html_search_regex(r'<em class="director-name" itemprop="name">([^<]+)</em>',
  35. page, 'director name', fatal=False)
  36. request = compat_urllib_request.Request('https://www.nfb.ca/film/%s/player_config' % video_id,
  37. compat_urllib_parse.urlencode({'getConfig': 'true'}))
  38. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  39. request.add_header('X-NFB-Referer', 'http://www.nfb.ca/medias/flash/NFBVideoPlayer.swf')
  40. config = self._download_xml(request, video_id, 'Downloading player config XML')
  41. thumbnail = config.find("./player/stream/media[@type='posterImage']/assets/asset[@quality='high']/default/url").text
  42. video = config.find("./player/stream/media[@type='video']")
  43. duration = int(video.get('duration'))
  44. title = video.find('title').text
  45. description = video.find('description').text
  46. # It seems assets always go from lower to better quality, so no need to sort
  47. formats = [{
  48. 'url': x.find('default/streamerURI').text + '/',
  49. 'play_path': x.find('default/url').text,
  50. 'rtmp_live': False,
  51. 'ext': 'mp4',
  52. 'format_id': x.get('quality'),
  53. } for x in video.findall('assets/asset')]
  54. return {
  55. 'id': video_id,
  56. 'title': title,
  57. 'description': description,
  58. 'thumbnail': thumbnail,
  59. 'duration': duration,
  60. 'uploader': uploader,
  61. 'uploader_id': uploader_id,
  62. 'formats': formats,
  63. }