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.

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