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.

234 lines
9.8 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(MTVServicesInfoExtractor):
  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. def _real_extract(self, url):
  103. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  104. if mobj is None:
  105. raise ExtractorError('Invalid URL: %s' % url)
  106. if mobj.group('shortname'):
  107. if mobj.group('shortname') in ('tds', 'thedailyshow'):
  108. url = 'http://thedailyshow.cc.com/full-episodes/'
  109. else:
  110. url = 'http://thecolbertreport.cc.com/full-episodes/'
  111. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  112. assert mobj is not None
  113. if mobj.group('clip'):
  114. if mobj.group('videotitle'):
  115. epTitle = mobj.group('videotitle')
  116. elif mobj.group('showname') == 'thedailyshow':
  117. epTitle = mobj.group('tdstitle')
  118. else:
  119. epTitle = mobj.group('cntitle')
  120. dlNewest = False
  121. elif mobj.group('interview'):
  122. epTitle = mobj.group('interview_title')
  123. dlNewest = False
  124. else:
  125. dlNewest = not mobj.group('episode')
  126. if dlNewest:
  127. epTitle = mobj.group('showname')
  128. else:
  129. epTitle = mobj.group('episode')
  130. show_name = mobj.group('showname')
  131. webpage, htmlHandle = self._download_webpage_handle(url, epTitle)
  132. if dlNewest:
  133. url = htmlHandle.geturl()
  134. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  135. if mobj is None:
  136. raise ExtractorError('Invalid redirected URL: ' + url)
  137. if mobj.group('episode') == '':
  138. raise ExtractorError('Redirected URL is still not specific: ' + url)
  139. epTitle = (mobj.group('episode') or mobj.group('videotitle')).rpartition('/')[-1]
  140. mMovieParams = re.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage)
  141. if len(mMovieParams) == 0:
  142. # The Colbert Report embeds the information in a without
  143. # a URL prefix; so extract the alternate reference
  144. # and then add the URL prefix manually.
  145. altMovieParams = re.findall('data-mgid="([^"]*(?:episode|video|playlist).*?:.*?)"', webpage)
  146. if len(altMovieParams) == 0:
  147. raise ExtractorError('unable to find Flash URL in webpage ' + url)
  148. else:
  149. mMovieParams = [("http://media.mtvnservices.com/" + altMovieParams[0], altMovieParams[0])]
  150. uri = mMovieParams[0][1]
  151. # Correct cc.com in uri
  152. uri = re.sub(r'(episode:[^.]+)(\.cc)?\.com', r'\1.cc.com', uri)
  153. index_url = 'http://%s.cc.com/feeds/mrss?%s' % (show_name, compat_urllib_parse.urlencode({'uri': uri}))
  154. idoc = self._download_xml(
  155. index_url, epTitle,
  156. 'Downloading show index', 'Unable to download episode index')
  157. title = idoc.find('./channel/title').text
  158. description = idoc.find('./channel/description').text
  159. entries = []
  160. item_els = idoc.findall('.//item')
  161. for part_num, itemEl in enumerate(item_els):
  162. upload_date = unified_strdate(itemEl.findall('./pubDate')[0].text)
  163. thumbnail = itemEl.find('.//{http://search.yahoo.com/mrss/}thumbnail').attrib.get('url')
  164. content = itemEl.find('.//{http://search.yahoo.com/mrss/}content')
  165. duration = float_or_none(content.attrib.get('duration'))
  166. mediagen_url = content.attrib['url']
  167. guid = itemEl.find('./guid').text.rpartition(':')[-1]
  168. cdoc = self._download_xml(
  169. mediagen_url, epTitle,
  170. 'Downloading configuration for segment %d / %d' % (part_num + 1, len(item_els)))
  171. turls = []
  172. for rendition in cdoc.findall('.//rendition'):
  173. finfo = (rendition.attrib['bitrate'], rendition.findall('./src')[0].text)
  174. turls.append(finfo)
  175. formats = []
  176. for format, rtmp_video_url in turls:
  177. w, h = self._video_dimensions.get(format, (None, None))
  178. formats.append({
  179. 'format_id': 'vhttp-%s' % format,
  180. 'url': self._transform_rtmp_url(rtmp_video_url),
  181. 'ext': self._video_extensions.get(format, 'mp4'),
  182. 'height': h,
  183. 'width': w,
  184. })
  185. formats.append({
  186. 'format_id': 'rtmp-%s' % format,
  187. 'url': rtmp_video_url.replace('viacomccstrm', 'viacommtvstrm'),
  188. 'ext': self._video_extensions.get(format, 'mp4'),
  189. 'height': h,
  190. 'width': w,
  191. })
  192. self._sort_formats(formats)
  193. virtual_id = show_name + ' ' + epTitle + ' part ' + compat_str(part_num + 1)
  194. entries.append({
  195. 'id': guid,
  196. 'title': virtual_id,
  197. 'formats': formats,
  198. 'uploader': show_name,
  199. 'upload_date': upload_date,
  200. 'duration': duration,
  201. 'thumbnail': thumbnail,
  202. 'description': description,
  203. })
  204. return {
  205. '_type': 'playlist',
  206. 'entries': entries,
  207. 'title': show_name + ' ' + title,
  208. 'description': description,
  209. }