logo

youtube-dl

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

cbsinteractive.py (4044B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .cbs import CBSIE
  5. from ..utils import int_or_none
  6. class CBSInteractiveIE(CBSIE):
  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': 'R49SYt__yAfmlXR85z4f7gNmCBDcN_00',
  12. 'display_id': 'hands-on-with-microsofts-windows-8-1-update',
  13. 'ext': 'mp4',
  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. 'params': {
  23. # m3u8 download
  24. 'skip_download': True,
  25. },
  26. }, {
  27. 'url': 'http://www.cnet.com/videos/whiny-pothole-tweets-at-local-government-when-hit-by-cars-tomorrow-daily-187/',
  28. 'md5': 'f11d27b2fa18597fbf92444d2a9ed386',
  29. 'info_dict': {
  30. 'id': 'kjOJd_OoVJqbg_ZD8MZCOk8Wekb9QccK',
  31. 'display_id': 'whiny-pothole-tweets-at-local-government-when-hit-by-cars-tomorrow-daily-187',
  32. 'ext': 'mp4',
  33. 'title': 'Whiny potholes tweet at local government when hit by cars (Tomorrow Daily 187)',
  34. 'description': 'md5:d2b9a95a5ffe978ae6fbd4cf944d618f',
  35. 'uploader_id': 'b163284d-6b73-44fc-b3e6-3da66c392d40',
  36. 'uploader': 'Ashley Esqueda',
  37. 'duration': 1482,
  38. 'timestamp': 1433289889,
  39. 'upload_date': '20150603',
  40. },
  41. }, {
  42. 'url': 'http://www.zdnet.com/video/share/video-keeping-android-smartphones-and-tablets-secure/',
  43. 'info_dict': {
  44. 'id': 'k0r4T_ehht4xW_hAOqiVQPuBDPZ8SRjt',
  45. 'display_id': 'video-keeping-android-smartphones-and-tablets-secure',
  46. 'ext': 'mp4',
  47. 'title': 'Video: Keeping Android smartphones and tablets secure',
  48. '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.',
  49. 'uploader_id': 'f2d97ea2-8175-11e2-9d12-0018fe8a00b0',
  50. 'uploader': 'Adrian Kingsley-Hughes',
  51. 'duration': 731,
  52. 'timestamp': 1449129925,
  53. 'upload_date': '20151203',
  54. },
  55. 'params': {
  56. # m3u8 download
  57. 'skip_download': True,
  58. },
  59. }, {
  60. 'url': 'http://www.zdnet.com/video/huawei-matebook-x-video/',
  61. 'only_matching': True,
  62. }]
  63. MPX_ACCOUNTS = {
  64. 'cnet': 2198311517,
  65. 'zdnet': 2387448114,
  66. }
  67. def _real_extract(self, url):
  68. site, display_id = re.match(self._VALID_URL, url).groups()
  69. webpage = self._download_webpage(url, display_id)
  70. data_json = self._html_search_regex(
  71. r"data(?:-(?:cnet|zdnet))?-video(?:-(?:uvp(?:js)?|player))?-options='([^']+)'",
  72. webpage, 'data json')
  73. data = self._parse_json(data_json, display_id)
  74. vdata = data.get('video') or (data.get('videos') or data.get('playlist'))[0]
  75. video_id = vdata['mpxRefId']
  76. title = vdata['title']
  77. author = vdata.get('author')
  78. if author:
  79. uploader = '%s %s' % (author['firstName'], author['lastName'])
  80. uploader_id = author.get('id')
  81. else:
  82. uploader = None
  83. uploader_id = None
  84. info = self._extract_video_info(video_id, site, self.MPX_ACCOUNTS[site])
  85. info.update({
  86. 'id': video_id,
  87. 'display_id': display_id,
  88. 'title': title,
  89. 'duration': int_or_none(vdata.get('duration')),
  90. 'uploader': uploader,
  91. 'uploader_id': uploader_id,
  92. })
  93. return info