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.

209 lines
9.1 KiB

10 years ago
10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .turner import TurnerBaseIE
  5. from ..utils import (
  6. ExtractorError,
  7. int_or_none,
  8. )
  9. class AdultSwimIE(TurnerBaseIE):
  10. _VALID_URL = r'https?://(?:www\.)?adultswim\.com/videos/(?P<is_playlist>playlists/)?(?P<show_path>[^/]+)/(?P<episode_path>[^/?#]+)/?'
  11. _TESTS = [{
  12. 'url': 'http://adultswim.com/videos/rick-and-morty/pilot',
  13. 'playlist': [
  14. {
  15. 'md5': '247572debc75c7652f253c8daa51a14d',
  16. 'info_dict': {
  17. 'id': 'rQxZvXQ4ROaSOqq-or2Mow-0',
  18. 'ext': 'flv',
  19. 'title': 'Rick and Morty - Pilot Part 1',
  20. 'description': "Rick moves in with his daughter's family and establishes himself as a bad influence on his grandson, Morty. "
  21. },
  22. },
  23. {
  24. 'md5': '77b0e037a4b20ec6b98671c4c379f48d',
  25. 'info_dict': {
  26. 'id': 'rQxZvXQ4ROaSOqq-or2Mow-3',
  27. 'ext': 'flv',
  28. 'title': 'Rick and Morty - Pilot Part 4',
  29. 'description': "Rick moves in with his daughter's family and establishes himself as a bad influence on his grandson, Morty. "
  30. },
  31. },
  32. ],
  33. 'info_dict': {
  34. 'id': 'rQxZvXQ4ROaSOqq-or2Mow',
  35. 'title': 'Rick and Morty - Pilot',
  36. 'description': "Rick moves in with his daughter's family and establishes himself as a bad influence on his grandson, Morty. "
  37. },
  38. 'skip': 'This video is only available for registered users',
  39. }, {
  40. 'url': 'http://www.adultswim.com/videos/playlists/american-parenting/putting-francine-out-of-business/',
  41. 'playlist': [
  42. {
  43. 'md5': '2eb5c06d0f9a1539da3718d897f13ec5',
  44. 'info_dict': {
  45. 'id': '-t8CamQlQ2aYZ49ItZCFog-0',
  46. 'ext': 'flv',
  47. 'title': 'American Dad - Putting Francine Out of Business',
  48. 'description': 'Stan hatches a plan to get Francine out of the real estate business.Watch more American Dad on [adult swim].'
  49. },
  50. }
  51. ],
  52. 'info_dict': {
  53. 'id': '-t8CamQlQ2aYZ49ItZCFog',
  54. 'title': 'American Dad - Putting Francine Out of Business',
  55. 'description': 'Stan hatches a plan to get Francine out of the real estate business.Watch more American Dad on [adult swim].'
  56. },
  57. }, {
  58. 'url': 'http://www.adultswim.com/videos/tim-and-eric-awesome-show-great-job/dr-steve-brule-for-your-wine/',
  59. 'playlist': [
  60. {
  61. 'md5': '3e346a2ab0087d687a05e1e7f3b3e529',
  62. 'info_dict': {
  63. 'id': 'sY3cMUR_TbuE4YmdjzbIcQ-0',
  64. 'ext': 'mp4',
  65. 'title': 'Tim and Eric Awesome Show Great Job! - Dr. Steve Brule, For Your Wine',
  66. 'description': 'Dr. Brule reports live from Wine Country with a special report on wines. \r\nWatch Tim and Eric Awesome Show Great Job! episode #20, "Embarrassed" on Adult Swim.\r\n\r\n',
  67. },
  68. }
  69. ],
  70. 'info_dict': {
  71. 'id': 'sY3cMUR_TbuE4YmdjzbIcQ',
  72. 'title': 'Tim and Eric Awesome Show Great Job! - Dr. Steve Brule, For Your Wine',
  73. 'description': 'Dr. Brule reports live from Wine Country with a special report on wines. \r\nWatch Tim and Eric Awesome Show Great Job! episode #20, "Embarrassed" on Adult Swim.\r\n\r\n',
  74. },
  75. 'params': {
  76. # m3u8 download
  77. 'skip_download': True,
  78. }
  79. }, {
  80. # heroMetadata.trailer
  81. 'url': 'http://www.adultswim.com/videos/decker/inside-decker-a-new-hero/',
  82. 'info_dict': {
  83. 'id': 'I0LQFQkaSUaFp8PnAWHhoQ',
  84. 'ext': 'mp4',
  85. 'title': 'Decker - Inside Decker: A New Hero',
  86. 'description': 'md5:c916df071d425d62d70c86d4399d3ee0',
  87. 'duration': 249.008,
  88. },
  89. 'params': {
  90. # m3u8 download
  91. 'skip_download': True,
  92. },
  93. 'expected_warnings': ['Unable to download f4m manifest'],
  94. }]
  95. @staticmethod
  96. def find_video_info(collection, slug):
  97. for video in collection.get('videos'):
  98. if video.get('slug') == slug:
  99. return video
  100. @staticmethod
  101. def find_collection_by_linkURL(collections, linkURL):
  102. for collection in collections:
  103. if collection.get('linkURL') == linkURL:
  104. return collection
  105. @staticmethod
  106. def find_collection_containing_video(collections, slug):
  107. for collection in collections:
  108. for video in collection.get('videos'):
  109. if video.get('slug') == slug:
  110. return collection, video
  111. return None, None
  112. def _real_extract(self, url):
  113. mobj = re.match(self._VALID_URL, url)
  114. show_path = mobj.group('show_path')
  115. episode_path = mobj.group('episode_path')
  116. is_playlist = True if mobj.group('is_playlist') else False
  117. webpage = self._download_webpage(url, episode_path)
  118. # Extract the value of `bootstrappedData` from the Javascript in the page.
  119. bootstrapped_data = self._parse_json(self._search_regex(
  120. r'var bootstrappedData = ({.*});', webpage, 'bootstraped data'), episode_path)
  121. # Downloading videos from a /videos/playlist/ URL needs to be handled differently.
  122. # NOTE: We are only downloading one video (the current one) not the playlist
  123. if is_playlist:
  124. collections = bootstrapped_data['playlists']['collections']
  125. collection = self.find_collection_by_linkURL(collections, show_path)
  126. video_info = self.find_video_info(collection, episode_path)
  127. show_title = video_info['showTitle']
  128. segment_ids = [video_info['videoPlaybackID']]
  129. else:
  130. collections = bootstrapped_data['show']['collections']
  131. collection, video_info = self.find_collection_containing_video(collections, episode_path)
  132. # Video wasn't found in the collections, let's try `slugged_video`.
  133. if video_info is None:
  134. if bootstrapped_data.get('slugged_video', {}).get('slug') == episode_path:
  135. video_info = bootstrapped_data['slugged_video']
  136. if not video_info:
  137. video_info = bootstrapped_data.get(
  138. 'heroMetadata', {}).get('trailer', {}).get('video')
  139. if not video_info:
  140. video_info = bootstrapped_data.get('onlineOriginals', [None])[0]
  141. if not video_info:
  142. raise ExtractorError('Unable to find video info')
  143. show = bootstrapped_data['show']
  144. show_title = show['title']
  145. stream = video_info.get('stream')
  146. if stream and stream.get('videoPlaybackID'):
  147. segment_ids = [stream['videoPlaybackID']]
  148. elif video_info.get('clips'):
  149. segment_ids = [clip['videoPlaybackID'] for clip in video_info['clips']]
  150. elif video_info.get('videoPlaybackID'):
  151. segment_ids = [video_info['videoPlaybackID']]
  152. else:
  153. if video_info.get('auth') is True:
  154. raise ExtractorError(
  155. 'This video is only available via cable service provider subscription that'
  156. ' is not currently supported. You may want to use --cookies.', expected=True)
  157. else:
  158. raise ExtractorError('Unable to find stream or clips')
  159. episode_id = video_info['id']
  160. episode_title = video_info['title']
  161. episode_description = video_info.get('description')
  162. episode_duration = int_or_none(video_info.get('duration'))
  163. view_count = int_or_none(video_info.get('views'))
  164. entries = []
  165. for part_num, segment_id in enumerate(segment_ids):
  166. segement_info = self._extract_cvp_info(
  167. 'http://www.adultswim.com/videos/api/v0/assets?id=%s&platform=desktop' % segment_id,
  168. segment_id, {
  169. 'secure': {
  170. 'media_src': 'http://androidhls-secure.cdn.turner.com/adultswim/big',
  171. 'tokenizer_src': 'http://www.adultswim.com/astv/mvpd/processors/services/token_ipadAdobe.do',
  172. },
  173. })
  174. segment_title = '%s - %s' % (show_title, episode_title)
  175. if len(segment_ids) > 1:
  176. segment_title += ' Part %d' % (part_num + 1)
  177. segement_info.update({
  178. 'id': segment_id,
  179. 'title': segment_title,
  180. 'description': episode_description,
  181. })
  182. entries.append(segement_info)
  183. return {
  184. '_type': 'playlist',
  185. 'id': episode_id,
  186. 'display_id': episode_path,
  187. 'entries': entries,
  188. 'title': '%s - %s' % (show_title, episode_title),
  189. 'description': episode_description,
  190. 'duration': episode_duration,
  191. 'view_count': view_count,
  192. }