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.

127 lines
5.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import (
  7. int_or_none,
  8. parse_iso8601,
  9. unescapeHTML,
  10. qualities,
  11. )
  12. class Revision3IE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?(?P<domain>(?:revision3|testtube|animalist)\.com)/(?P<id>[^/]+(?:/[^/?#]+)?)'
  14. _TESTS = [{
  15. 'url': 'http://www.revision3.com/technobuffalo/5-google-predictions-for-2016',
  16. 'md5': 'd94a72d85d0a829766de4deb8daaf7df',
  17. 'info_dict': {
  18. 'id': '73034',
  19. 'display_id': 'technobuffalo/5-google-predictions-for-2016',
  20. 'ext': 'webm',
  21. 'title': '5 Google Predictions for 2016',
  22. 'description': 'Google had a great 2015, but it\'s already time to look ahead. Here are our five predictions for 2016.',
  23. 'upload_date': '20151228',
  24. 'timestamp': 1451325600,
  25. 'duration': 187,
  26. 'uploader': 'TechnoBuffalo',
  27. 'uploader_id': 'technobuffalo',
  28. }
  29. }, {
  30. 'url': 'http://testtube.com/brainstuff',
  31. 'info_dict': {
  32. 'id': '251',
  33. 'title': 'BrainStuff',
  34. 'description': 'Whether the topic is popcorn or particle physics, you can count on the HowStuffWorks team to explore-and explain-the everyday science in the world around us on BrainStuff.',
  35. },
  36. 'playlist_mincount': 93,
  37. }, {
  38. 'url': 'https://testtube.com/dnews/5-weird-ways-plants-can-eat-animals?utm_source=FB&utm_medium=DNews&utm_campaign=DNewsSocial',
  39. 'info_dict': {
  40. 'id': '60163',
  41. 'display_id': 'dnews/5-weird-ways-plants-can-eat-animals',
  42. 'duration': 275,
  43. 'ext': 'webm',
  44. 'title': '5 Weird Ways Plants Can Eat Animals',
  45. 'description': 'Why have some plants evolved to eat meat?',
  46. 'upload_date': '20150120',
  47. 'timestamp': 1421763300,
  48. 'uploader': 'DNews',
  49. 'uploader_id': 'dnews',
  50. },
  51. }]
  52. _PAGE_DATA_TEMPLATE = 'http://www.%s/apiProxy/ddn/%s?domain=%s'
  53. _API_KEY = 'ba9c741bce1b9d8e3defcc22193f3651b8867e62'
  54. def _real_extract(self, url):
  55. domain, display_id = re.match(self._VALID_URL, url).groups()
  56. page_info = self._download_json(
  57. self._PAGE_DATA_TEMPLATE % (domain, display_id, domain), display_id)
  58. if page_info['data']['type'] == 'episode':
  59. episode_data = page_info['data']
  60. video_id = compat_str(episode_data['video']['data']['id'])
  61. video_data = self._download_json(
  62. 'http://revision3.com/api/getPlaylist.json?api_key=%s&codecs=h264,vp8,theora&video_id=%s' % (self._API_KEY, video_id),
  63. video_id)['items'][0]
  64. formats = []
  65. for vcodec, media in video_data['media'].items():
  66. for quality_id, quality in media.items():
  67. if quality_id == 'hls':
  68. formats.extend(self._extract_m3u8_formats(
  69. quality['url'], video_id, 'mp4',
  70. 'm3u8_native', m3u8_id='hls', fatal=False))
  71. else:
  72. formats.append({
  73. 'url': quality['url'],
  74. 'format_id': '%s-%s' % (vcodec, quality_id),
  75. 'tbr': int_or_none(quality.get('bitrate')),
  76. 'vcodec': vcodec,
  77. })
  78. self._sort_formats(formats)
  79. preference = qualities(['mini', 'small', 'medium', 'large'])
  80. thumbnails = [{
  81. 'url': image_url,
  82. 'id': image_id,
  83. 'preference': preference(image_id)
  84. } for image_id, image_url in video_data.get('images', {}).items()]
  85. return {
  86. 'id': video_id,
  87. 'display_id': display_id,
  88. 'title': unescapeHTML(video_data['title']),
  89. 'description': unescapeHTML(video_data.get('summary')),
  90. 'timestamp': parse_iso8601(episode_data.get('publishTime'), ' '),
  91. 'author': episode_data.get('author'),
  92. 'uploader': video_data.get('show', {}).get('name'),
  93. 'uploader_id': video_data.get('show', {}).get('slug'),
  94. 'duration': int_or_none(video_data.get('duration')),
  95. 'thumbnails': thumbnails,
  96. 'formats': formats,
  97. }
  98. else:
  99. show_data = page_info['show']['data']
  100. episodes_data = page_info['episodes']['data']
  101. num_episodes = page_info['meta']['totalEpisodes']
  102. processed_episodes = 0
  103. entries = []
  104. page_num = 1
  105. while True:
  106. entries.extend([self.url_result(
  107. 'http://%s/%s/%s' % (domain, display_id, episode['slug'])) for episode in episodes_data])
  108. processed_episodes += len(episodes_data)
  109. if processed_episodes == num_episodes:
  110. break
  111. page_num += 1
  112. episodes_data = self._download_json(self._PAGE_DATA_TEMPLATE % (
  113. domain, display_id + '/' + compat_str(page_num), domain),
  114. display_id)['episodes']['data']
  115. return self.playlist_result(
  116. entries, compat_str(show_data['id']),
  117. show_data.get('name'), show_data.get('summary'))