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.4 KiB

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. int_or_none,
  7. strip_or_none,
  8. )
  9. class AdultSwimIE(TurnerBaseIE):
  10. _VALID_URL = r'https?://(?:www\.)?adultswim\.com/videos/(?P<show_path>[^/?#]+)(?:/(?P<episode_path>[^/?#]+))?'
  11. _TESTS = [{
  12. 'url': 'http://adultswim.com/videos/rick-and-morty/pilot',
  13. 'info_dict': {
  14. 'id': 'rQxZvXQ4ROaSOqq-or2Mow',
  15. 'ext': 'mp4',
  16. 'title': 'Rick and Morty - Pilot',
  17. 'description': 'Rick moves in with his daughter\'s family and establishes himself as a bad influence on his grandson, Morty.',
  18. 'timestamp': 1493267400,
  19. 'upload_date': '20170427',
  20. },
  21. 'params': {
  22. # m3u8 download
  23. 'skip_download': True,
  24. },
  25. 'expected_warnings': ['Unable to download f4m manifest'],
  26. }, {
  27. 'url': 'http://www.adultswim.com/videos/tim-and-eric-awesome-show-great-job/dr-steve-brule-for-your-wine/',
  28. 'info_dict': {
  29. 'id': 'sY3cMUR_TbuE4YmdjzbIcQ',
  30. 'ext': 'mp4',
  31. 'title': 'Tim and Eric Awesome Show Great Job! - Dr. Steve Brule, For Your Wine',
  32. 'description': 'Dr. Brule reports live from Wine Country with a special report on wines. \nWatch Tim and Eric Awesome Show Great Job! episode #20, "Embarrassed" on Adult Swim.',
  33. 'upload_date': '20080124',
  34. 'timestamp': 1201150800,
  35. },
  36. 'params': {
  37. # m3u8 download
  38. 'skip_download': True,
  39. },
  40. }, {
  41. 'url': 'http://www.adultswim.com/videos/decker/inside-decker-a-new-hero/',
  42. 'info_dict': {
  43. 'id': 'I0LQFQkaSUaFp8PnAWHhoQ',
  44. 'ext': 'mp4',
  45. 'title': 'Decker - Inside Decker: A New Hero',
  46. 'description': 'The guys recap the conclusion of the season. They announce a new hero, take a peek into the Victorville Film Archive and welcome back the talented James Dean.',
  47. 'timestamp': 1469480460,
  48. 'upload_date': '20160725',
  49. },
  50. 'params': {
  51. # m3u8 download
  52. 'skip_download': True,
  53. },
  54. 'expected_warnings': ['Unable to download f4m manifest'],
  55. }, {
  56. 'url': 'http://www.adultswim.com/videos/attack-on-titan',
  57. 'info_dict': {
  58. 'id': 'b7A69dzfRzuaXIECdxW8XQ',
  59. 'title': 'Attack on Titan',
  60. 'description': 'md5:6c8e003ea0777b47013e894767f5e114',
  61. },
  62. 'playlist_mincount': 12,
  63. }, {
  64. 'url': 'http://www.adultswim.com/videos/streams/williams-stream',
  65. 'info_dict': {
  66. 'id': 'd8DEBj7QRfetLsRgFnGEyg',
  67. 'ext': 'mp4',
  68. 'title': r're:^Williams Stream \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
  69. 'description': 'original programming',
  70. },
  71. 'params': {
  72. # m3u8 download
  73. 'skip_download': True,
  74. },
  75. }]
  76. def _real_extract(self, url):
  77. show_path, episode_path = re.match(self._VALID_URL, url).groups()
  78. display_id = episode_path or show_path
  79. webpage = self._download_webpage(url, display_id)
  80. initial_data = self._parse_json(self._search_regex(
  81. r'AS_INITIAL_DATA(?:__)?\s*=\s*({.+?});',
  82. webpage, 'initial data'), display_id)
  83. is_stream = show_path == 'streams'
  84. if is_stream:
  85. if not episode_path:
  86. episode_path = 'live-stream'
  87. video_data = next(stream for stream_path, stream in initial_data['streams'].items() if stream_path == episode_path)
  88. video_id = video_data.get('stream')
  89. if not video_id:
  90. entries = []
  91. for episode in video_data.get('archiveEpisodes', []):
  92. episode_url = episode.get('url')
  93. if not episode_url:
  94. continue
  95. entries.append(self.url_result(
  96. episode_url, 'AdultSwim', episode.get('id')))
  97. return self.playlist_result(
  98. entries, video_data.get('id'), video_data.get('title'),
  99. strip_or_none(video_data.get('description')))
  100. else:
  101. show_data = initial_data['show']
  102. if not episode_path:
  103. entries = []
  104. for video in show_data.get('videos', []):
  105. slug = video.get('slug')
  106. if not slug:
  107. continue
  108. entries.append(self.url_result(
  109. 'http://adultswim.com/videos/%s/%s' % (show_path, slug),
  110. 'AdultSwim', video.get('id')))
  111. return self.playlist_result(
  112. entries, show_data.get('id'), show_data.get('title'),
  113. strip_or_none(show_data.get('metadata', {}).get('description')))
  114. video_data = show_data['sluggedVideo']
  115. video_id = video_data['id']
  116. info = self._extract_cvp_info(
  117. 'http://www.adultswim.com/videos/api/v0/assets?platform=desktop&id=' + video_id,
  118. video_id, {
  119. 'secure': {
  120. 'media_src': 'http://androidhls-secure.cdn.turner.com/adultswim/big',
  121. 'tokenizer_src': 'http://www.adultswim.com/astv/mvpd/processors/services/token_ipadAdobe.do',
  122. },
  123. }, {
  124. 'url': url,
  125. 'site_name': 'AdultSwim',
  126. 'auth_required': video_data.get('auth'),
  127. })
  128. info.update({
  129. 'id': video_id,
  130. 'display_id': display_id,
  131. 'description': info.get('description') or strip_or_none(video_data.get('description')),
  132. })
  133. if not is_stream:
  134. info.update({
  135. 'duration': info.get('duration') or int_or_none(video_data.get('duration')),
  136. 'timestamp': info.get('timestamp') or int_or_none(video_data.get('launch_date')),
  137. 'season_number': info.get('season_number') or int_or_none(video_data.get('season_number')),
  138. 'episode': info['title'],
  139. 'episode_number': info.get('episode_number') or int_or_none(video_data.get('episode_number')),
  140. })
  141. info['series'] = video_data.get('collection_title') or info.get('series')
  142. if info['series'] and info['series'] != info['title']:
  143. info['title'] = '%s - %s' % (info['series'], info['title'])
  144. return info