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.

245 lines
10 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\.)?cc\.com/
  14. (video-clips|episodes|cc-studios|video-collections|full-episodes)
  15. /(?P<title>.*)'''
  16. _FEED_URL = 'http://comedycentral.com/feeds/mrss/'
  17. _TEST = {
  18. 'url': 'http://www.cc.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|news-team/[^/]+)/[^/]+/(?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. _TESTS = [{
  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. 'url': 'http://thedailyshow.cc.com/extended-interviews/xm3fnq/andrew-napolitano-extended-interview',
  59. 'only_matching': True,
  60. }, {
  61. 'url': 'http://thecolbertreport.cc.com/videos/29w6fx/-realhumanpraise-for-fox-news',
  62. 'only_matching': True,
  63. }, {
  64. 'url': 'http://thecolbertreport.cc.com/videos/gh6urb/neil-degrasse-tyson-pt--1?xrs=eml_col_031114',
  65. 'only_matching': True,
  66. }, {
  67. 'url': 'http://thedailyshow.cc.com/guests/michael-lewis/3efna8/exclusive---michael-lewis-extended-interview-pt--3',
  68. 'only_matching': True,
  69. }, {
  70. 'url': 'http://thedailyshow.cc.com/episodes/sy7yv0/april-8--2014---denis-leary',
  71. 'only_matching': True,
  72. }, {
  73. 'url': 'http://thecolbertreport.cc.com/episodes/8ase07/april-8--2014---jane-goodall',
  74. 'only_matching': True,
  75. }, {
  76. 'url': 'http://thedailyshow.cc.com/video-playlists/npde3s/the-daily-show-19088-highlights',
  77. 'only_matching': True,
  78. }, {
  79. 'url': 'http://thedailyshow.cc.com/special-editions/2l8fdb/special-edition---a-look-back-at-food',
  80. 'only_matching': True,
  81. }, {
  82. 'url': 'http://thedailyshow.cc.com/news-team/michael-che/7wnfel/we-need-to-talk-about-israel',
  83. 'only_matching': True,
  84. }]
  85. _available_formats = ['3500', '2200', '1700', '1200', '750', '400']
  86. _video_extensions = {
  87. '3500': 'mp4',
  88. '2200': 'mp4',
  89. '1700': 'mp4',
  90. '1200': 'mp4',
  91. '750': 'mp4',
  92. '400': 'mp4',
  93. }
  94. _video_dimensions = {
  95. '3500': (1280, 720),
  96. '2200': (960, 540),
  97. '1700': (768, 432),
  98. '1200': (640, 360),
  99. '750': (512, 288),
  100. '400': (384, 216),
  101. }
  102. @staticmethod
  103. def _transform_rtmp_url(rtmp_video_url):
  104. m = re.match(r'^rtmpe?://.*?/(?P<finalid>gsp\.comedystor/.*)$', rtmp_video_url)
  105. if not m:
  106. raise ExtractorError('Cannot transform RTMP url')
  107. base = 'http://mtvnmobile.vo.llnwd.net/kip0/_pxn=1+_pxI0=Ripod-h264+_pxL0=undefined+_pxM0=+_pxK=18639+_pxE=mp4/44620/mtvnorigin/'
  108. return base + m.group('finalid')
  109. def _real_extract(self, url):
  110. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  111. if mobj is None:
  112. raise ExtractorError('Invalid URL: %s' % url)
  113. if mobj.group('shortname'):
  114. if mobj.group('shortname') in ('tds', 'thedailyshow'):
  115. url = 'http://thedailyshow.cc.com/full-episodes/'
  116. else:
  117. url = 'http://thecolbertreport.cc.com/full-episodes/'
  118. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  119. assert mobj is not None
  120. if mobj.group('clip'):
  121. if mobj.group('videotitle'):
  122. epTitle = mobj.group('videotitle')
  123. elif mobj.group('showname') == 'thedailyshow':
  124. epTitle = mobj.group('tdstitle')
  125. else:
  126. epTitle = mobj.group('cntitle')
  127. dlNewest = False
  128. elif mobj.group('interview'):
  129. epTitle = mobj.group('interview_title')
  130. dlNewest = False
  131. else:
  132. dlNewest = not mobj.group('episode')
  133. if dlNewest:
  134. epTitle = mobj.group('showname')
  135. else:
  136. epTitle = mobj.group('episode')
  137. show_name = mobj.group('showname')
  138. webpage, htmlHandle = self._download_webpage_handle(url, epTitle)
  139. if dlNewest:
  140. url = htmlHandle.geturl()
  141. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  142. if mobj is None:
  143. raise ExtractorError('Invalid redirected URL: ' + url)
  144. if mobj.group('episode') == '':
  145. raise ExtractorError('Redirected URL is still not specific: ' + url)
  146. epTitle = (mobj.group('episode') or mobj.group('videotitle')).rpartition('/')[-1]
  147. mMovieParams = re.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage)
  148. if len(mMovieParams) == 0:
  149. # The Colbert Report embeds the information in a without
  150. # a URL prefix; so extract the alternate reference
  151. # and then add the URL prefix manually.
  152. altMovieParams = re.findall('data-mgid="([^"]*(?:episode|video|playlist).*?:.*?)"', webpage)
  153. if len(altMovieParams) == 0:
  154. raise ExtractorError('unable to find Flash URL in webpage ' + url)
  155. else:
  156. mMovieParams = [("http://media.mtvnservices.com/" + altMovieParams[0], altMovieParams[0])]
  157. uri = mMovieParams[0][1]
  158. # Correct cc.com in uri
  159. uri = re.sub(r'(episode:[^.]+)(\.cc)?\.com', r'\1.cc.com', uri)
  160. index_url = 'http://%s.cc.com/feeds/mrss?%s' % (show_name, compat_urllib_parse.urlencode({'uri': uri}))
  161. idoc = self._download_xml(
  162. index_url, epTitle,
  163. 'Downloading show index', 'Unable to download episode index')
  164. title = idoc.find('./channel/title').text
  165. description = idoc.find('./channel/description').text
  166. entries = []
  167. item_els = idoc.findall('.//item')
  168. for part_num, itemEl in enumerate(item_els):
  169. upload_date = unified_strdate(itemEl.findall('./pubDate')[0].text)
  170. thumbnail = itemEl.find('.//{http://search.yahoo.com/mrss/}thumbnail').attrib.get('url')
  171. content = itemEl.find('.//{http://search.yahoo.com/mrss/}content')
  172. duration = float_or_none(content.attrib.get('duration'))
  173. mediagen_url = content.attrib['url']
  174. guid = itemEl.find('./guid').text.rpartition(':')[-1]
  175. cdoc = self._download_xml(
  176. mediagen_url, epTitle,
  177. 'Downloading configuration for segment %d / %d' % (part_num + 1, len(item_els)))
  178. turls = []
  179. for rendition in cdoc.findall('.//rendition'):
  180. finfo = (rendition.attrib['bitrate'], rendition.findall('./src')[0].text)
  181. turls.append(finfo)
  182. formats = []
  183. for format, rtmp_video_url in turls:
  184. w, h = self._video_dimensions.get(format, (None, None))
  185. formats.append({
  186. 'format_id': 'vhttp-%s' % format,
  187. 'url': self._transform_rtmp_url(rtmp_video_url),
  188. 'ext': self._video_extensions.get(format, 'mp4'),
  189. 'height': h,
  190. 'width': w,
  191. 'format_note': 'HTTP 400 at the moment (patches welcome!)',
  192. 'preference': -100,
  193. })
  194. formats.append({
  195. 'format_id': 'rtmp-%s' % format,
  196. 'url': rtmp_video_url.replace('viacomccstrm', 'viacommtvstrm'),
  197. 'ext': self._video_extensions.get(format, 'mp4'),
  198. 'height': h,
  199. 'width': w,
  200. })
  201. self._sort_formats(formats)
  202. virtual_id = show_name + ' ' + epTitle + ' part ' + compat_str(part_num + 1)
  203. entries.append({
  204. 'id': guid,
  205. 'title': virtual_id,
  206. 'formats': formats,
  207. 'uploader': show_name,
  208. 'upload_date': upload_date,
  209. 'duration': duration,
  210. 'thumbnail': thumbnail,
  211. 'description': description,
  212. })
  213. return {
  214. '_type': 'playlist',
  215. 'entries': entries,
  216. 'title': show_name + ' ' + title,
  217. 'description': description,
  218. }