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.

75 lines
2.4 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. 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. 'md5': '041233212a0d06b179c87cbcca1577b8',
  15. 'info_dict': {
  16. 'id': '56f4ea68-bd21-4852-b08c-4de5b8354c60',
  17. 'ext': 'mp4',
  18. 'title': 'Hands-on with Microsoft Windows 8.1 Update',
  19. 'description': 'The new update to the Windows 8 OS brings improved performance for mouse and keyboard users.',
  20. 'thumbnail': 're:^http://.*/flmswindows8.jpg$',
  21. 'uploader_id': 'sarah.mitroff@cbsinteractive.com',
  22. 'uploader': 'Sarah Mitroff',
  23. }
  24. }
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. display_id = mobj.group('id')
  28. webpage = self._download_webpage(url, display_id)
  29. data_json = self._html_search_regex(
  30. r"<div class=\"cnetVideoPlayer\" data-cnet-video-options='([^']+)'",
  31. webpage, 'data json')
  32. data = json.loads(data_json)
  33. vdata = data['video']
  34. if not vdata:
  35. vdata = data['videos'][0]
  36. if not vdata:
  37. raise ExtractorError('Cannot find video data')
  38. video_id = vdata['id']
  39. title = vdata['headline']
  40. description = vdata.get('dek')
  41. thumbnail = vdata.get('image', {}).get('path')
  42. author = vdata.get('author')
  43. if author:
  44. uploader = '%s %s' % (author['firstName'], author['lastName'])
  45. uploader_id = author.get('email')
  46. else:
  47. uploader = None
  48. uploader_id = None
  49. formats = [{
  50. 'format_id': '%s-%s-%s' % (
  51. f['type'], f['format'],
  52. int_or_none(f.get('bitrate'), 1000, default='')),
  53. 'url': f['uri'],
  54. 'tbr': int_or_none(f.get('bitrate'), 1000),
  55. } for f in vdata['files']['data']]
  56. self._sort_formats(formats)
  57. return {
  58. 'id': video_id,
  59. 'display_id': display_id,
  60. 'title': title,
  61. 'formats': formats,
  62. 'description': description,
  63. 'uploader': uploader,
  64. 'uploader_id': uploader_id,
  65. 'thumbnail': thumbnail,
  66. }