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.

232 lines
9.9 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. 'url': 'http://www.adultswim.com/videos/toonami/friday-october-14th-2016/',
  96. 'info_dict': {
  97. 'id': 'eYiLsKVgQ6qTC6agD67Sig',
  98. 'title': 'Toonami - Friday, October 14th, 2016',
  99. 'description': 'md5:99892c96ffc85e159a428de85c30acde',
  100. },
  101. 'playlist': [{
  102. 'md5': '',
  103. 'info_dict': {
  104. 'id': 'eYiLsKVgQ6qTC6agD67Sig',
  105. 'ext': 'mp4',
  106. 'title': 'Toonami - Friday, October 14th, 2016',
  107. 'description': 'md5:99892c96ffc85e159a428de85c30acde',
  108. },
  109. }],
  110. 'params': {
  111. # m3u8 download
  112. 'skip_download': True,
  113. },
  114. 'expected_warnings': ['Unable to download f4m manifest'],
  115. }]
  116. @staticmethod
  117. def find_video_info(collection, slug):
  118. for video in collection.get('videos'):
  119. if video.get('slug') == slug:
  120. return video
  121. @staticmethod
  122. def find_collection_by_linkURL(collections, linkURL):
  123. for collection in collections:
  124. if collection.get('linkURL') == linkURL:
  125. return collection
  126. @staticmethod
  127. def find_collection_containing_video(collections, slug):
  128. for collection in collections:
  129. for video in collection.get('videos'):
  130. if video.get('slug') == slug:
  131. return collection, video
  132. return None, None
  133. def _real_extract(self, url):
  134. mobj = re.match(self._VALID_URL, url)
  135. show_path = mobj.group('show_path')
  136. episode_path = mobj.group('episode_path')
  137. is_playlist = True if mobj.group('is_playlist') else False
  138. webpage = self._download_webpage(url, episode_path)
  139. # Extract the value of `bootstrappedData` from the Javascript in the page.
  140. bootstrapped_data = self._parse_json(self._search_regex(
  141. r'var bootstrappedData = ({.*});', webpage, 'bootstraped data'), episode_path)
  142. # Downloading videos from a /videos/playlist/ URL needs to be handled differently.
  143. # NOTE: We are only downloading one video (the current one) not the playlist
  144. if is_playlist:
  145. collections = bootstrapped_data['playlists']['collections']
  146. collection = self.find_collection_by_linkURL(collections, show_path)
  147. video_info = self.find_video_info(collection, episode_path)
  148. show_title = video_info['showTitle']
  149. segment_ids = [video_info['videoPlaybackID']]
  150. else:
  151. collections = bootstrapped_data['show']['collections']
  152. collection, video_info = self.find_collection_containing_video(collections, episode_path)
  153. # Video wasn't found in the collections, let's try `slugged_video`.
  154. if video_info is None:
  155. if bootstrapped_data.get('slugged_video', {}).get('slug') == episode_path:
  156. video_info = bootstrapped_data['slugged_video']
  157. if not video_info:
  158. video_info = bootstrapped_data.get(
  159. 'heroMetadata', {}).get('trailer', {}).get('video')
  160. if not video_info:
  161. video_info = bootstrapped_data.get('onlineOriginals', [None])[0]
  162. if not video_info:
  163. raise ExtractorError('Unable to find video info')
  164. show = bootstrapped_data['show']
  165. show_title = show['title']
  166. stream = video_info.get('stream')
  167. if stream and stream.get('videoPlaybackID'):
  168. segment_ids = [stream['videoPlaybackID']]
  169. elif video_info.get('clips'):
  170. segment_ids = [clip['videoPlaybackID'] for clip in video_info['clips']]
  171. elif video_info.get('videoPlaybackID'):
  172. segment_ids = [video_info['videoPlaybackID']]
  173. elif video_info.get('id'):
  174. segment_ids = [video_info['id']]
  175. else:
  176. if video_info.get('auth') is True:
  177. raise ExtractorError(
  178. 'This video is only available via cable service provider subscription that'
  179. ' is not currently supported. You may want to use --cookies.', expected=True)
  180. else:
  181. raise ExtractorError('Unable to find stream or clips')
  182. episode_id = video_info['id']
  183. episode_title = video_info['title']
  184. episode_description = video_info.get('description')
  185. episode_duration = int_or_none(video_info.get('duration'))
  186. view_count = int_or_none(video_info.get('views'))
  187. entries = []
  188. for part_num, segment_id in enumerate(segment_ids):
  189. segement_info = self._extract_cvp_info(
  190. 'http://www.adultswim.com/videos/api/v0/assets?id=%s&platform=desktop' % segment_id,
  191. segment_id, {
  192. 'secure': {
  193. 'media_src': 'http://androidhls-secure.cdn.turner.com/adultswim/big',
  194. 'tokenizer_src': 'http://www.adultswim.com/astv/mvpd/processors/services/token_ipadAdobe.do',
  195. },
  196. })
  197. segment_title = '%s - %s' % (show_title, episode_title)
  198. if len(segment_ids) > 1:
  199. segment_title += ' Part %d' % (part_num + 1)
  200. segement_info.update({
  201. 'id': segment_id,
  202. 'title': segment_title,
  203. 'description': episode_description,
  204. })
  205. entries.append(segement_info)
  206. return {
  207. '_type': 'playlist',
  208. 'id': episode_id,
  209. 'display_id': episode_path,
  210. 'entries': entries,
  211. 'title': '%s - %s' % (show_title, episode_title),
  212. 'description': episode_description,
  213. 'duration': episode_duration,
  214. 'view_count': view_count,
  215. }