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.

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