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.

95 lines
3.6 KiB

Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
10 years ago
  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. sanitized_Request,
  5. urlencode_postdata,
  6. )
  7. class NFBIE(InfoExtractor):
  8. IE_NAME = 'nfb'
  9. IE_DESC = 'National Film Board of Canada'
  10. _VALID_URL = r'https?://(?:www\.)?(?:nfb|onf)\.ca/film/(?P<id>[\da-z_-]+)'
  11. _TEST = {
  12. 'url': 'https://www.nfb.ca/film/qallunaat_why_white_people_are_funny',
  13. 'info_dict': {
  14. 'id': 'qallunaat_why_white_people_are_funny',
  15. 'ext': 'mp4',
  16. 'title': 'Qallunaat! Why White People Are Funny ',
  17. 'description': 'md5:836d8aff55e087d04d9f6df554d4e038',
  18. 'duration': 3128,
  19. 'uploader': 'Mark Sandiford',
  20. 'uploader_id': 'mark-sandiford',
  21. },
  22. 'params': {
  23. # rtmp download
  24. 'skip_download': True,
  25. }
  26. }
  27. def _real_extract(self, url):
  28. video_id = self._match_id(url)
  29. page = self._download_webpage(
  30. 'https://www.nfb.ca/film/%s' % video_id, video_id,
  31. '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 = sanitized_Request(
  37. 'https://www.nfb.ca/film/%s/player_config' % video_id,
  38. urlencode_postdata({'getConfig': 'true'}))
  39. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  40. request.add_header('X-NFB-Referer', 'http://www.nfb.ca/medias/flash/NFBVideoPlayer.swf')
  41. config = self._download_xml(request, video_id, 'Downloading player config XML')
  42. title = None
  43. description = None
  44. thumbnail = None
  45. duration = None
  46. formats = []
  47. def extract_thumbnail(media):
  48. thumbnails = {}
  49. for asset in media.findall('assets/asset'):
  50. thumbnails[asset.get('quality')] = asset.find('default/url').text
  51. if not thumbnails:
  52. return None
  53. if 'high' in thumbnails:
  54. return thumbnails['high']
  55. return list(thumbnails.values())[0]
  56. for media in config.findall('./player/stream/media'):
  57. if media.get('type') == 'posterImage':
  58. thumbnail = extract_thumbnail(media)
  59. elif media.get('type') == 'video':
  60. duration = int(media.get('duration'))
  61. title = media.find('title').text
  62. description = media.find('description').text
  63. # It seems assets always go from lower to better quality, so no need to sort
  64. for asset in media.findall('assets/asset'):
  65. for x in asset:
  66. formats.append({
  67. 'url': x.find('streamerURI').text,
  68. 'app': x.find('streamerURI').text.split('/', 3)[3],
  69. 'play_path': x.find('url').text,
  70. 'rtmp_live': False,
  71. 'ext': 'mp4',
  72. 'format_id': '%s-%s' % (x.tag, asset.get('quality')),
  73. })
  74. return {
  75. 'id': video_id,
  76. 'title': title,
  77. 'description': description,
  78. 'thumbnail': thumbnail,
  79. 'duration': duration,
  80. 'uploader': uploader,
  81. 'uploader_id': uploader_id,
  82. 'formats': formats,
  83. }