cnet.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .theplatform import ThePlatformIE
  4. from ..utils import int_or_none
  5. class CNETIE(ThePlatformIE):
  6. _VALID_URL = r'https?://(?:www\.)?cnet\.com/videos/(?P<id>[^/]+)/'
  7. _TESTS = [{
  8. 'url': 'http://www.cnet.com/videos/hands-on-with-microsofts-windows-8-1-update/',
  9. 'info_dict': {
  10. 'id': '56f4ea68-bd21-4852-b08c-4de5b8354c60',
  11. 'ext': 'flv',
  12. 'title': 'Hands-on with Microsoft Windows 8.1 Update',
  13. 'description': 'The new update to the Windows 8 OS brings improved performance for mouse and keyboard users.',
  14. 'uploader_id': '6085384d-619e-11e3-b231-14feb5ca9861',
  15. 'uploader': 'Sarah Mitroff',
  16. 'duration': 70,
  17. 'timestamp': 1396479627,
  18. 'upload_date': '20140402',
  19. },
  20. }, {
  21. 'url': 'http://www.cnet.com/videos/whiny-pothole-tweets-at-local-government-when-hit-by-cars-tomorrow-daily-187/',
  22. 'info_dict': {
  23. 'id': '56527b93-d25d-44e3-b738-f989ce2e49ba',
  24. 'ext': 'flv',
  25. 'title': 'Whiny potholes tweet at local government when hit by cars (Tomorrow Daily 187)',
  26. 'description': 'Khail and Ashley wonder what other civic woes can be solved by self-tweeting objects, investigate a new kind of VR camera and watch an origami robot self-assemble, walk, climb, dig and dissolve. #TDPothole',
  27. 'uploader_id': 'b163284d-6b73-44fc-b3e6-3da66c392d40',
  28. 'uploader': 'Ashley Esqueda',
  29. 'duration': 1482,
  30. 'timestamp': 1433289889,
  31. 'upload_date': '20150603',
  32. },
  33. }]
  34. TP_RELEASE_URL_TEMPLATE = 'http://link.theplatform.com/s/kYEXFC/%s?mbr=true'
  35. def _real_extract(self, url):
  36. display_id = self._match_id(url)
  37. webpage = self._download_webpage(url, display_id)
  38. data_json = self._html_search_regex(
  39. r"data-cnet-video(?:-uvp)?-options='([^']+)'",
  40. webpage, 'data json')
  41. data = self._parse_json(data_json, display_id)
  42. vdata = data.get('video') or data['videos'][0]
  43. video_id = vdata['id']
  44. title = vdata['title']
  45. author = vdata.get('author')
  46. if author:
  47. uploader = '%s %s' % (author['firstName'], author['lastName'])
  48. uploader_id = author.get('id')
  49. else:
  50. uploader = None
  51. uploader_id = None
  52. media_guid_path = 'media/guid/2288573011/%s' % vdata['mpxRefId']
  53. formats, subtitles = self._extract_theplatform_smil(self.TP_RELEASE_URL_TEMPLATE % media_guid_path, video_id)
  54. for (fkey, vid) in vdata['files'].items():
  55. if fkey == 'hls_phone' and 'hls_tablet' in vdata['files']:
  56. continue
  57. release_url = self.TP_RELEASE_URL_TEMPLATE % vid
  58. if fkey == 'hds':
  59. release_url += '&manifest=f4m'
  60. tp_formats, tp_subtitles = self._extract_theplatform_smil(release_url, video_id, 'Downloading %s SMIL data' % fkey)
  61. formats.extend(tp_formats)
  62. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  63. self._sort_formats(formats)
  64. info = self.get_metadata('kYEXFC/%s' % media_guid_path, video_id)
  65. info.update({
  66. 'id': video_id,
  67. 'display_id': display_id,
  68. 'title': title,
  69. 'duration': int_or_none(vdata.get('duration')),
  70. 'uploader': uploader,
  71. 'uploader_id': uploader_id,
  72. 'subtitles': subtitles,
  73. 'formats': formats,
  74. })
  75. return info