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.

105 lines
4.4 KiB

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