[cnet] Update to new theplatform infrastructure (Fixes #2736)
[youtube-dl] / youtube_dl / extractor / cnet.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import json
5 import re
6
7 from .common import InfoExtractor
8 from ..utils import (
9     ExtractorError,
10     int_or_none,
11 )
12
13
14 class CNETIE(InfoExtractor):
15     _VALID_URL = r'https?://(?:www\.)?cnet\.com/videos/(?P<id>[^/]+)/'
16     _TEST = {
17         'url': 'http://www.cnet.com/videos/hands-on-with-microsofts-windows-8-1-update/',
18         'info_dict': {
19             'id': '56f4ea68-bd21-4852-b08c-4de5b8354c60',
20             'ext': 'flv',
21             'title': 'Hands-on with Microsoft Windows 8.1 Update',
22             'description': 'The new update to the Windows 8 OS brings improved performance for mouse and keyboard users.',
23             'thumbnail': 're:^http://.*/flmswindows8.jpg$',
24             'uploader_id': '6085384d-619e-11e3-b231-14feb5ca9861',
25             'uploader': 'Sarah Mitroff',
26         },
27         'params': {
28             'skip_download': 'requires rtmpdump',
29         }
30     }
31
32     def _real_extract(self, url):
33         display_id = self._match_id(url)
34         webpage = self._download_webpage(url, display_id)
35
36         data_json = self._html_search_regex(
37             r"<div class=\"cnetVideoPlayer\"\s+.*?data-cnet-video-options='([^']+)'",
38             webpage, 'data json')
39         data = json.loads(data_json)
40         vdata = data['video']
41         if not vdata:
42             vdata = data['videos'][0]
43         if not vdata:
44             raise ExtractorError('Cannot find video data')
45
46         mpx_account = data['config']['players']['default']['mpx_account']
47         vid = vdata['files']['rtmp']
48         tp_link = 'http://link.theplatform.com/s/%s/%s' % (mpx_account, vid)
49
50         video_id = vdata['id']
51         title = vdata.get('headline')
52         if title is None:
53             title = vdata.get('title')
54         if title is None:
55             raise ExtractorError('Cannot find title!')
56         thumbnail = vdata.get('image', {}).get('path')
57         author = vdata.get('author')
58         if author:
59             uploader = '%s %s' % (author['firstName'], author['lastName'])
60             uploader_id = author.get('id')
61         else:
62             uploader = None
63             uploader_id = None
64
65         return {
66             '_type': 'url_transparent',
67             'url': tp_link,
68             'id': video_id,
69             'display_id': display_id,
70             'title': title,
71             'uploader': uploader,
72             'uploader_id': uploader_id,
73             'thumbnail': thumbnail,
74         }