]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/cbsinteractive.py
[ard] Improve _VALID_URL (closes #25134) (#25198)
[youtube-dl.git] / youtube_dl / extractor / cbsinteractive.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .cbs import CBSIE
7 from ..utils import int_or_none
8
9
10 class CBSInteractiveIE(CBSIE):
11     _VALID_URL = r'https?://(?:www\.)?(?P<site>cnet|zdnet)\.com/(?:videos|video(?:/share)?)/(?P<id>[^/?]+)'
12     _TESTS = [{
13         'url': 'http://www.cnet.com/videos/hands-on-with-microsofts-windows-8-1-update/',
14         'info_dict': {
15             'id': 'R49SYt__yAfmlXR85z4f7gNmCBDcN_00',
16             'display_id': 'hands-on-with-microsofts-windows-8-1-update',
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             'uploader_id': '6085384d-619e-11e3-b231-14feb5ca9861',
21             'uploader': 'Sarah Mitroff',
22             'duration': 70,
23             'timestamp': 1396479627,
24             'upload_date': '20140402',
25         },
26         'params': {
27             # m3u8 download
28             'skip_download': True,
29         },
30     }, {
31         'url': 'http://www.cnet.com/videos/whiny-pothole-tweets-at-local-government-when-hit-by-cars-tomorrow-daily-187/',
32         'md5': 'f11d27b2fa18597fbf92444d2a9ed386',
33         'info_dict': {
34             'id': 'kjOJd_OoVJqbg_ZD8MZCOk8Wekb9QccK',
35             'display_id': 'whiny-pothole-tweets-at-local-government-when-hit-by-cars-tomorrow-daily-187',
36             'ext': 'mp4',
37             'title': 'Whiny potholes tweet at local government when hit by cars (Tomorrow Daily 187)',
38             'description': 'md5:d2b9a95a5ffe978ae6fbd4cf944d618f',
39             'uploader_id': 'b163284d-6b73-44fc-b3e6-3da66c392d40',
40             'uploader': 'Ashley Esqueda',
41             'duration': 1482,
42             'timestamp': 1433289889,
43             'upload_date': '20150603',
44         },
45     }, {
46         'url': 'http://www.zdnet.com/video/share/video-keeping-android-smartphones-and-tablets-secure/',
47         'info_dict': {
48             'id': 'k0r4T_ehht4xW_hAOqiVQPuBDPZ8SRjt',
49             'display_id': 'video-keeping-android-smartphones-and-tablets-secure',
50             'ext': 'mp4',
51             'title': 'Video: Keeping Android smartphones and tablets secure',
52             '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.',
53             'uploader_id': 'f2d97ea2-8175-11e2-9d12-0018fe8a00b0',
54             'uploader': 'Adrian Kingsley-Hughes',
55             'duration': 731,
56             'timestamp': 1449129925,
57             'upload_date': '20151203',
58         },
59         'params': {
60             # m3u8 download
61             'skip_download': True,
62         },
63     }, {
64         'url': 'http://www.zdnet.com/video/huawei-matebook-x-video/',
65         'only_matching': True,
66     }]
67
68     MPX_ACCOUNTS = {
69         'cnet': 2198311517,
70         'zdnet': 2387448114,
71     }
72
73     def _real_extract(self, url):
74         site, display_id = re.match(self._VALID_URL, url).groups()
75         webpage = self._download_webpage(url, display_id)
76
77         data_json = self._html_search_regex(
78             r"data(?:-(?:cnet|zdnet))?-video(?:-(?:uvp(?:js)?|player))?-options='([^']+)'",
79             webpage, 'data json')
80         data = self._parse_json(data_json, display_id)
81         vdata = data.get('video') or (data.get('videos') or data.get('playlist'))[0]
82
83         video_id = vdata['mpxRefId']
84
85         title = vdata['title']
86         author = vdata.get('author')
87         if author:
88             uploader = '%s %s' % (author['firstName'], author['lastName'])
89             uploader_id = author.get('id')
90         else:
91             uploader = None
92             uploader_id = None
93
94         info = self._extract_video_info(video_id, site, self.MPX_ACCOUNTS[site])
95         info.update({
96             'id': video_id,
97             'display_id': display_id,
98             'title': title,
99             'duration': int_or_none(vdata.get('duration')),
100             'uploader': uploader,
101             'uploader_id': uploader_id,
102         })
103         return info