Switch codebase to use sanitized_Request instead of
[youtube-dl] / youtube_dl / extractor / cbs.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import (
5     sanitized_Request,
6     smuggle_url,
7 )
8
9
10 class CBSIE(InfoExtractor):
11     _VALID_URL = r'https?://(?:www\.)?(?:cbs\.com/shows/[^/]+/(?:video|artist)|colbertlateshow\.com/(?:video|podcasts))/[^/]+/(?P<id>[^/]+)'
12
13     _TESTS = [{
14         'url': 'http://www.cbs.com/shows/garth-brooks/video/_u7W953k6la293J7EPTd9oHkSPs6Xn6_/connect-chat-feat-garth-brooks/',
15         'info_dict': {
16             'id': '4JUVEwq3wUT7',
17             'display_id': 'connect-chat-feat-garth-brooks',
18             'ext': 'flv',
19             'title': 'Connect Chat feat. Garth Brooks',
20             'description': 'Connect with country music singer Garth Brooks, as he chats with fans on Wednesday November 27, 2013. Be sure to tune in to Garth Brooks: Live from Las Vegas, Friday November 29, at 9/8c on CBS!',
21             'duration': 1495,
22         },
23         'params': {
24             # rtmp download
25             'skip_download': True,
26         },
27         '_skip': 'Blocked outside the US',
28     }, {
29         'url': 'http://www.cbs.com/shows/liveonletterman/artist/221752/st-vincent/',
30         'info_dict': {
31             'id': 'WWF_5KqY3PK1',
32             'display_id': 'st-vincent',
33             'ext': 'flv',
34             'title': 'Live on Letterman - St. Vincent',
35             'description': 'Live On Letterman: St. Vincent in concert from New York\'s Ed Sullivan Theater on Tuesday, July 16, 2014.',
36             'duration': 3221,
37         },
38         'params': {
39             # rtmp download
40             'skip_download': True,
41         },
42         '_skip': 'Blocked outside the US',
43     }, {
44         'url': 'http://colbertlateshow.com/video/8GmB0oY0McANFvp2aEffk9jZZZ2YyXxy/the-colbeard/',
45         'only_matching': True,
46     }, {
47         'url': 'http://www.colbertlateshow.com/podcasts/dYSwjqPs_X1tvbV_P2FcPWRa_qT6akTC/in-the-bad-room-with-stephen/',
48         'only_matching': True,
49     }]
50
51     def _real_extract(self, url):
52         display_id = self._match_id(url)
53         request = sanitized_Request(url)
54         # Android UA is served with higher quality (720p) streams (see
55         # https://github.com/rg3/youtube-dl/issues/7490)
56         request.add_header('User-Agent', 'Mozilla/5.0 (Linux; Android 4.4; Nexus 5)')
57         webpage = self._download_webpage(request, display_id)
58         real_id = self._search_regex(
59             [r"video\.settings\.pid\s*=\s*'([^']+)';", r"cbsplayer\.pid\s*=\s*'([^']+)';"],
60             webpage, 'real video ID')
61         return {
62             '_type': 'url_transparent',
63             'ie_key': 'ThePlatform',
64             'url': smuggle_url(
65                 'http://link.theplatform.com/s/dJ5BDC/%s?mbr=true&manifest=m3u' % real_id,
66                 {'force_smil_url': True}),
67             'display_id': display_id,
68         }