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.

79 lines
2.6 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\"\s+.*?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.get('headline')
  40. if title is None:
  41. title = vdata.get('title')
  42. if title is None:
  43. raise ExtractorError('Cannot find title!')
  44. description = vdata.get('dek')
  45. thumbnail = vdata.get('image', {}).get('path')
  46. author = vdata.get('author')
  47. if author:
  48. uploader = '%s %s' % (author['firstName'], author['lastName'])
  49. uploader_id = author.get('email')
  50. else:
  51. uploader = None
  52. uploader_id = None
  53. formats = [{
  54. 'format_id': '%s-%s-%s' % (
  55. f['type'], f['format'],
  56. int_or_none(f.get('bitrate'), 1000, default='')),
  57. 'url': f['uri'],
  58. 'tbr': int_or_none(f.get('bitrate'), 1000),
  59. } for f in vdata['files']['data']]
  60. self._sort_formats(formats)
  61. return {
  62. 'id': video_id,
  63. 'display_id': display_id,
  64. 'title': title,
  65. 'formats': formats,
  66. 'description': description,
  67. 'uploader': uploader,
  68. 'uploader_id': uploader_id,
  69. 'thumbnail': thumbnail,
  70. }