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.

139 lines
6.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class AdultSwimIE(InfoExtractor):
  6. _VALID_URL = r'https?://video\.adultswim\.com/(?P<path>.+?)(?:\.html)?(?:\?.*)?(?:#.*)?$'
  7. _TEST = {
  8. 'url': 'http://video.adultswim.com/rick-and-morty/close-rick-counters-of-the-rick-kind.html?x=y#title',
  9. 'playlist': [
  10. {
  11. 'md5': '4da359ec73b58df4575cd01a610ba5dc',
  12. 'info_dict': {
  13. 'id': '8a250ba1450996e901453d7f02ca02f5',
  14. 'ext': 'flv',
  15. 'title': 'Rick and Morty Close Rick-Counters of the Rick Kind part 1',
  16. 'description': 'Rick has a run in with some old associates, resulting in a fallout with Morty. You got any chips, broh?',
  17. 'uploader': 'Rick and Morty',
  18. 'thumbnail': 'http://i.cdn.turner.com/asfix/repository/8a250ba13f865824013fc9db8b6b0400/thumbnail_267549017116827057.jpg'
  19. }
  20. },
  21. {
  22. 'md5': 'ffbdf55af9331c509d95350bd0cc1819',
  23. 'info_dict': {
  24. 'id': '8a250ba1450996e901453d7f4bd102f6',
  25. 'ext': 'flv',
  26. 'title': 'Rick and Morty Close Rick-Counters of the Rick Kind part 2',
  27. 'description': 'Rick has a run in with some old associates, resulting in a fallout with Morty. You got any chips, broh?',
  28. 'uploader': 'Rick and Morty',
  29. 'thumbnail': 'http://i.cdn.turner.com/asfix/repository/8a250ba13f865824013fc9db8b6b0400/thumbnail_267549017116827057.jpg'
  30. }
  31. },
  32. {
  33. 'md5': 'b92409635540304280b4b6c36bd14a0a',
  34. 'info_dict': {
  35. 'id': '8a250ba1450996e901453d7fa73c02f7',
  36. 'ext': 'flv',
  37. 'title': 'Rick and Morty Close Rick-Counters of the Rick Kind part 3',
  38. 'description': 'Rick has a run in with some old associates, resulting in a fallout with Morty. You got any chips, broh?',
  39. 'uploader': 'Rick and Morty',
  40. 'thumbnail': 'http://i.cdn.turner.com/asfix/repository/8a250ba13f865824013fc9db8b6b0400/thumbnail_267549017116827057.jpg'
  41. }
  42. },
  43. {
  44. 'md5': 'e8818891d60e47b29cd89d7b0278156d',
  45. 'info_dict': {
  46. 'id': '8a250ba1450996e901453d7fc8ba02f8',
  47. 'ext': 'flv',
  48. 'title': 'Rick and Morty Close Rick-Counters of the Rick Kind part 4',
  49. 'description': 'Rick has a run in with some old associates, resulting in a fallout with Morty. You got any chips, broh?',
  50. 'uploader': 'Rick and Morty',
  51. 'thumbnail': 'http://i.cdn.turner.com/asfix/repository/8a250ba13f865824013fc9db8b6b0400/thumbnail_267549017116827057.jpg'
  52. }
  53. }
  54. ]
  55. }
  56. _video_extensions = {
  57. '3500': 'flv',
  58. '640': 'mp4',
  59. '150': 'mp4',
  60. 'ipad': 'm3u8',
  61. 'iphone': 'm3u8'
  62. }
  63. _video_dimensions = {
  64. '3500': (1280, 720),
  65. '640': (480, 270),
  66. '150': (320, 180)
  67. }
  68. def _real_extract(self, url):
  69. mobj = re.match(self._VALID_URL, url)
  70. video_path = mobj.group('path')
  71. webpage = self._download_webpage(url, video_path)
  72. episode_id = self._html_search_regex(r'<link rel="video_src" href="http://i\.adultswim\.com/adultswim/adultswimtv/tools/swf/viralplayer.swf\?id=([0-9a-f]+?)"\s*/?\s*>', webpage, 'episode_id')
  73. title = self._og_search_title(webpage)
  74. index_url = 'http://asfix.adultswim.com/asfix-svc/episodeSearch/getEpisodesByIDs?networkName=AS&ids=%s' % episode_id
  75. idoc = self._download_xml(index_url, title, 'Downloading episode index', 'Unable to download episode index')
  76. episode_el = idoc.find('.//episode')
  77. show_title = episode_el.attrib.get('collectionTitle')
  78. episode_title = episode_el.attrib.get('title')
  79. thumbnail = episode_el.attrib.get('thumbnailUrl')
  80. description = episode_el.find('./description').text.strip()
  81. entries = []
  82. segment_els = episode_el.findall('./segments/segment')
  83. for part_num, segment_el in enumerate(segment_els):
  84. segment_id = segment_el.attrib.get('id')
  85. segment_title = '%s %s part %d' % (show_title, episode_title, part_num + 1)
  86. thumbnail = segment_el.attrib.get('thumbnailUrl')
  87. duration = segment_el.attrib.get('duration')
  88. segment_url = 'http://asfix.adultswim.com/asfix-svc/episodeservices/getCvpPlaylist?networkName=AS&id=%s' % segment_id
  89. idoc = self._download_xml(segment_url, segment_title, 'Downloading segment information', 'Unable to download segment information')
  90. formats = []
  91. file_els = idoc.findall('.//files/file')
  92. for file_el in file_els:
  93. bitrate = file_el.attrib.get('bitrate')
  94. type = file_el.attrib.get('type')
  95. width, height = self._video_dimensions.get(bitrate, (None, None))
  96. formats.append({
  97. 'format_id': '%s-%s' % (bitrate, type),
  98. 'url': file_el.text,
  99. 'ext': self._video_extensions.get(bitrate, 'mp4'),
  100. # The bitrate may not be a number (for example: 'iphone')
  101. 'tbr': int(bitrate) if bitrate.isdigit() else None,
  102. 'height': height,
  103. 'width': width
  104. })
  105. self._sort_formats(formats)
  106. entries.append({
  107. 'id': segment_id,
  108. 'title': segment_title,
  109. 'formats': formats,
  110. 'uploader': show_title,
  111. 'thumbnail': thumbnail,
  112. 'duration': duration,
  113. 'description': description
  114. })
  115. return {
  116. '_type': 'playlist',
  117. 'id': episode_id,
  118. 'display_id': video_path,
  119. 'entries': entries,
  120. 'title': '%s %s' % (show_title, episode_title),
  121. 'description': description,
  122. 'thumbnail': thumbnail
  123. }