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.

236 lines
9.8 KiB

  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]+)/(?:playlist_tds_extended_)?(?P<interview_title>.*?)(/.*?)?)))
  46. '''
  47. _TESTS = [{
  48. 'url': 'http://thedailyshow.cc.com/watch/thu-december-13-2012/kristen-stewart',
  49. 'md5': '4e2f5cb088a83cd8cdb7756132f9739d',
  50. 'info_dict': {
  51. 'id': 'ab9ab3e7-5a98-4dbe-8b21-551dc0523d55',
  52. 'ext': 'mp4',
  53. 'upload_date': '20121213',
  54. 'description': 'Kristen Stewart learns to let loose in "On the Road."',
  55. 'uploader': 'thedailyshow',
  56. 'title': 'thedailyshow kristen-stewart part 1',
  57. }
  58. }, {
  59. 'url': 'http://thedailyshow.cc.com/extended-interviews/xm3fnq/andrew-napolitano-extended-interview',
  60. 'only_matching': True,
  61. }, {
  62. 'url': 'http://thecolbertreport.cc.com/videos/29w6fx/-realhumanpraise-for-fox-news',
  63. 'only_matching': True,
  64. }, {
  65. 'url': 'http://thecolbertreport.cc.com/videos/gh6urb/neil-degrasse-tyson-pt--1?xrs=eml_col_031114',
  66. 'only_matching': True,
  67. }, {
  68. 'url': 'http://thedailyshow.cc.com/guests/michael-lewis/3efna8/exclusive---michael-lewis-extended-interview-pt--3',
  69. 'only_matching': True,
  70. }, {
  71. 'url': 'http://thedailyshow.cc.com/episodes/sy7yv0/april-8--2014---denis-leary',
  72. 'only_matching': True,
  73. }, {
  74. 'url': 'http://thecolbertreport.cc.com/episodes/8ase07/april-8--2014---jane-goodall',
  75. 'only_matching': True,
  76. }, {
  77. 'url': 'http://thedailyshow.cc.com/video-playlists/npde3s/the-daily-show-19088-highlights',
  78. 'only_matching': True,
  79. }, {
  80. 'url': 'http://thedailyshow.cc.com/video-playlists/t6d9sg/the-daily-show-20038-highlights/be3cwo',
  81. 'only_matching': True,
  82. }, {
  83. 'url': 'http://thedailyshow.cc.com/special-editions/2l8fdb/special-edition---a-look-back-at-food',
  84. 'only_matching': True,
  85. }, {
  86. 'url': 'http://thedailyshow.cc.com/news-team/michael-che/7wnfel/we-need-to-talk-about-israel',
  87. 'only_matching': True,
  88. }]
  89. _available_formats = ['3500', '2200', '1700', '1200', '750', '400']
  90. _video_extensions = {
  91. '3500': 'mp4',
  92. '2200': 'mp4',
  93. '1700': 'mp4',
  94. '1200': 'mp4',
  95. '750': 'mp4',
  96. '400': 'mp4',
  97. }
  98. _video_dimensions = {
  99. '3500': (1280, 720),
  100. '2200': (960, 540),
  101. '1700': (768, 432),
  102. '1200': (640, 360),
  103. '750': (512, 288),
  104. '400': (384, 216),
  105. }
  106. def _real_extract(self, url):
  107. mobj = re.match(self._VALID_URL, url)
  108. if mobj.group('shortname'):
  109. if mobj.group('shortname') in ('tds', 'thedailyshow'):
  110. url = 'http://thedailyshow.cc.com/full-episodes/'
  111. else:
  112. url = 'http://thecolbertreport.cc.com/full-episodes/'
  113. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  114. assert mobj is not None
  115. if mobj.group('clip'):
  116. if mobj.group('videotitle'):
  117. epTitle = mobj.group('videotitle')
  118. elif mobj.group('showname') == 'thedailyshow':
  119. epTitle = mobj.group('tdstitle')
  120. else:
  121. epTitle = mobj.group('cntitle')
  122. dlNewest = False
  123. elif mobj.group('interview'):
  124. epTitle = mobj.group('interview_title')
  125. dlNewest = False
  126. else:
  127. dlNewest = not mobj.group('episode')
  128. if dlNewest:
  129. epTitle = mobj.group('showname')
  130. else:
  131. epTitle = mobj.group('episode')
  132. show_name = mobj.group('showname')
  133. webpage, htmlHandle = self._download_webpage_handle(url, epTitle)
  134. if dlNewest:
  135. url = htmlHandle.geturl()
  136. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  137. if mobj is None:
  138. raise ExtractorError('Invalid redirected URL: ' + url)
  139. if mobj.group('episode') == '':
  140. raise ExtractorError('Redirected URL is still not specific: ' + url)
  141. epTitle = (mobj.group('episode') or mobj.group('videotitle')).rpartition('/')[-1]
  142. mMovieParams = re.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage)
  143. if len(mMovieParams) == 0:
  144. # The Colbert Report embeds the information in a without
  145. # a URL prefix; so extract the alternate reference
  146. # and then add the URL prefix manually.
  147. altMovieParams = re.findall('data-mgid="([^"]*(?:episode|video|playlist).*?:.*?)"', webpage)
  148. if len(altMovieParams) == 0:
  149. raise ExtractorError('unable to find Flash URL in webpage ' + url)
  150. else:
  151. mMovieParams = [("http://media.mtvnservices.com/" + altMovieParams[0], altMovieParams[0])]
  152. uri = mMovieParams[0][1]
  153. # Correct cc.com in uri
  154. uri = re.sub(r'(episode:[^.]+)(\.cc)?\.com', r'\1.cc.com', uri)
  155. index_url = 'http://%s.cc.com/feeds/mrss?%s' % (show_name, compat_urllib_parse.urlencode({'uri': uri}))
  156. idoc = self._download_xml(
  157. index_url, epTitle,
  158. 'Downloading show index', 'Unable to download episode index')
  159. title = idoc.find('./channel/title').text
  160. description = idoc.find('./channel/description').text
  161. entries = []
  162. item_els = idoc.findall('.//item')
  163. for part_num, itemEl in enumerate(item_els):
  164. upload_date = unified_strdate(itemEl.findall('./pubDate')[0].text)
  165. thumbnail = itemEl.find('.//{http://search.yahoo.com/mrss/}thumbnail').attrib.get('url')
  166. content = itemEl.find('.//{http://search.yahoo.com/mrss/}content')
  167. duration = float_or_none(content.attrib.get('duration'))
  168. mediagen_url = content.attrib['url']
  169. guid = itemEl.find('./guid').text.rpartition(':')[-1]
  170. cdoc = self._download_xml(
  171. mediagen_url, epTitle,
  172. 'Downloading configuration for segment %d / %d' % (part_num + 1, len(item_els)))
  173. turls = []
  174. for rendition in cdoc.findall('.//rendition'):
  175. finfo = (rendition.attrib['bitrate'], rendition.findall('./src')[0].text)
  176. turls.append(finfo)
  177. formats = []
  178. for format, rtmp_video_url in turls:
  179. w, h = self._video_dimensions.get(format, (None, None))
  180. formats.append({
  181. 'format_id': 'vhttp-%s' % format,
  182. 'url': self._transform_rtmp_url(rtmp_video_url),
  183. 'ext': self._video_extensions.get(format, 'mp4'),
  184. 'height': h,
  185. 'width': w,
  186. })
  187. formats.append({
  188. 'format_id': 'rtmp-%s' % format,
  189. 'url': rtmp_video_url.replace('viacomccstrm', 'viacommtvstrm'),
  190. 'ext': self._video_extensions.get(format, 'mp4'),
  191. 'height': h,
  192. 'width': w,
  193. })
  194. self._sort_formats(formats)
  195. virtual_id = show_name + ' ' + epTitle + ' part ' + compat_str(part_num + 1)
  196. entries.append({
  197. 'id': guid,
  198. 'title': virtual_id,
  199. 'formats': formats,
  200. 'uploader': show_name,
  201. 'upload_date': upload_date,
  202. 'duration': duration,
  203. 'thumbnail': thumbnail,
  204. 'description': description,
  205. })
  206. return {
  207. '_type': 'playlist',
  208. 'entries': entries,
  209. 'title': show_name + ' ' + title,
  210. 'description': description,
  211. }