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.

85 lines
3.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. )
  8. class CNETIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?cnet\.com/videos/(?P<id>[^/]+)/'
  10. _TESTS = [{
  11. 'url': 'http://www.cnet.com/videos/hands-on-with-microsofts-windows-8-1-update/',
  12. 'info_dict': {
  13. 'id': '56f4ea68-bd21-4852-b08c-4de5b8354c60',
  14. 'ext': 'flv',
  15. 'title': 'Hands-on with Microsoft Windows 8.1 Update',
  16. 'description': 'The new update to the Windows 8 OS brings improved performance for mouse and keyboard users.',
  17. 'thumbnail': 're:^http://.*/flmswindows8.jpg$',
  18. 'uploader_id': '6085384d-619e-11e3-b231-14feb5ca9861',
  19. 'uploader': 'Sarah Mitroff',
  20. },
  21. 'params': {
  22. 'skip_download': 'requires rtmpdump',
  23. }
  24. }, {
  25. 'url': 'http://www.cnet.com/videos/whiny-pothole-tweets-at-local-government-when-hit-by-cars-tomorrow-daily-187/',
  26. 'info_dict': {
  27. 'id': '56527b93-d25d-44e3-b738-f989ce2e49ba',
  28. 'ext': 'flv',
  29. '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',
  30. 'uploader_id': 'b163284d-6b73-44fc-b3e6-3da66c392d40',
  31. 'uploader': 'Ashley Esqueda',
  32. 'title': 'Whiny potholes tweet at local government when hit by cars (Tomorrow Daily 187)',
  33. },
  34. 'params': {
  35. 'skip_download': True, # requires rtmpdump
  36. },
  37. }]
  38. def _real_extract(self, url):
  39. display_id = self._match_id(url)
  40. webpage = self._download_webpage(url, display_id)
  41. data_json = self._html_search_regex(
  42. r"<div class=\"cnetVideoPlayer\"\s+.*?data-cnet-video-options='([^']+)'",
  43. webpage, 'data json')
  44. data = json.loads(data_json)
  45. vdata = data['video']
  46. if not vdata:
  47. vdata = data['videos'][0]
  48. if not vdata:
  49. raise ExtractorError('Cannot find video data')
  50. mpx_account = data['config']['players']['default']['mpx_account']
  51. vid = vdata['files'].get('rtmp', vdata['files']['hds'])
  52. tp_link = 'http://link.theplatform.com/s/%s/%s' % (mpx_account, vid)
  53. video_id = vdata['id']
  54. title = vdata.get('headline')
  55. if title is None:
  56. title = vdata.get('title')
  57. if title is None:
  58. raise ExtractorError('Cannot find title!')
  59. thumbnail = vdata.get('image', {}).get('path')
  60. author = vdata.get('author')
  61. if author:
  62. uploader = '%s %s' % (author['firstName'], author['lastName'])
  63. uploader_id = author.get('id')
  64. else:
  65. uploader = None
  66. uploader_id = None
  67. return {
  68. '_type': 'url_transparent',
  69. 'url': tp_link,
  70. 'id': video_id,
  71. 'display_id': display_id,
  72. 'title': title,
  73. 'uploader': uploader,
  74. 'uploader_id': uploader_id,
  75. 'thumbnail': thumbnail,
  76. }