logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

cbs.py (4856B)


  1. from __future__ import unicode_literals
  2. from .theplatform import ThePlatformFeedIE
  3. from ..utils import (
  4. ExtractorError,
  5. int_or_none,
  6. find_xpath_attr,
  7. xpath_element,
  8. xpath_text,
  9. update_url_query,
  10. )
  11. class CBSBaseIE(ThePlatformFeedIE):
  12. def _parse_smil_subtitles(self, smil, namespace=None, subtitles_lang='en'):
  13. subtitles = {}
  14. for k, ext in [('sMPTE-TTCCURL', 'tt'), ('ClosedCaptionURL', 'ttml'), ('webVTTCaptionURL', 'vtt')]:
  15. cc_e = find_xpath_attr(smil, self._xpath_ns('.//param', namespace), 'name', k)
  16. if cc_e is not None:
  17. cc_url = cc_e.get('value')
  18. if cc_url:
  19. subtitles.setdefault(subtitles_lang, []).append({
  20. 'ext': ext,
  21. 'url': cc_url,
  22. })
  23. return subtitles
  24. class CBSIE(CBSBaseIE):
  25. _VALID_URL = r'(?:cbs:|https?://(?:www\.)?(?:(?:cbs|paramountplus)\.com/shows/[^/]+/video|colbertlateshow\.com/(?:video|podcasts))/)(?P<id>[\w-]+)'
  26. _TESTS = [{
  27. 'url': 'http://www.cbs.com/shows/garth-brooks/video/_u7W953k6la293J7EPTd9oHkSPs6Xn6_/connect-chat-feat-garth-brooks/',
  28. 'info_dict': {
  29. 'id': '_u7W953k6la293J7EPTd9oHkSPs6Xn6_',
  30. 'ext': 'mp4',
  31. 'title': 'Connect Chat feat. Garth Brooks',
  32. '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!',
  33. 'duration': 1495,
  34. 'timestamp': 1385585425,
  35. 'upload_date': '20131127',
  36. 'uploader': 'CBSI-NEW',
  37. },
  38. 'params': {
  39. # m3u8 download
  40. 'skip_download': True,
  41. },
  42. '_skip': 'Blocked outside the US',
  43. }, {
  44. 'url': 'http://colbertlateshow.com/video/8GmB0oY0McANFvp2aEffk9jZZZ2YyXxy/the-colbeard/',
  45. 'only_matching': True,
  46. }, {
  47. 'url': 'http://www.colbertlateshow.com/podcasts/dYSwjqPs_X1tvbV_P2FcPWRa_qT6akTC/in-the-bad-room-with-stephen/',
  48. 'only_matching': True,
  49. }, {
  50. 'url': 'https://www.paramountplus.com/shows/all-rise/video/QmR1WhNkh1a_IrdHZrbcRklm176X_rVc/all-rise-space/',
  51. 'only_matching': True,
  52. }]
  53. def _extract_video_info(self, content_id, site='cbs', mpx_acc=2198311517):
  54. items_data = self._download_xml(
  55. 'http://can.cbs.com/thunder/player/videoPlayerService.php',
  56. content_id, query={'partner': site, 'contentId': content_id})
  57. video_data = xpath_element(items_data, './/item')
  58. title = xpath_text(video_data, 'videoTitle', 'title', True)
  59. tp_path = 'dJ5BDC/media/guid/%d/%s' % (mpx_acc, content_id)
  60. tp_release_url = 'http://link.theplatform.com/s/' + tp_path
  61. asset_types = []
  62. subtitles = {}
  63. formats = []
  64. last_e = None
  65. for item in items_data.findall('.//item'):
  66. asset_type = xpath_text(item, 'assetType')
  67. if not asset_type or asset_type in asset_types or 'HLS_FPS' in asset_type or 'DASH_CENC' in asset_type:
  68. continue
  69. asset_types.append(asset_type)
  70. query = {
  71. 'mbr': 'true',
  72. 'assetTypes': asset_type,
  73. }
  74. if asset_type.startswith('HLS') or asset_type in ('OnceURL', 'StreamPack'):
  75. query['formats'] = 'MPEG4,M3U'
  76. elif asset_type in ('RTMP', 'WIFI', '3G'):
  77. query['formats'] = 'MPEG4,FLV'
  78. try:
  79. tp_formats, tp_subtitles = self._extract_theplatform_smil(
  80. update_url_query(tp_release_url, query), content_id,
  81. 'Downloading %s SMIL data' % asset_type)
  82. except ExtractorError as e:
  83. last_e = e
  84. continue
  85. formats.extend(tp_formats)
  86. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  87. if last_e and not formats:
  88. raise last_e
  89. self._sort_formats(formats)
  90. info = self._extract_theplatform_metadata(tp_path, content_id)
  91. info.update({
  92. 'id': content_id,
  93. 'title': title,
  94. 'series': xpath_text(video_data, 'seriesTitle'),
  95. 'season_number': int_or_none(xpath_text(video_data, 'seasonNumber')),
  96. 'episode_number': int_or_none(xpath_text(video_data, 'episodeNumber')),
  97. 'duration': int_or_none(xpath_text(video_data, 'videoLength'), 1000),
  98. 'thumbnail': xpath_text(video_data, 'previewImageURL'),
  99. 'formats': formats,
  100. 'subtitles': subtitles,
  101. })
  102. return info
  103. def _real_extract(self, url):
  104. content_id = self._match_id(url)
  105. return self._extract_video_info(content_id)