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.

200 lines
8.2 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from .mtv import MTVServicesInfoExtractor
  5. from ..utils import (
  6. compat_str,
  7. compat_urllib_parse,
  8. ExtractorError,
  9. unified_strdate,
  10. )
  11. class ComedyCentralIE(MTVServicesInfoExtractor):
  12. _VALID_URL = r'''(?x)https?://(?:www\.)?(comedycentral|cc)\.com/
  13. (video-clips|episodes|cc-studios|video-collections)
  14. /(?P<title>.*)'''
  15. _FEED_URL = 'http://comedycentral.com/feeds/mrss/'
  16. _TEST = {
  17. 'url': 'http://www.comedycentral.com/video-clips/kllhuv/stand-up-greg-fitzsimmons--uncensored---too-good-of-a-mother',
  18. 'md5': '4167875aae411f903b751a21f357f1ee',
  19. 'info_dict': {
  20. 'id': 'cef0cbb3-e776-4bc9-b62e-8016deccb354',
  21. 'ext': 'mp4',
  22. 'title': 'CC:Stand-Up|Greg Fitzsimmons: Life on Stage|Uncensored - Too Good of a Mother',
  23. 'description': 'After a certain point, breastfeeding becomes c**kblocking.',
  24. },
  25. }
  26. class ComedyCentralShowsIE(InfoExtractor):
  27. IE_DESC = 'The Daily Show / Colbert Report'
  28. # urls can be abbreviations like :thedailyshow or :colbert
  29. # urls for episodes like:
  30. # or urls for clips like: http://www.thedailyshow.com/watch/mon-december-10-2012/any-given-gun-day
  31. # or: http://www.colbertnation.com/the-colbert-report-videos/421667/november-29-2012/moon-shattering-news
  32. # or: http://www.colbertnation.com/the-colbert-report-collections/422008/festival-of-lights/79524
  33. _VALID_URL = r"""^(:(?P<shortname>tds|thedailyshow|cr|colbert|colbertnation|colbertreport)
  34. |(https?://)?(www\.)?
  35. (?P<showname>thedailyshow|colbertnation)\.com/
  36. (full-episodes/(?P<episode>.*)|
  37. (?P<clip>
  38. (the-colbert-report-(videos|collections)/(?P<clipID>[0-9]+)/[^/]*/(?P<cntitle>.*?))
  39. |(watch/(?P<date>[^/]*)/(?P<tdstitle>.*)))|
  40. (?P<interview>
  41. extended-interviews/(?P<interID>[0-9]+)/playlist_tds_extended_(?P<interview_title>.*?)/.*?)))
  42. $"""
  43. _TEST = {
  44. 'url': 'http://www.thedailyshow.com/watch/thu-december-13-2012/kristen-stewart',
  45. 'file': '422212.mp4',
  46. 'md5': '4e2f5cb088a83cd8cdb7756132f9739d',
  47. 'info_dict': {
  48. "upload_date": "20121214",
  49. "description": "Kristen Stewart",
  50. "uploader": "thedailyshow",
  51. "title": "thedailyshow-kristen-stewart part 1"
  52. }
  53. }
  54. _available_formats = ['3500', '2200', '1700', '1200', '750', '400']
  55. _video_extensions = {
  56. '3500': 'mp4',
  57. '2200': 'mp4',
  58. '1700': 'mp4',
  59. '1200': 'mp4',
  60. '750': 'mp4',
  61. '400': 'mp4',
  62. }
  63. _video_dimensions = {
  64. '3500': (1280, 720),
  65. '2200': (960, 540),
  66. '1700': (768, 432),
  67. '1200': (640, 360),
  68. '750': (512, 288),
  69. '400': (384, 216),
  70. }
  71. @classmethod
  72. def suitable(cls, url):
  73. """Receives a URL and returns True if suitable for this IE."""
  74. return re.match(cls._VALID_URL, url, re.VERBOSE) is not None
  75. @staticmethod
  76. def _transform_rtmp_url(rtmp_video_url):
  77. m = re.match(r'^rtmpe?://.*?/(?P<finalid>gsp\.comedystor/.*)$', rtmp_video_url)
  78. if not m:
  79. raise ExtractorError('Cannot transform RTMP url')
  80. base = 'http://mtvnmobile.vo.llnwd.net/kip0/_pxn=1+_pxI0=Ripod-h264+_pxL0=undefined+_pxM0=+_pxK=18639+_pxE=mp4/44620/mtvnorigin/'
  81. return base + m.group('finalid')
  82. def _real_extract(self, url):
  83. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  84. if mobj is None:
  85. raise ExtractorError('Invalid URL: %s' % url)
  86. if mobj.group('shortname'):
  87. if mobj.group('shortname') in ('tds', 'thedailyshow'):
  88. url = 'http://www.thedailyshow.com/full-episodes/'
  89. else:
  90. url = 'http://www.colbertnation.com/full-episodes/'
  91. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  92. assert mobj is not None
  93. if mobj.group('clip'):
  94. if mobj.group('showname') == 'thedailyshow':
  95. epTitle = mobj.group('tdstitle')
  96. else:
  97. epTitle = mobj.group('cntitle')
  98. dlNewest = False
  99. elif mobj.group('interview'):
  100. epTitle = mobj.group('interview_title')
  101. dlNewest = False
  102. else:
  103. dlNewest = not mobj.group('episode')
  104. if dlNewest:
  105. epTitle = mobj.group('showname')
  106. else:
  107. epTitle = mobj.group('episode')
  108. self.report_extraction(epTitle)
  109. webpage,htmlHandle = self._download_webpage_handle(url, epTitle)
  110. if dlNewest:
  111. url = htmlHandle.geturl()
  112. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  113. if mobj is None:
  114. raise ExtractorError('Invalid redirected URL: ' + url)
  115. if mobj.group('episode') == '':
  116. raise ExtractorError('Redirected URL is still not specific: ' + url)
  117. epTitle = mobj.group('episode')
  118. mMovieParams = re.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage)
  119. if len(mMovieParams) == 0:
  120. # The Colbert Report embeds the information in a without
  121. # a URL prefix; so extract the alternate reference
  122. # and then add the URL prefix manually.
  123. altMovieParams = re.findall('data-mgid="([^"]*(?:episode|video).*?:.*?)"', webpage)
  124. if len(altMovieParams) == 0:
  125. raise ExtractorError('unable to find Flash URL in webpage ' + url)
  126. else:
  127. mMovieParams = [("http://media.mtvnservices.com/" + altMovieParams[0], altMovieParams[0])]
  128. uri = mMovieParams[0][1]
  129. indexUrl = 'http://shadow.comedycentral.com/feeds/video_player/mrss/?' + compat_urllib_parse.urlencode({'uri': uri})
  130. idoc = self._download_xml(indexUrl, epTitle,
  131. 'Downloading show index',
  132. 'unable to download episode index')
  133. results = []
  134. itemEls = idoc.findall('.//item')
  135. for partNum,itemEl in enumerate(itemEls):
  136. mediaId = itemEl.findall('./guid')[0].text
  137. shortMediaId = mediaId.split(':')[-1]
  138. showId = mediaId.split(':')[-2].replace('.com', '')
  139. officialTitle = itemEl.findall('./title')[0].text
  140. officialDate = unified_strdate(itemEl.findall('./pubDate')[0].text)
  141. configUrl = ('http://www.comedycentral.com/global/feeds/entertainment/media/mediaGenEntertainment.jhtml?' +
  142. compat_urllib_parse.urlencode({'uri': mediaId}))
  143. cdoc = self._download_xml(configUrl, epTitle,
  144. 'Downloading configuration for %s' % shortMediaId)
  145. turls = []
  146. for rendition in cdoc.findall('.//rendition'):
  147. finfo = (rendition.attrib['bitrate'], rendition.findall('./src')[0].text)
  148. turls.append(finfo)
  149. if len(turls) == 0:
  150. self._downloader.report_error('unable to download ' + mediaId + ': No videos found')
  151. continue
  152. formats = []
  153. for format, rtmp_video_url in turls:
  154. w, h = self._video_dimensions.get(format, (None, None))
  155. formats.append({
  156. 'url': self._transform_rtmp_url(rtmp_video_url),
  157. 'ext': self._video_extensions.get(format, 'mp4'),
  158. 'format_id': format,
  159. 'height': h,
  160. 'width': w,
  161. })
  162. effTitle = showId + '-' + epTitle + ' part ' + compat_str(partNum+1)
  163. results.append({
  164. 'id': shortMediaId,
  165. 'formats': formats,
  166. 'uploader': showId,
  167. 'upload_date': officialDate,
  168. 'title': effTitle,
  169. 'thumbnail': None,
  170. 'description': compat_str(officialTitle),
  171. })
  172. return results