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.

272 lines
12 KiB

10 years ago
10 years ago
10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .mtv import MTVServicesInfoExtractor
  4. from ..compat import (
  5. compat_str,
  6. compat_urllib_parse,
  7. )
  8. from ..utils import (
  9. ExtractorError,
  10. float_or_none,
  11. unified_strdate,
  12. )
  13. class ComedyCentralIE(MTVServicesInfoExtractor):
  14. _VALID_URL = r'''(?x)https?://(?:www\.)?cc\.com/
  15. (video-clips|episodes|cc-studios|video-collections|full-episodes|shows)
  16. /(?P<title>.*)'''
  17. _FEED_URL = 'http://comedycentral.com/feeds/mrss/'
  18. _TESTS = [{
  19. 'url': 'http://www.cc.com/video-clips/kllhuv/stand-up-greg-fitzsimmons--uncensored---too-good-of-a-mother',
  20. 'md5': 'c4f48e9eda1b16dd10add0744344b6d8',
  21. 'info_dict': {
  22. 'id': 'cef0cbb3-e776-4bc9-b62e-8016deccb354',
  23. 'ext': 'mp4',
  24. 'title': 'CC:Stand-Up|Greg Fitzsimmons: Life on Stage|Uncensored - Too Good of a Mother',
  25. 'description': 'After a certain point, breastfeeding becomes c**kblocking.',
  26. },
  27. }, {
  28. 'url': 'http://www.cc.com/shows/the-daily-show-with-trevor-noah/interviews/6yx39d/exclusive-rand-paul-extended-interview',
  29. 'only_matching': True,
  30. }]
  31. class ComedyCentralShowsIE(MTVServicesInfoExtractor):
  32. IE_DESC = 'The Daily Show / The Colbert Report'
  33. # urls can be abbreviations like :thedailyshow
  34. # urls for episodes like:
  35. # or urls for clips like: http://www.thedailyshow.com/watch/mon-december-10-2012/any-given-gun-day
  36. # or: http://www.colbertnation.com/the-colbert-report-videos/421667/november-29-2012/moon-shattering-news
  37. # or: http://www.colbertnation.com/the-colbert-report-collections/422008/festival-of-lights/79524
  38. _VALID_URL = r'''(?x)^(:(?P<shortname>tds|thedailyshow)
  39. |https?://(:www\.)?
  40. (?P<showname>thedailyshow|thecolbertreport)\.(?:cc\.)?com/
  41. ((?:full-)?episodes/(?:[0-9a-z]{6}/)?(?P<episode>.*)|
  42. (?P<clip>
  43. (?:(?:guests/[^/]+|videos|video-playlists|special-editions|news-team/[^/]+)/[^/]+/(?P<videotitle>[^/?#]+))
  44. |(the-colbert-report-(videos|collections)/(?P<clipID>[0-9]+)/[^/]*/(?P<cntitle>.*?))
  45. |(watch/(?P<date>[^/]*)/(?P<tdstitle>.*))
  46. )|
  47. (?P<interview>
  48. extended-interviews/(?P<interID>[0-9a-z]+)/
  49. (?:playlist_tds_extended_)?(?P<interview_title>[^/?#]*?)
  50. (?:/[^/?#]?|[?#]|$))))
  51. '''
  52. _TESTS = [{
  53. 'url': 'http://thedailyshow.cc.com/watch/thu-december-13-2012/kristen-stewart',
  54. 'md5': '4e2f5cb088a83cd8cdb7756132f9739d',
  55. 'info_dict': {
  56. 'id': 'ab9ab3e7-5a98-4dbe-8b21-551dc0523d55',
  57. 'ext': 'mp4',
  58. 'upload_date': '20121213',
  59. 'description': 'Kristen Stewart learns to let loose in "On the Road."',
  60. 'uploader': 'thedailyshow',
  61. 'title': 'thedailyshow kristen-stewart part 1',
  62. }
  63. }, {
  64. 'url': 'http://thedailyshow.cc.com/extended-interviews/b6364d/sarah-chayes-extended-interview',
  65. 'info_dict': {
  66. 'id': 'sarah-chayes-extended-interview',
  67. 'description': 'Carnegie Endowment Senior Associate Sarah Chayes discusses how corrupt institutions function throughout the world in her book "Thieves of State: Why Corruption Threatens Global Security."',
  68. 'title': 'thedailyshow Sarah Chayes Extended Interview',
  69. },
  70. 'playlist': [
  71. {
  72. 'info_dict': {
  73. 'id': '0baad492-cbec-4ec1-9e50-ad91c291127f',
  74. 'ext': 'mp4',
  75. 'upload_date': '20150129',
  76. 'description': 'Carnegie Endowment Senior Associate Sarah Chayes discusses how corrupt institutions function throughout the world in her book "Thieves of State: Why Corruption Threatens Global Security."',
  77. 'uploader': 'thedailyshow',
  78. 'title': 'thedailyshow sarah-chayes-extended-interview part 1',
  79. },
  80. },
  81. {
  82. 'info_dict': {
  83. 'id': '1e4fb91b-8ce7-4277-bd7c-98c9f1bbd283',
  84. 'ext': 'mp4',
  85. 'upload_date': '20150129',
  86. 'description': 'Carnegie Endowment Senior Associate Sarah Chayes discusses how corrupt institutions function throughout the world in her book "Thieves of State: Why Corruption Threatens Global Security."',
  87. 'uploader': 'thedailyshow',
  88. 'title': 'thedailyshow sarah-chayes-extended-interview part 2',
  89. },
  90. },
  91. ],
  92. 'params': {
  93. 'skip_download': True,
  94. },
  95. }, {
  96. 'url': 'http://thedailyshow.cc.com/extended-interviews/xm3fnq/andrew-napolitano-extended-interview',
  97. 'only_matching': True,
  98. }, {
  99. 'url': 'http://thecolbertreport.cc.com/videos/29w6fx/-realhumanpraise-for-fox-news',
  100. 'only_matching': True,
  101. }, {
  102. 'url': 'http://thecolbertreport.cc.com/videos/gh6urb/neil-degrasse-tyson-pt--1?xrs=eml_col_031114',
  103. 'only_matching': True,
  104. }, {
  105. 'url': 'http://thedailyshow.cc.com/guests/michael-lewis/3efna8/exclusive---michael-lewis-extended-interview-pt--3',
  106. 'only_matching': True,
  107. }, {
  108. 'url': 'http://thedailyshow.cc.com/episodes/sy7yv0/april-8--2014---denis-leary',
  109. 'only_matching': True,
  110. }, {
  111. 'url': 'http://thecolbertreport.cc.com/episodes/8ase07/april-8--2014---jane-goodall',
  112. 'only_matching': True,
  113. }, {
  114. 'url': 'http://thedailyshow.cc.com/video-playlists/npde3s/the-daily-show-19088-highlights',
  115. 'only_matching': True,
  116. }, {
  117. 'url': 'http://thedailyshow.cc.com/video-playlists/t6d9sg/the-daily-show-20038-highlights/be3cwo',
  118. 'only_matching': True,
  119. }, {
  120. 'url': 'http://thedailyshow.cc.com/special-editions/2l8fdb/special-edition---a-look-back-at-food',
  121. 'only_matching': True,
  122. }, {
  123. 'url': 'http://thedailyshow.cc.com/news-team/michael-che/7wnfel/we-need-to-talk-about-israel',
  124. 'only_matching': True,
  125. }]
  126. _available_formats = ['3500', '2200', '1700', '1200', '750', '400']
  127. _video_extensions = {
  128. '3500': 'mp4',
  129. '2200': 'mp4',
  130. '1700': 'mp4',
  131. '1200': 'mp4',
  132. '750': 'mp4',
  133. '400': 'mp4',
  134. }
  135. _video_dimensions = {
  136. '3500': (1280, 720),
  137. '2200': (960, 540),
  138. '1700': (768, 432),
  139. '1200': (640, 360),
  140. '750': (512, 288),
  141. '400': (384, 216),
  142. }
  143. def _real_extract(self, url):
  144. mobj = re.match(self._VALID_URL, url)
  145. if mobj.group('shortname'):
  146. return self.url_result('http://www.cc.com/shows/the-daily-show-with-trevor-noah/full-episodes')
  147. if mobj.group('clip'):
  148. if mobj.group('videotitle'):
  149. epTitle = mobj.group('videotitle')
  150. elif mobj.group('showname') == 'thedailyshow':
  151. epTitle = mobj.group('tdstitle')
  152. else:
  153. epTitle = mobj.group('cntitle')
  154. dlNewest = False
  155. elif mobj.group('interview'):
  156. epTitle = mobj.group('interview_title')
  157. dlNewest = False
  158. else:
  159. dlNewest = not mobj.group('episode')
  160. if dlNewest:
  161. epTitle = mobj.group('showname')
  162. else:
  163. epTitle = mobj.group('episode')
  164. show_name = mobj.group('showname')
  165. webpage, htmlHandle = self._download_webpage_handle(url, epTitle)
  166. if dlNewest:
  167. url = htmlHandle.geturl()
  168. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  169. if mobj is None:
  170. raise ExtractorError('Invalid redirected URL: ' + url)
  171. if mobj.group('episode') == '':
  172. raise ExtractorError('Redirected URL is still not specific: ' + url)
  173. epTitle = (mobj.group('episode') or mobj.group('videotitle')).rpartition('/')[-1]
  174. mMovieParams = re.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage)
  175. if len(mMovieParams) == 0:
  176. # The Colbert Report embeds the information in a without
  177. # a URL prefix; so extract the alternate reference
  178. # and then add the URL prefix manually.
  179. altMovieParams = re.findall('data-mgid="([^"]*(?:episode|video|playlist).*?:.*?)"', webpage)
  180. if len(altMovieParams) == 0:
  181. raise ExtractorError('unable to find Flash URL in webpage ' + url)
  182. else:
  183. mMovieParams = [('http://media.mtvnservices.com/' + altMovieParams[0], altMovieParams[0])]
  184. uri = mMovieParams[0][1]
  185. # Correct cc.com in uri
  186. uri = re.sub(r'(episode:[^.]+)(\.cc)?\.com', r'\1.com', uri)
  187. index_url = 'http://%s.cc.com/feeds/mrss?%s' % (show_name, compat_urllib_parse.urlencode({'uri': uri}))
  188. idoc = self._download_xml(
  189. index_url, epTitle,
  190. 'Downloading show index', 'Unable to download episode index')
  191. title = idoc.find('./channel/title').text
  192. description = idoc.find('./channel/description').text
  193. entries = []
  194. item_els = idoc.findall('.//item')
  195. for part_num, itemEl in enumerate(item_els):
  196. upload_date = unified_strdate(itemEl.findall('./pubDate')[0].text)
  197. thumbnail = itemEl.find('.//{http://search.yahoo.com/mrss/}thumbnail').attrib.get('url')
  198. content = itemEl.find('.//{http://search.yahoo.com/mrss/}content')
  199. duration = float_or_none(content.attrib.get('duration'))
  200. mediagen_url = content.attrib['url']
  201. guid = itemEl.find('./guid').text.rpartition(':')[-1]
  202. cdoc = self._download_xml(
  203. mediagen_url, epTitle,
  204. 'Downloading configuration for segment %d / %d' % (part_num + 1, len(item_els)))
  205. turls = []
  206. for rendition in cdoc.findall('.//rendition'):
  207. finfo = (rendition.attrib['bitrate'], rendition.findall('./src')[0].text)
  208. turls.append(finfo)
  209. formats = []
  210. for format, rtmp_video_url in turls:
  211. w, h = self._video_dimensions.get(format, (None, None))
  212. formats.append({
  213. 'format_id': 'vhttp-%s' % format,
  214. 'url': self._transform_rtmp_url(rtmp_video_url),
  215. 'ext': self._video_extensions.get(format, 'mp4'),
  216. 'height': h,
  217. 'width': w,
  218. })
  219. formats.append({
  220. 'format_id': 'rtmp-%s' % format,
  221. 'url': rtmp_video_url.replace('viacomccstrm', 'viacommtvstrm'),
  222. 'ext': self._video_extensions.get(format, 'mp4'),
  223. 'height': h,
  224. 'width': w,
  225. })
  226. self._sort_formats(formats)
  227. subtitles = self._extract_subtitles(cdoc, guid)
  228. virtual_id = show_name + ' ' + epTitle + ' part ' + compat_str(part_num + 1)
  229. entries.append({
  230. 'id': guid,
  231. 'title': virtual_id,
  232. 'formats': formats,
  233. 'uploader': show_name,
  234. 'upload_date': upload_date,
  235. 'duration': duration,
  236. 'thumbnail': thumbnail,
  237. 'description': description,
  238. 'subtitles': subtitles,
  239. })
  240. return {
  241. '_type': 'playlist',
  242. 'id': epTitle,
  243. 'entries': entries,
  244. 'title': show_name + ' ' + title,
  245. 'description': description,
  246. }