]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/cbsinteractive.py
[cleanup] Misc
[yt-dlp.git] / yt_dlp / extractor / cbsinteractive.py
CommitLineData
96820c1c 1from .cbs import CBSIE
c6ed6fad 2from ..utils import int_or_none
9271bc83
PH
3
4
6368e2e6 5class CBSInteractiveIE(CBSIE): # XXX: Do not subclass from concrete IE
03327bc9 6 _VALID_URL = r'https?://(?:www\.)?(?P<site>cnet|zdnet)\.com/(?:videos|video(?:/share)?)/(?P<id>[^/?]+)'
788be331 7 _TESTS = [{
9271bc83 8 'url': 'http://www.cnet.com/videos/hands-on-with-microsofts-windows-8-1-update/',
9271bc83 9 'info_dict': {
96820c1c
TF
10 'id': 'R49SYt__yAfmlXR85z4f7gNmCBDcN_00',
11 'display_id': 'hands-on-with-microsofts-windows-8-1-update',
e095109d 12 'ext': 'mp4',
9271bc83
PH
13 'title': 'Hands-on with Microsoft Windows 8.1 Update',
14 'description': 'The new update to the Windows 8 OS brings improved performance for mouse and keyboard users.',
412c617d 15 'uploader_id': '6085384d-619e-11e3-b231-14feb5ca9861',
9271bc83 16 'uploader': 'Sarah Mitroff',
c6ed6fad 17 'duration': 70,
5f705baf 18 'timestamp': 1396479627,
19 'upload_date': '20140402',
412c617d 20 },
e095109d 21 'params': {
96820c1c
TF
22 # m3u8 download
23 'skip_download': True,
e095109d 24 },
788be331
YCH
25 }, {
26 'url': 'http://www.cnet.com/videos/whiny-pothole-tweets-at-local-government-when-hit-by-cars-tomorrow-daily-187/',
96820c1c 27 'md5': 'f11d27b2fa18597fbf92444d2a9ed386',
788be331 28 'info_dict': {
96820c1c
TF
29 'id': 'kjOJd_OoVJqbg_ZD8MZCOk8Wekb9QccK',
30 'display_id': 'whiny-pothole-tweets-at-local-government-when-hit-by-cars-tomorrow-daily-187',
e095109d 31 'ext': 'mp4',
c6ed6fad 32 'title': 'Whiny potholes tweet at local government when hit by cars (Tomorrow Daily 187)',
96820c1c 33 'description': 'md5:d2b9a95a5ffe978ae6fbd4cf944d618f',
788be331
YCH
34 'uploader_id': 'b163284d-6b73-44fc-b3e6-3da66c392d40',
35 'uploader': 'Ashley Esqueda',
c6ed6fad 36 'duration': 1482,
5f705baf 37 'timestamp': 1433289889,
38 'upload_date': '20150603',
788be331 39 },
fe7ef95e 40 }, {
41 'url': 'http://www.zdnet.com/video/share/video-keeping-android-smartphones-and-tablets-secure/',
42 'info_dict': {
96820c1c
TF
43 'id': 'k0r4T_ehht4xW_hAOqiVQPuBDPZ8SRjt',
44 'display_id': 'video-keeping-android-smartphones-and-tablets-secure',
fe7ef95e 45 'ext': 'mp4',
46 'title': 'Video: Keeping Android smartphones and tablets secure',
47 'description': 'Here\'s the best way to keep Android devices secure, and what you do when they\'ve come to the end of their lives.',
48 'uploader_id': 'f2d97ea2-8175-11e2-9d12-0018fe8a00b0',
49 'uploader': 'Adrian Kingsley-Hughes',
96820c1c 50 'duration': 731,
e095109d
TF
51 'timestamp': 1449129925,
52 'upload_date': '20151203',
fe7ef95e 53 },
54 'params': {
55 # m3u8 download
56 'skip_download': True,
96820c1c 57 },
03327bc9
S
58 }, {
59 'url': 'http://www.zdnet.com/video/huawei-matebook-x-video/',
60 'only_matching': True,
788be331 61 }]
96820c1c 62
fe7ef95e 63 MPX_ACCOUNTS = {
96820c1c 64 'cnet': 2198311517,
fe7ef95e 65 'zdnet': 2387448114,
66 }
9271bc83
PH
67
68 def _real_extract(self, url):
5ad28e7f 69 site, display_id = self._match_valid_url(url).groups()
9271bc83 70 webpage = self._download_webpage(url, display_id)
412c617d 71
9271bc83 72 data_json = self._html_search_regex(
d2a422f5 73 r"data(?:-(?:cnet|zdnet))?-video(?:-(?:uvp(?:js)?|player))?-options='([^']+)'",
9271bc83 74 webpage, 'data json')
c6ed6fad 75 data = self._parse_json(data_json, display_id)
d2a422f5 76 vdata = data.get('video') or (data.get('videos') or data.get('playlist'))[0]
412c617d 77
96820c1c
TF
78 video_id = vdata['mpxRefId']
79
b306c439 80 title = vdata['title']
9271bc83
PH
81 author = vdata.get('author')
82 if author:
83 uploader = '%s %s' % (author['firstName'], author['lastName'])
412c617d 84 uploader_id = author.get('id')
9271bc83
PH
85 else:
86 uploader = None
87 uploader_id = None
88
96820c1c 89 info = self._extract_video_info(video_id, site, self.MPX_ACCOUNTS[site])
5f705baf 90 info.update({
9271bc83
PH
91 'id': video_id,
92 'display_id': display_id,
93 'title': title,
5f705baf 94 'duration': int_or_none(vdata.get('duration')),
9271bc83
PH
95 'uploader': uploader,
96 'uploader_id': uploader_id,
5f705baf 97 })
98 return info