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.

176 lines
7.2 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': '71089',
  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. # Show
  31. 'url': 'http://testtube.com/brainstuff',
  32. 'info_dict': {
  33. 'id': '251',
  34. 'title': 'BrainStuff',
  35. '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.',
  36. },
  37. 'playlist_mincount': 93,
  38. }, {
  39. 'url': 'https://testtube.com/dnews/5-weird-ways-plants-can-eat-animals?utm_source=FB&utm_medium=DNews&utm_campaign=DNewsSocial',
  40. 'info_dict': {
  41. 'id': '58227',
  42. 'display_id': 'dnews/5-weird-ways-plants-can-eat-animals',
  43. 'duration': 275,
  44. 'ext': 'webm',
  45. 'title': '5 Weird Ways Plants Can Eat Animals',
  46. 'description': 'Why have some plants evolved to eat meat?',
  47. 'upload_date': '20150120',
  48. 'timestamp': 1421763300,
  49. 'uploader': 'DNews',
  50. 'uploader_id': 'dnews',
  51. },
  52. }, {
  53. 'url': 'http://testtube.com/tt-editors-picks/the-israel-palestine-conflict-explained-in-ten-min',
  54. 'info_dict': {
  55. 'id': '71618',
  56. 'ext': 'mp4',
  57. 'display_id': 'tt-editors-picks/the-israel-palestine-conflict-explained-in-ten-min',
  58. 'title': 'The Israel-Palestine Conflict Explained in Ten Minutes',
  59. 'description': 'If you\'d like to learn about the struggle between Israelis and Palestinians, this video is a great place to start',
  60. 'uploader': 'Editors\' Picks',
  61. 'uploader_id': 'tt-editors-picks',
  62. 'timestamp': 1453309200,
  63. 'upload_date': '20160120',
  64. },
  65. 'add_ie': ['Youtube'],
  66. }, {
  67. # Tag
  68. 'url': 'http://testtube.com/tech-news',
  69. 'info_dict': {
  70. 'id': '21018',
  71. 'title': 'tech news',
  72. },
  73. 'playlist_mincount': 9,
  74. }]
  75. _PAGE_DATA_TEMPLATE = 'http://www.%s/apiProxy/ddn/%s?domain=%s'
  76. _API_KEY = 'ba9c741bce1b9d8e3defcc22193f3651b8867e62'
  77. def _real_extract(self, url):
  78. domain, display_id = re.match(self._VALID_URL, url).groups()
  79. site = domain.split('.')[0]
  80. page_info = self._download_json(
  81. self._PAGE_DATA_TEMPLATE % (domain, display_id, domain), display_id)
  82. page_data = page_info['data']
  83. page_type = page_data['type']
  84. if page_type in ('episode', 'embed'):
  85. show_data = page_data['show']['data']
  86. page_id = compat_str(page_data['id'])
  87. video_id = compat_str(page_data['video']['data']['id'])
  88. preference = qualities(['mini', 'small', 'medium', 'large'])
  89. thumbnails = [{
  90. 'url': image_url,
  91. 'id': image_id,
  92. 'preference': preference(image_id)
  93. } for image_id, image_url in page_data.get('images', {}).items()]
  94. info = {
  95. 'id': page_id,
  96. 'display_id': display_id,
  97. 'title': unescapeHTML(page_data['name']),
  98. 'description': unescapeHTML(page_data.get('summary')),
  99. 'timestamp': parse_iso8601(page_data.get('publishTime'), ' '),
  100. 'author': page_data.get('author'),
  101. 'uploader': show_data.get('name'),
  102. 'uploader_id': show_data.get('slug'),
  103. 'thumbnails': thumbnails,
  104. 'extractor_key': site,
  105. }
  106. if page_type == 'embed':
  107. info.update({
  108. '_type': 'url_transparent',
  109. 'url': page_data['video']['data']['embed'],
  110. })
  111. return info
  112. video_data = self._download_json(
  113. 'http://revision3.com/api/getPlaylist.json?api_key=%s&codecs=h264,vp8,theora&video_id=%s' % (self._API_KEY, video_id),
  114. video_id)['items'][0]
  115. formats = []
  116. for vcodec, media in video_data['media'].items():
  117. for quality_id, quality in media.items():
  118. if quality_id == 'hls':
  119. formats.extend(self._extract_m3u8_formats(
  120. quality['url'], video_id, 'mp4',
  121. 'm3u8_native', m3u8_id='hls', fatal=False))
  122. else:
  123. formats.append({
  124. 'url': quality['url'],
  125. 'format_id': '%s-%s' % (vcodec, quality_id),
  126. 'tbr': int_or_none(quality.get('bitrate')),
  127. 'vcodec': vcodec,
  128. })
  129. self._sort_formats(formats)
  130. info.update({
  131. 'title': unescapeHTML(video_data['title']),
  132. 'description': unescapeHTML(video_data.get('summary')),
  133. 'uploader': video_data.get('show', {}).get('name'),
  134. 'uploader_id': video_data.get('show', {}).get('slug'),
  135. 'duration': int_or_none(video_data.get('duration')),
  136. 'formats': formats,
  137. })
  138. return info
  139. else:
  140. list_data = page_info[page_type]['data']
  141. episodes_data = page_info['episodes']['data']
  142. num_episodes = page_info['meta']['totalEpisodes']
  143. processed_episodes = 0
  144. entries = []
  145. page_num = 1
  146. while True:
  147. entries.extend([{
  148. '_type': 'url',
  149. 'url': 'http://%s%s' % (domain, episode['path']),
  150. 'id': compat_str(episode['id']),
  151. 'ie_key': 'Revision3',
  152. 'extractor_key': site,
  153. } for episode in episodes_data])
  154. processed_episodes += len(episodes_data)
  155. if processed_episodes == num_episodes:
  156. break
  157. page_num += 1
  158. episodes_data = self._download_json(self._PAGE_DATA_TEMPLATE % (
  159. domain, display_id + '/' + compat_str(page_num), domain),
  160. display_id)['episodes']['data']
  161. return self.playlist_result(
  162. entries, compat_str(list_data['id']),
  163. list_data.get('name'), list_data.get('summary'))