cnet.py 2.4 KB

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