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.

112 lines
4.4 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. clean_html,
  5. determine_ext,
  6. int_or_none,
  7. qualities,
  8. urlencode_postdata,
  9. xpath_text,
  10. )
  11. class NFBIE(InfoExtractor):
  12. IE_NAME = 'nfb'
  13. IE_DESC = 'National Film Board of Canada'
  14. _VALID_URL = r'https?://(?:www\.)?(?:nfb|onf)\.ca/film/(?P<id>[\da-z_-]+)'
  15. _TEST = {
  16. 'url': 'https://www.nfb.ca/film/qallunaat_why_white_people_are_funny',
  17. 'info_dict': {
  18. 'id': 'qallunaat_why_white_people_are_funny',
  19. 'ext': 'flv',
  20. 'title': 'Qallunaat! Why White People Are Funny ',
  21. 'description': 'md5:6b8e32dde3abf91e58857b174916620c',
  22. 'duration': 3128,
  23. 'creator': 'Mark Sandiford',
  24. 'uploader': 'Mark Sandiford',
  25. },
  26. 'params': {
  27. # rtmp download
  28. 'skip_download': True,
  29. }
  30. }
  31. def _real_extract(self, url):
  32. video_id = self._match_id(url)
  33. config = self._download_xml(
  34. 'https://www.nfb.ca/film/%s/player_config' % video_id,
  35. video_id, 'Downloading player config XML',
  36. data=urlencode_postdata({'getConfig': 'true'}),
  37. headers={
  38. 'Content-Type': 'application/x-www-form-urlencoded',
  39. 'X-NFB-Referer': 'http://www.nfb.ca/medias/flash/NFBVideoPlayer.swf'
  40. })
  41. title, description, thumbnail, duration, uploader, author = [None] * 6
  42. thumbnails, formats = [[]] * 2
  43. subtitles = {}
  44. for media in config.findall('./player/stream/media'):
  45. if media.get('type') == 'posterImage':
  46. quality_key = qualities(('low', 'high'))
  47. thumbnails = []
  48. for asset in media.findall('assets/asset'):
  49. asset_url = xpath_text(asset, 'default/url', default=None)
  50. if not asset_url:
  51. continue
  52. quality = asset.get('quality')
  53. thumbnails.append({
  54. 'url': asset_url,
  55. 'id': quality,
  56. 'preference': quality_key(quality),
  57. })
  58. elif media.get('type') == 'video':
  59. title = xpath_text(media, 'title', fatal=True)
  60. for asset in media.findall('assets/asset'):
  61. quality = asset.get('quality')
  62. height = int_or_none(self._search_regex(
  63. r'^(\d+)[pP]$', quality or '', 'height', default=None))
  64. for node in asset:
  65. streamer = xpath_text(node, 'streamerURI', default=None)
  66. if not streamer:
  67. continue
  68. play_path = xpath_text(node, 'url', default=None)
  69. if not play_path:
  70. continue
  71. formats.append({
  72. 'url': streamer,
  73. 'app': streamer.split('/', 3)[3],
  74. 'play_path': play_path,
  75. 'rtmp_live': False,
  76. 'ext': 'flv',
  77. 'format_id': '%s-%s' % (node.tag, quality) if quality else node.tag,
  78. 'height': height,
  79. })
  80. self._sort_formats(formats)
  81. description = clean_html(xpath_text(media, 'description'))
  82. uploader = xpath_text(media, 'author')
  83. duration = int_or_none(media.get('duration'))
  84. for subtitle in media.findall('./subtitles/subtitle'):
  85. subtitle_url = xpath_text(subtitle, 'url', default=None)
  86. if not subtitle_url:
  87. continue
  88. lang = xpath_text(subtitle, 'lang', default='en')
  89. subtitles.setdefault(lang, []).append({
  90. 'url': subtitle_url,
  91. 'ext': (subtitle.get('format') or determine_ext(subtitle_url)).lower(),
  92. })
  93. return {
  94. 'id': video_id,
  95. 'title': title,
  96. 'description': description,
  97. 'thumbnails': thumbnails,
  98. 'duration': duration,
  99. 'creator': uploader,
  100. 'uploader': uploader,
  101. 'formats': formats,
  102. 'subtitles': subtitles,
  103. }