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.

274 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. if mobj.group('shortname') in ('tds', 'thedailyshow'):
  144. url = 'http://thedailyshow.cc.com/full-episodes/'
  145. else:
  146. url = 'http://thecolbertreport.cc.com/full-episodes/'
  147. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  148. assert mobj is not None
  149. if mobj.group('clip'):
  150. if mobj.group('videotitle'):
  151. epTitle = mobj.group('videotitle')
  152. elif mobj.group('showname') == 'thedailyshow':
  153. epTitle = mobj.group('tdstitle')
  154. else:
  155. epTitle = mobj.group('cntitle')
  156. dlNewest = False
  157. elif mobj.group('interview'):
  158. epTitle = mobj.group('interview_title')
  159. dlNewest = False
  160. else:
  161. dlNewest = not mobj.group('episode')
  162. if dlNewest:
  163. epTitle = mobj.group('showname')
  164. else:
  165. epTitle = mobj.group('episode')
  166. show_name = mobj.group('showname')
  167. webpage, htmlHandle = self._download_webpage_handle(url, epTitle)
  168. if dlNewest:
  169. url = htmlHandle.geturl()
  170. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  171. if mobj is None:
  172. raise ExtractorError('Invalid redirected URL: ' + url)
  173. if mobj.group('episode') == '':
  174. raise ExtractorError('Redirected URL is still not specific: ' + url)
  175. epTitle = (mobj.group('episode') or mobj.group('videotitle')).rpartition('/')[-1]
  176. mMovieParams = re.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage)
  177. if len(mMovieParams) == 0:
  178. # The Colbert Report embeds the information in a without
  179. # a URL prefix; so extract the alternate reference
  180. # and then add the URL prefix manually.
  181. altMovieParams = re.findall('data-mgid="([^"]*(?:episode|video|playlist).*?:.*?)"', webpage)
  182. if len(altMovieParams) == 0:
  183. raise ExtractorError('unable to find Flash URL in webpage ' + url)
  184. else:
  185. mMovieParams = [("http://media.mtvnservices.com/" + altMovieParams[0], altMovieParams[0])]
  186. uri = mMovieParams[0][1]
  187. # Correct cc.com in uri
  188. uri = re.sub(r'(episode:[^.]+)(\.cc)?\.com', r'\1.com', uri)
  189. index_url = 'http://%s.cc.com/feeds/mrss?%s' % (show_name, compat_urllib_parse.urlencode({'uri': uri}))
  190. idoc = self._download_xml(
  191. index_url, epTitle,
  192. 'Downloading show index', 'Unable to download episode index')
  193. title = idoc.find('./channel/title').text
  194. description = idoc.find('./channel/description').text
  195. entries = []
  196. item_els = idoc.findall('.//item')
  197. for part_num, itemEl in enumerate(item_els):
  198. upload_date = unified_strdate(itemEl.findall('./pubDate')[0].text)
  199. thumbnail = itemEl.find('.//{http://search.yahoo.com/mrss/}thumbnail').attrib.get('url')
  200. content = itemEl.find('.//{http://search.yahoo.com/mrss/}content')
  201. duration = float_or_none(content.attrib.get('duration'))
  202. mediagen_url = content.attrib['url']
  203. guid = itemEl.find('./guid').text.rpartition(':')[-1]
  204. cdoc = self._download_xml(
  205. mediagen_url, epTitle,
  206. 'Downloading configuration for segment %d / %d' % (part_num + 1, len(item_els)))
  207. turls = []
  208. for rendition in cdoc.findall('.//rendition'):
  209. finfo = (rendition.attrib['bitrate'], rendition.findall('./src')[0].text)
  210. turls.append(finfo)
  211. formats = []
  212. for format, rtmp_video_url in turls:
  213. w, h = self._video_dimensions.get(format, (None, None))
  214. formats.append({
  215. 'format_id': 'vhttp-%s' % format,
  216. 'url': self._transform_rtmp_url(rtmp_video_url),
  217. 'ext': self._video_extensions.get(format, 'mp4'),
  218. 'height': h,
  219. 'width': w,
  220. })
  221. formats.append({
  222. 'format_id': 'rtmp-%s' % format,
  223. 'url': rtmp_video_url.replace('viacomccstrm', 'viacommtvstrm'),
  224. 'ext': self._video_extensions.get(format, 'mp4'),
  225. 'height': h,
  226. 'width': w,
  227. })
  228. self._sort_formats(formats)
  229. subtitles = self._extract_subtitles(cdoc, guid)
  230. virtual_id = show_name + ' ' + epTitle + ' part ' + compat_str(part_num + 1)
  231. entries.append({
  232. 'id': guid,
  233. 'title': virtual_id,
  234. 'formats': formats,
  235. 'uploader': show_name,
  236. 'upload_date': upload_date,
  237. 'duration': duration,
  238. 'thumbnail': thumbnail,
  239. 'description': description,
  240. 'subtitles': subtitles,
  241. })
  242. return {
  243. '_type': 'playlist',
  244. 'id': epTitle,
  245. 'entries': entries,
  246. 'title': show_name + ' ' + title,
  247. 'description': description,
  248. }