cbsinteractive.py 3.9 KB

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