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.

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