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.

206 lines
8.5 KiB

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