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.

231 lines
9.7 KiB

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