cbs.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. from __future__ import unicode_literals
  2. from .theplatform import ThePlatformIE
  3. from ..utils import (
  4. xpath_text,
  5. xpath_element,
  6. int_or_none,
  7. ExtractorError,
  8. find_xpath_attr,
  9. )
  10. class CBSIE(ThePlatformIE):
  11. _VALID_URL = r'https?://(?:www\.)?(?:cbs\.com/shows/[^/]+/(?:video|artist)|colbertlateshow\.com/(?:video|podcasts))/[^/]+/(?P<id>[^/]+)'
  12. _TESTS = [{
  13. 'url': 'http://www.cbs.com/shows/garth-brooks/video/_u7W953k6la293J7EPTd9oHkSPs6Xn6_/connect-chat-feat-garth-brooks/',
  14. 'info_dict': {
  15. 'id': '_u7W953k6la293J7EPTd9oHkSPs6Xn6_',
  16. 'display_id': 'connect-chat-feat-garth-brooks',
  17. 'ext': 'mp4',
  18. 'title': 'Connect Chat feat. Garth Brooks',
  19. 'description': 'Connect with country music singer Garth Brooks, as he chats with fans on Wednesday November 27, 2013. Be sure to tune in to Garth Brooks: Live from Las Vegas, Friday November 29, at 9/8c on CBS!',
  20. 'duration': 1495,
  21. },
  22. 'params': {
  23. # rtmp download
  24. 'skip_download': True,
  25. },
  26. '_skip': 'Blocked outside the US',
  27. }, {
  28. 'url': 'http://www.cbs.com/shows/liveonletterman/artist/221752/st-vincent/',
  29. 'info_dict': {
  30. 'id': 'WWF_5KqY3PK1',
  31. 'display_id': 'st-vincent',
  32. 'ext': 'flv',
  33. 'title': 'Live on Letterman - St. Vincent',
  34. 'description': 'Live On Letterman: St. Vincent in concert from New York\'s Ed Sullivan Theater on Tuesday, July 16, 2014.',
  35. 'duration': 3221,
  36. },
  37. 'params': {
  38. # rtmp download
  39. 'skip_download': True,
  40. },
  41. '_skip': 'Blocked outside the US',
  42. }, {
  43. 'url': 'http://colbertlateshow.com/video/8GmB0oY0McANFvp2aEffk9jZZZ2YyXxy/the-colbeard/',
  44. 'only_matching': True,
  45. }, {
  46. 'url': 'http://www.colbertlateshow.com/podcasts/dYSwjqPs_X1tvbV_P2FcPWRa_qT6akTC/in-the-bad-room-with-stephen/',
  47. 'only_matching': True,
  48. }]
  49. TP_RELEASE_URL_TEMPLATE = 'http://link.theplatform.com/s/dJ5BDC/%s?manifest=m3u&mbr=true'
  50. def _parse_smil_subtitles(self, smil, namespace=None, subtitles_lang='en'):
  51. closed_caption_e = find_xpath_attr(smil, self._xpath_ns('.//param', namespace), 'name', 'ClosedCaptionURL')
  52. return {
  53. 'en': [{
  54. 'ext': 'ttml',
  55. 'url': closed_caption_e.attrib['value'],
  56. }]
  57. } if closed_caption_e is not None and closed_caption_e.attrib.get('value') else []
  58. def _real_extract(self, url):
  59. display_id = self._match_id(url)
  60. webpage = self._download_webpage(url, display_id)
  61. content_id = self._search_regex(
  62. [r"video\.settings\.content_id\s*=\s*'([^']+)';", r"cbsplayer\.contentId\s*=\s*'([^']+)';"],
  63. webpage, 'content id')
  64. items_data = self._download_xml(
  65. 'http://can.cbs.com/thunder/player/videoPlayerService.php',
  66. content_id, query={'partner': 'cbs', 'contentId': content_id})
  67. video_data = xpath_element(items_data, './/item')
  68. title = xpath_text(video_data, 'videoTitle', 'title', True)
  69. subtitles = {}
  70. formats = []
  71. for item in items_data.findall('.//item'):
  72. pid = xpath_text(item, 'pid')
  73. if not pid:
  74. continue
  75. try:
  76. tp_formats, tp_subtitles = self._extract_theplatform_smil(
  77. self.TP_RELEASE_URL_TEMPLATE % pid, content_id, 'Downloading %s SMIL data' % pid)
  78. except ExtractorError:
  79. continue
  80. formats.extend(tp_formats)
  81. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  82. self._sort_formats(formats)
  83. info = self.get_metadata('dJ5BDC/media/guid/2198311517/%s' % content_id, content_id)
  84. info.update({
  85. 'id': content_id,
  86. 'display_id': display_id,
  87. 'title': title,
  88. 'series': xpath_text(video_data, 'seriesTitle'),
  89. 'season_number': int_or_none(xpath_text(video_data, 'seasonNumber')),
  90. 'episode_number': int_or_none(xpath_text(video_data, 'episodeNumber')),
  91. 'duration': int_or_none(xpath_text(video_data, 'videoLength'), 1000),
  92. 'thumbnail': xpath_text(video_data, 'previewImageURL'),
  93. 'formats': formats,
  94. 'subtitles': subtitles,
  95. })
  96. return info