]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/cnet.py
[youtube] Add test with '};' in tags
[yt-dlp.git] / youtube_dl / extractor / cnet.py
CommitLineData
9271bc83
PH
1# coding: utf-8
2from __future__ import unicode_literals
3
4import json
9271bc83
PH
5
6from .common import InfoExtractor
7from ..utils import (
0e518e2f 8 ExtractorError,
9271bc83
PH
9)
10
11
12class CNETIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?cnet\.com/videos/(?P<id>[^/]+)/'
788be331 14 _TESTS = [{
9271bc83 15 'url': 'http://www.cnet.com/videos/hands-on-with-microsofts-windows-8-1-update/',
9271bc83
PH
16 'info_dict': {
17 'id': '56f4ea68-bd21-4852-b08c-4de5b8354c60',
412c617d 18 'ext': 'flv',
9271bc83
PH
19 'title': 'Hands-on with Microsoft Windows 8.1 Update',
20 'description': 'The new update to the Windows 8 OS brings improved performance for mouse and keyboard users.',
21 'thumbnail': 're:^http://.*/flmswindows8.jpg$',
412c617d 22 'uploader_id': '6085384d-619e-11e3-b231-14feb5ca9861',
9271bc83 23 'uploader': 'Sarah Mitroff',
412c617d
PH
24 },
25 'params': {
26 'skip_download': 'requires rtmpdump',
9271bc83 27 }
788be331
YCH
28 }, {
29 'url': 'http://www.cnet.com/videos/whiny-pothole-tweets-at-local-government-when-hit-by-cars-tomorrow-daily-187/',
30 'info_dict': {
31 'id': '56527b93-d25d-44e3-b738-f989ce2e49ba',
32 'ext': 'flv',
33 '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',
34 'uploader_id': 'b163284d-6b73-44fc-b3e6-3da66c392d40',
35 'uploader': 'Ashley Esqueda',
36 'title': 'Whiny potholes tweet at local government when hit by cars (Tomorrow Daily 187)',
37 },
38 'params': {
39 'skip_download': True, # requires rtmpdump
40 },
41 }]
9271bc83
PH
42
43 def _real_extract(self, url):
412c617d 44 display_id = self._match_id(url)
9271bc83 45 webpage = self._download_webpage(url, display_id)
412c617d 46
9271bc83 47 data_json = self._html_search_regex(
e51880fd 48 r"<div class=\"cnetVideoPlayer\"\s+.*?data-cnet-video-options='([^']+)'",
9271bc83
PH
49 webpage, 'data json')
50 data = json.loads(data_json)
51 vdata = data['video']
0e518e2f
PH
52 if not vdata:
53 vdata = data['videos'][0]
54 if not vdata:
55 raise ExtractorError('Cannot find video data')
9271bc83 56
412c617d 57 mpx_account = data['config']['players']['default']['mpx_account']
788be331 58 vid = vdata['files'].get('rtmp', vdata['files']['hds'])
412c617d
PH
59 tp_link = 'http://link.theplatform.com/s/%s/%s' % (mpx_account, vid)
60
9271bc83 61 video_id = vdata['id']
6f5342a2
PH
62 title = vdata.get('headline')
63 if title is None:
64 title = vdata.get('title')
65 if title is None:
66 raise ExtractorError('Cannot find title!')
9271bc83
PH
67 thumbnail = vdata.get('image', {}).get('path')
68 author = vdata.get('author')
69 if author:
70 uploader = '%s %s' % (author['firstName'], author['lastName'])
412c617d 71 uploader_id = author.get('id')
9271bc83
PH
72 else:
73 uploader = None
74 uploader_id = None
75
9271bc83 76 return {
412c617d
PH
77 '_type': 'url_transparent',
78 'url': tp_link,
9271bc83
PH
79 'id': video_id,
80 'display_id': display_id,
81 'title': title,
9271bc83
PH
82 'uploader': uploader,
83 'uploader_id': uploader_id,
84 'thumbnail': thumbnail,
85 }