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.

159 lines
6.7 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. 'url': 'http://testtube.com/tt-editors-picks/the-israel-palestine-conflict-explained-in-ten-min',
  53. 'info_dict': {
  54. 'id': '73573',
  55. 'ext': 'mp4',
  56. 'display_id': 'tt-editors-picks/the-israel-palestine-conflict-explained-in-ten-min',
  57. 'title': 'The Israel-Palestine Conflict Explained in Ten Minutes',
  58. 'description': 'If you\'d like to learn about the struggle between Israelis and Palestinians, this video is a great place to start',
  59. 'uploader': 'Editors\' Picks',
  60. 'uploader_id': 'tt-editors-picks',
  61. 'timestamp': 1453309200,
  62. 'upload_date': '20160120',
  63. },
  64. 'add_ie': ['Youtube'],
  65. }]
  66. _PAGE_DATA_TEMPLATE = 'http://www.%s/apiProxy/ddn/%s?domain=%s'
  67. _API_KEY = 'ba9c741bce1b9d8e3defcc22193f3651b8867e62'
  68. def _real_extract(self, url):
  69. domain, display_id = re.match(self._VALID_URL, url).groups()
  70. page_info = self._download_json(
  71. self._PAGE_DATA_TEMPLATE % (domain, display_id, domain), display_id)
  72. page_data = page_info['data']
  73. page_type = page_data['type']
  74. if page_type == 'episode' or page_type == 'embed':
  75. show_data = page_data['show']['data']
  76. video_id = compat_str(page_data['video']['data']['id'])
  77. preference = qualities(['mini', 'small', 'medium', 'large'])
  78. thumbnails = [{
  79. 'url': image_url,
  80. 'id': image_id,
  81. 'preference': preference(image_id)
  82. } for image_id, image_url in page_data.get('images', {}).items()]
  83. info = {
  84. 'id': video_id,
  85. 'display_id': display_id,
  86. 'title': unescapeHTML(page_data['name']),
  87. 'description': unescapeHTML(page_data.get('summary')),
  88. 'timestamp': parse_iso8601(page_data.get('publishTime'), ' '),
  89. 'author': page_data.get('author'),
  90. 'uploader': show_data.get('name'),
  91. 'uploader_id': show_data.get('slug'),
  92. 'thumbnails': thumbnails,
  93. }
  94. if page_type == 'embed':
  95. info.update({
  96. '_type': 'url_transparent',
  97. 'url': page_data['video']['data']['embed'],
  98. })
  99. return info
  100. video_data = self._download_json(
  101. 'http://revision3.com/api/getPlaylist.json?api_key=%s&codecs=h264,vp8,theora&video_id=%s' % (self._API_KEY, video_id),
  102. video_id)['items'][0]
  103. formats = []
  104. for vcodec, media in video_data['media'].items():
  105. for quality_id, quality in media.items():
  106. if quality_id == 'hls':
  107. formats.extend(self._extract_m3u8_formats(
  108. quality['url'], video_id, 'mp4',
  109. 'm3u8_native', m3u8_id='hls', fatal=False))
  110. else:
  111. formats.append({
  112. 'url': quality['url'],
  113. 'format_id': '%s-%s' % (vcodec, quality_id),
  114. 'tbr': int_or_none(quality.get('bitrate')),
  115. 'vcodec': vcodec,
  116. })
  117. self._sort_formats(formats)
  118. info.update({
  119. 'title': unescapeHTML(video_data['title']),
  120. 'description': unescapeHTML(video_data.get('summary')),
  121. 'uploader': video_data.get('show', {}).get('name'),
  122. 'uploader_id': video_data.get('show', {}).get('slug'),
  123. 'duration': int_or_none(video_data.get('duration')),
  124. 'formats': formats,
  125. })
  126. return info
  127. else:
  128. show_data = page_info['show']['data']
  129. episodes_data = page_info['episodes']['data']
  130. num_episodes = page_info['meta']['totalEpisodes']
  131. processed_episodes = 0
  132. entries = []
  133. page_num = 1
  134. while True:
  135. entries.extend([self.url_result(
  136. 'http://%s/%s/%s' % (domain, display_id, episode['slug'])) for episode in episodes_data])
  137. processed_episodes += len(episodes_data)
  138. if processed_episodes == num_episodes:
  139. break
  140. page_num += 1
  141. episodes_data = self._download_json(self._PAGE_DATA_TEMPLATE % (
  142. domain, display_id + '/' + compat_str(page_num), domain),
  143. display_id)['episodes']['data']
  144. return self.playlist_result(
  145. entries, compat_str(show_data['id']),
  146. show_data.get('name'), show_data.get('summary'))