cbs.py 4.4 KB

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