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.

72 lines
2.4 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. _TEST = {
  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. def _real_extract(self, url):
  26. display_id = self._match_id(url)
  27. webpage = self._download_webpage(url, display_id)
  28. data_json = self._html_search_regex(
  29. r"<div class=\"cnetVideoPlayer\"\s+.*?data-cnet-video-options='([^']+)'",
  30. webpage, 'data json')
  31. data = json.loads(data_json)
  32. vdata = data['video']
  33. if not vdata:
  34. vdata = data['videos'][0]
  35. if not vdata:
  36. raise ExtractorError('Cannot find video data')
  37. mpx_account = data['config']['players']['default']['mpx_account']
  38. vid = vdata['files']['rtmp']
  39. tp_link = 'http://link.theplatform.com/s/%s/%s' % (mpx_account, vid)
  40. video_id = vdata['id']
  41. title = vdata.get('headline')
  42. if title is None:
  43. title = vdata.get('title')
  44. if title is None:
  45. raise ExtractorError('Cannot find title!')
  46. thumbnail = vdata.get('image', {}).get('path')
  47. author = vdata.get('author')
  48. if author:
  49. uploader = '%s %s' % (author['firstName'], author['lastName'])
  50. uploader_id = author.get('id')
  51. else:
  52. uploader = None
  53. uploader_id = None
  54. return {
  55. '_type': 'url_transparent',
  56. 'url': tp_link,
  57. 'id': video_id,
  58. 'display_id': display_id,
  59. 'title': title,
  60. 'uploader': uploader,
  61. 'uploader_id': uploader_id,
  62. 'thumbnail': thumbnail,
  63. }