cbsinteractive.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .theplatform import ThePlatformIE
  5. from ..compat import compat_urllib_parse
  6. from ..utils import int_or_none
  7. class CBSInteractiveIE(ThePlatformIE):
  8. _VALID_URL = r'https?://(?:www\.)?(?P<site>cnet|zdnet)\.com/(?:videos|video/share)/(?P<id>[^/?]+)'
  9. _TESTS = [{
  10. 'url': 'http://www.cnet.com/videos/hands-on-with-microsofts-windows-8-1-update/',
  11. 'info_dict': {
  12. 'id': '56f4ea68-bd21-4852-b08c-4de5b8354c60',
  13. 'ext': 'flv',
  14. 'title': 'Hands-on with Microsoft Windows 8.1 Update',
  15. 'description': 'The new update to the Windows 8 OS brings improved performance for mouse and keyboard users.',
  16. 'uploader_id': '6085384d-619e-11e3-b231-14feb5ca9861',
  17. 'uploader': 'Sarah Mitroff',
  18. 'duration': 70,
  19. 'timestamp': 1396479627,
  20. 'upload_date': '20140402',
  21. },
  22. }, {
  23. 'url': 'http://www.cnet.com/videos/whiny-pothole-tweets-at-local-government-when-hit-by-cars-tomorrow-daily-187/',
  24. 'info_dict': {
  25. 'id': '56527b93-d25d-44e3-b738-f989ce2e49ba',
  26. 'ext': 'flv',
  27. 'title': 'Whiny potholes tweet at local government when hit by cars (Tomorrow Daily 187)',
  28. 'description': 'Khail and Ashley wonder what other civic woes can be solved by self-tweeting objects, investigate a new kind of VR camera and watch an origami robot self-assemble, walk, climb, dig and dissolve. #TDPothole',
  29. 'uploader_id': 'b163284d-6b73-44fc-b3e6-3da66c392d40',
  30. 'uploader': 'Ashley Esqueda',
  31. 'duration': 1482,
  32. 'timestamp': 1433289889,
  33. 'upload_date': '20150603',
  34. },
  35. }, {
  36. 'url': 'http://www.zdnet.com/video/share/video-keeping-android-smartphones-and-tablets-secure/',
  37. 'info_dict': {
  38. 'id': 'bc1af9f0-a2b5-4e54-880d-0d95525781c0',
  39. 'ext': 'mp4',
  40. 'title': 'Video: Keeping Android smartphones and tablets secure',
  41. 'description': 'Here\'s the best way to keep Android devices secure, and what you do when they\'ve come to the end of their lives.',
  42. 'uploader_id': 'f2d97ea2-8175-11e2-9d12-0018fe8a00b0',
  43. 'uploader': 'Adrian Kingsley-Hughes',
  44. 'timestamp': 1448961720,
  45. 'upload_date': '20151201',
  46. },
  47. 'params': {
  48. # m3u8 download
  49. 'skip_download': True,
  50. }
  51. }]
  52. TP_RELEASE_URL_TEMPLATE = 'http://link.theplatform.com/s/kYEXFC/%s?mbr=true'
  53. MPX_ACCOUNTS = {
  54. 'cnet': 2288573011,
  55. 'zdnet': 2387448114,
  56. }
  57. def _real_extract(self, url):
  58. site, display_id = re.match(self._VALID_URL, url).groups()
  59. webpage = self._download_webpage(url, display_id)
  60. data_json = self._html_search_regex(
  61. r"data-(?:cnet|zdnet)-video(?:-uvp(?:js)?)?-options='([^']+)'",
  62. webpage, 'data json')
  63. data = self._parse_json(data_json, display_id)
  64. vdata = data.get('video') or data['videos'][0]
  65. video_id = vdata['id']
  66. title = vdata['title']
  67. author = vdata.get('author')
  68. if author:
  69. uploader = '%s %s' % (author['firstName'], author['lastName'])
  70. uploader_id = author.get('id')
  71. else:
  72. uploader = None
  73. uploader_id = None
  74. media_guid_path = 'media/guid/%d/%s' % (self.MPX_ACCOUNTS[site], vdata['mpxRefId'])
  75. formats, subtitles = [], {}
  76. for (fkey, vid) in vdata.get('files', {}).items():
  77. if fkey == 'hls_phone' and 'hls_tablet' in vdata['files']:
  78. continue
  79. release_url = self.TP_RELEASE_URL_TEMPLATE % vid
  80. if fkey == 'hds':
  81. release_url += '&manifest=f4m'
  82. tp_formats, tp_subtitles = self._extract_theplatform_smil(release_url, video_id, 'Downloading %s SMIL data' % fkey)
  83. formats.extend(tp_formats)
  84. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  85. if 'm3u8' in vdata:
  86. parsed_url = compat_urllib_parse.urlparse(url)
  87. m3u8_url = ('%s://%s%s'
  88. % (parsed_url.scheme, parsed_url.netloc, vdata['m3u8']))
  89. m3u8_formats = self._extract_m3u8_formats(m3u8_url, video_id)
  90. for format in m3u8_formats:
  91. format['url'] = format['url'].replace('https://', 'http://')
  92. formats.extend(m3u8_formats)
  93. if 'mp4' in vdata:
  94. formats.append({
  95. 'url': vdata['mp4'],
  96. 'format_id': 'mp4',
  97. 'ext': 'mp4',
  98. })
  99. self._sort_formats(formats)
  100. info = self._extract_theplatform_metadata('kYEXFC/%s' % media_guid_path, video_id)
  101. info.update({
  102. 'id': video_id,
  103. 'display_id': display_id,
  104. 'title': title,
  105. 'duration': int_or_none(vdata.get('duration')),
  106. 'uploader': uploader,
  107. 'uploader_id': uploader_id,
  108. 'subtitles': subtitles,
  109. 'formats': formats,
  110. })
  111. return info