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.

215 lines
8.8 KiB

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