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.

144 lines
6.2 KiB

10 years ago
  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(
  73. r'<link rel="video_src" href="http://i\.adultswim\.com/adultswim/adultswimtv/tools/swf/viralplayer.swf\?id=([0-9a-f]+?)"\s*/?\s*>',
  74. webpage, 'episode_id')
  75. title = self._og_search_title(webpage)
  76. index_url = 'http://asfix.adultswim.com/asfix-svc/episodeSearch/getEpisodesByIDs?networkName=AS&ids=%s' % episode_id
  77. idoc = self._download_xml(index_url, title, 'Downloading episode index', 'Unable to download episode index')
  78. episode_el = idoc.find('.//episode')
  79. show_title = episode_el.attrib.get('collectionTitle')
  80. episode_title = episode_el.attrib.get('title')
  81. thumbnail = episode_el.attrib.get('thumbnailUrl')
  82. description = episode_el.find('./description').text.strip()
  83. entries = []
  84. segment_els = episode_el.findall('./segments/segment')
  85. for part_num, segment_el in enumerate(segment_els):
  86. segment_id = segment_el.attrib.get('id')
  87. segment_title = '%s %s part %d' % (show_title, episode_title, part_num + 1)
  88. thumbnail = segment_el.attrib.get('thumbnailUrl')
  89. duration = segment_el.attrib.get('duration')
  90. segment_url = 'http://asfix.adultswim.com/asfix-svc/episodeservices/getCvpPlaylist?networkName=AS&id=%s' % segment_id
  91. idoc = self._download_xml(
  92. segment_url, segment_title,
  93. 'Downloading segment information', 'Unable to download segment information')
  94. formats = []
  95. file_els = idoc.findall('.//files/file')
  96. for file_el in file_els:
  97. bitrate = file_el.attrib.get('bitrate')
  98. type = file_el.attrib.get('type')
  99. width, height = self._video_dimensions.get(bitrate, (None, None))
  100. formats.append({
  101. 'format_id': '%s-%s' % (bitrate, type),
  102. 'url': file_el.text,
  103. 'ext': self._video_extensions.get(bitrate, 'mp4'),
  104. # The bitrate may not be a number (for example: 'iphone')
  105. 'tbr': int(bitrate) if bitrate.isdigit() else None,
  106. 'height': height,
  107. 'width': width
  108. })
  109. self._sort_formats(formats)
  110. entries.append({
  111. 'id': segment_id,
  112. 'title': segment_title,
  113. 'formats': formats,
  114. 'uploader': show_title,
  115. 'thumbnail': thumbnail,
  116. 'duration': duration,
  117. 'description': description
  118. })
  119. return {
  120. '_type': 'playlist',
  121. 'id': episode_id,
  122. 'display_id': video_path,
  123. 'entries': entries,
  124. 'title': '%s %s' % (show_title, episode_title),
  125. 'description': description,
  126. 'thumbnail': thumbnail
  127. }