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.

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