70 lines
2.3 KiB

  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. int_or_none,
  8. )
  9. class CNETIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?cnet\.com/videos/(?P<id>[^/]+)/'
  11. _TEST = {
  12. 'url': 'http://www.cnet.com/videos/hands-on-with-microsofts-windows-8-1-update/',
  13. 'md5': '041233212a0d06b179c87cbcca1577b8',
  14. 'info_dict': {
  15. 'id': '56f4ea68-bd21-4852-b08c-4de5b8354c60',
  16. 'ext': 'mp4',
  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': 'sarah.mitroff@cbsinteractive.com',
  21. 'uploader': 'Sarah Mitroff',
  22. }
  23. }
  24. def _real_extract(self, url):
  25. mobj = re.match(self._VALID_URL, url)
  26. display_id = mobj.group('id')
  27. webpage = self._download_webpage(url, display_id)
  28. data_json = self._html_search_regex(
  29. r"<div class=\"cnetVideoPlayer\" data-cnet-video-options='([^']+)'",
  30. webpage, 'data json')
  31. data = json.loads(data_json)
  32. vdata = data['video']
  33. video_id = vdata['id']
  34. title = vdata['headline']
  35. description = vdata.get('dek')
  36. thumbnail = vdata.get('image', {}).get('path')
  37. author = vdata.get('author')
  38. if author:
  39. uploader = '%s %s' % (author['firstName'], author['lastName'])
  40. uploader_id = author.get('email')
  41. else:
  42. uploader = None
  43. uploader_id = None
  44. formats = [{
  45. 'format_id': '%s-%s-%s' % (
  46. f['type'], f['format'],
  47. int_or_none(f.get('bitrate'), 1000, default='')),
  48. 'url': f['uri'],
  49. 'tbr': int_or_none(f.get('bitrate'), 1000),
  50. } for f in vdata['files']['data']]
  51. self._sort_formats(formats)
  52. return {
  53. 'id': video_id,
  54. 'display_id': display_id,
  55. 'title': title,
  56. 'formats': formats,
  57. 'description': description,
  58. 'uploader': uploader,
  59. 'uploader_id': uploader_id,
  60. 'thumbnail': thumbnail,
  61. }