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.9 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. float_or_none,
  10. unified_strdate,
  11. )
  12. class ComedyCentralIE(MTVServicesInfoExtractor):
  13. _VALID_URL = r'''(?x)https?://(?:www\.)?(comedycentral|cc)\.com/
  14. (video-clips|episodes|cc-studios|video-collections)
  15. /(?P<title>.*)'''
  16. _FEED_URL = 'http://comedycentral.com/feeds/mrss/'
  17. _TEST = {
  18. 'url': 'http://www.comedycentral.com/video-clips/kllhuv/stand-up-greg-fitzsimmons--uncensored---too-good-of-a-mother',
  19. 'md5': 'c4f48e9eda1b16dd10add0744344b6d8',
  20. 'info_dict': {
  21. 'id': 'cef0cbb3-e776-4bc9-b62e-8016deccb354',
  22. 'ext': 'mp4',
  23. 'title': 'CC:Stand-Up|Greg Fitzsimmons: Life on Stage|Uncensored - Too Good of a Mother',
  24. 'description': 'After a certain point, breastfeeding becomes c**kblocking.',
  25. },
  26. }
  27. class ComedyCentralShowsIE(InfoExtractor):
  28. IE_DESC = 'The Daily Show / The Colbert Report'
  29. # urls can be abbreviations like :thedailyshow or :colbert
  30. # urls for episodes like:
  31. # or urls for clips like: http://www.thedailyshow.com/watch/mon-december-10-2012/any-given-gun-day
  32. # or: http://www.colbertnation.com/the-colbert-report-videos/421667/november-29-2012/moon-shattering-news
  33. # or: http://www.colbertnation.com/the-colbert-report-collections/422008/festival-of-lights/79524
  34. _VALID_URL = r'''(?x)^(:(?P<shortname>tds|thedailyshow|cr|colbert|colbertnation|colbertreport)
  35. |https?://(:www\.)?
  36. (?P<showname>thedailyshow|thecolbertreport)\.(?:cc\.)?com/
  37. ((?:full-)?episodes/(?:[0-9a-z]{6}/)?(?P<episode>.*)|
  38. (?P<clip>
  39. (?:(?:guests/[^/]+|videos|video-playlists|special-editions)/[^/]+/(?P<videotitle>[^/?#]+))
  40. |(the-colbert-report-(videos|collections)/(?P<clipID>[0-9]+)/[^/]*/(?P<cntitle>.*?))
  41. |(watch/(?P<date>[^/]*)/(?P<tdstitle>.*))
  42. )|
  43. (?P<interview>
  44. extended-interviews/(?P<interID>[0-9a-z]+)/(?:playlist_tds_extended_)?(?P<interview_title>.*?)(/.*?)?)))
  45. (?:[?#].*|$)'''
  46. _TEST = {
  47. 'url': 'http://thedailyshow.cc.com/watch/thu-december-13-2012/kristen-stewart',
  48. 'md5': '4e2f5cb088a83cd8cdb7756132f9739d',
  49. 'info_dict': {
  50. 'id': 'ab9ab3e7-5a98-4dbe-8b21-551dc0523d55',
  51. 'ext': 'mp4',
  52. 'upload_date': '20121213',
  53. 'description': 'Kristen Stewart learns to let loose in "On the Road."',
  54. 'uploader': 'thedailyshow',
  55. 'title': '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. @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://thedailyshow.cc.com/full-episodes/'
  89. else:
  90. url = 'http://thecolbertreport.cc.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('videotitle'):
  95. epTitle = mobj.group('videotitle')
  96. elif mobj.group('showname') == 'thedailyshow':
  97. epTitle = mobj.group('tdstitle')
  98. else:
  99. epTitle = mobj.group('cntitle')
  100. dlNewest = False
  101. elif mobj.group('interview'):
  102. epTitle = mobj.group('interview_title')
  103. dlNewest = False
  104. else:
  105. dlNewest = not mobj.group('episode')
  106. if dlNewest:
  107. epTitle = mobj.group('showname')
  108. else:
  109. epTitle = mobj.group('episode')
  110. show_name = mobj.group('showname')
  111. webpage, htmlHandle = self._download_webpage_handle(url, epTitle)
  112. if dlNewest:
  113. url = htmlHandle.geturl()
  114. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  115. if mobj is None:
  116. raise ExtractorError('Invalid redirected URL: ' + url)
  117. if mobj.group('episode') == '':
  118. raise ExtractorError('Redirected URL is still not specific: ' + url)
  119. epTitle = mobj.group('episode').rpartition('/')[-1]
  120. mMovieParams = re.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage)
  121. if len(mMovieParams) == 0:
  122. # The Colbert Report embeds the information in a without
  123. # a URL prefix; so extract the alternate reference
  124. # and then add the URL prefix manually.
  125. altMovieParams = re.findall('data-mgid="([^"]*(?:episode|video|playlist).*?:.*?)"', webpage)
  126. if len(altMovieParams) == 0:
  127. raise ExtractorError('unable to find Flash URL in webpage ' + url)
  128. else:
  129. mMovieParams = [("http://media.mtvnservices.com/" + altMovieParams[0], altMovieParams[0])]
  130. uri = mMovieParams[0][1]
  131. # Correct cc.com in uri
  132. uri = re.sub(r'(episode:[^.]+)(\.cc)?\.com', r'\1.cc.com', uri)
  133. index_url = 'http://%s.cc.com/feeds/mrss?%s' % (show_name, compat_urllib_parse.urlencode({'uri': uri}))
  134. idoc = self._download_xml(
  135. index_url, epTitle,
  136. 'Downloading show index', 'Unable to download episode index')
  137. title = idoc.find('./channel/title').text
  138. description = idoc.find('./channel/description').text
  139. entries = []
  140. item_els = idoc.findall('.//item')
  141. for part_num, itemEl in enumerate(item_els):
  142. upload_date = unified_strdate(itemEl.findall('./pubDate')[0].text)
  143. thumbnail = itemEl.find('.//{http://search.yahoo.com/mrss/}thumbnail').attrib.get('url')
  144. content = itemEl.find('.//{http://search.yahoo.com/mrss/}content')
  145. duration = float_or_none(content.attrib.get('duration'))
  146. mediagen_url = content.attrib['url']
  147. guid = itemEl.find('./guid').text.rpartition(':')[-1]
  148. cdoc = self._download_xml(
  149. mediagen_url, epTitle,
  150. 'Downloading configuration for segment %d / %d' % (part_num + 1, len(item_els)))
  151. turls = []
  152. for rendition in cdoc.findall('.//rendition'):
  153. finfo = (rendition.attrib['bitrate'], rendition.findall('./src')[0].text)
  154. turls.append(finfo)
  155. formats = []
  156. for format, rtmp_video_url in turls:
  157. w, h = self._video_dimensions.get(format, (None, None))
  158. formats.append({
  159. 'format_id': 'vhttp-%s' % format,
  160. 'url': self._transform_rtmp_url(rtmp_video_url),
  161. 'ext': self._video_extensions.get(format, 'mp4'),
  162. 'height': h,
  163. 'width': w,
  164. })
  165. formats.append({
  166. 'format_id': 'rtmp-%s' % format,
  167. 'url': rtmp_video_url.replace('viacomccstrm', 'viacommtvstrm'),
  168. 'ext': self._video_extensions.get(format, 'mp4'),
  169. 'height': h,
  170. 'width': w,
  171. })
  172. self._sort_formats(formats)
  173. virtual_id = show_name + ' ' + epTitle + ' part ' + compat_str(part_num + 1)
  174. entries.append({
  175. 'id': guid,
  176. 'title': virtual_id,
  177. 'formats': formats,
  178. 'uploader': show_name,
  179. 'upload_date': upload_date,
  180. 'duration': duration,
  181. 'thumbnail': thumbnail,
  182. 'description': description,
  183. })
  184. return {
  185. '_type': 'playlist',
  186. 'entries': entries,
  187. 'title': show_name + ' ' + title,
  188. 'description': description,
  189. }