[cbc] Skip geo-restricted test case
[youtube-dl] / youtube_dl / extractor / cbc.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8     js_to_json,
9     smuggle_url,
10 )
11
12
13 class CBCIE(InfoExtractor):
14     _VALID_URL = r'https?://(?:www\.)?cbc\.ca/(?!player/)(?:[^/]+/)+(?P<id>[^/?#]+)'
15     _TESTS = [{
16         # with mediaId
17         'url': 'http://www.cbc.ca/22minutes/videos/clips-season-23/don-cherry-play-offs',
18         'md5': '97e24d09672fc4cf56256d6faa6c25bc',
19         'info_dict': {
20             'id': '2682904050',
21             'ext': 'mp4',
22             'title': 'Don Cherry – All-Stars',
23             'description': 'Don Cherry has a bee in his bonnet about AHL player John Scott because that guy’s got heart.',
24             'timestamp': 1454463000,
25             'upload_date': '20160203',
26             'uploader': 'CBCC-NEW',
27         },
28         'skip': 'Geo-restricted to Canada',
29     }, {
30         # with clipId
31         'url': 'http://www.cbc.ca/archives/entry/1978-robin-williams-freestyles-on-90-minutes-live',
32         'md5': '0274a90b51a9b4971fe005c63f592f12',
33         'info_dict': {
34             'id': '2487345465',
35             'ext': 'mp4',
36             'title': 'Robin Williams freestyles on 90 Minutes Live',
37             'description': 'Wacky American comedian Robin Williams shows off his infamous "freestyle" comedic talents while being interviewed on CBC\'s 90 Minutes Live.',
38             'upload_date': '19780210',
39             'uploader': 'CBCC-NEW',
40             'timestamp': 255977160,
41         },
42     }, {
43         # multiple iframes
44         'url': 'http://www.cbc.ca/natureofthings/blog/birds-eye-view-from-vancouvers-burrard-street-bridge-how-we-got-the-shot',
45         'playlist': [{
46             'md5': '377572d0b49c4ce0c9ad77470e0b96b4',
47             'info_dict': {
48                 'id': '2680832926',
49                 'ext': 'mp4',
50                 'title': 'An Eagle\'s-Eye View Off Burrard Bridge',
51                 'description': 'Hercules the eagle flies from Vancouver\'s Burrard Bridge down to a nearby park with a mini-camera strapped to his back.',
52                 'upload_date': '20160201',
53                 'timestamp': 1454342820,
54                 'uploader': 'CBCC-NEW',
55             },
56         }, {
57             'md5': '415a0e3f586113894174dfb31aa5bb1a',
58             'info_dict': {
59                 'id': '2658915080',
60                 'ext': 'mp4',
61                 'title': 'Fly like an eagle!',
62                 'description': 'Eagle equipped with a mini camera flies from the world\'s tallest tower',
63                 'upload_date': '20150315',
64                 'timestamp': 1426443984,
65                 'uploader': 'CBCC-NEW',
66             },
67         }],
68         'skip': 'Geo-restricted to Canada',
69     }]
70
71     @classmethod
72     def suitable(cls, url):
73         return False if CBCPlayerIE.suitable(url) else super(CBCIE, cls).suitable(url)
74
75     def _real_extract(self, url):
76         display_id = self._match_id(url)
77         webpage = self._download_webpage(url, display_id)
78         player_init = self._search_regex(
79             r'CBC\.APP\.Caffeine\.initInstance\(({.+?})\);', webpage, 'player init',
80             default=None)
81         if player_init:
82             player_info = self._parse_json(player_init, display_id, js_to_json)
83             media_id = player_info.get('mediaId')
84             if not media_id:
85                 clip_id = player_info['clipId']
86                 media_id = self._download_json(
87                     'http://feed.theplatform.com/f/h9dtGB/punlNGjMlc1F?fields=id&byContent=byReleases%3DbyId%253D' + clip_id,
88                     clip_id)['entries'][0]['id'].split('/')[-1]
89             return self.url_result('cbcplayer:%s' % media_id, 'CBCPlayer', media_id)
90         else:
91             entries = [self.url_result('cbcplayer:%s' % media_id, 'CBCPlayer', media_id) for media_id in re.findall(r'<iframe[^>]+src="[^"]+?mediaId=(\d+)"', webpage)]
92             return self.playlist_result(entries)
93
94
95 class CBCPlayerIE(InfoExtractor):
96     _VALID_URL = r'(?:cbcplayer:|https?://(?:www\.)?cbc\.ca/(?:player/play/|i/caffeine/syndicate/\?mediaId=))(?P<id>\d+)'
97     _TESTS = [{
98         'url': 'http://www.cbc.ca/player/play/2683190193',
99         'md5': '64d25f841ddf4ddb28a235338af32e2c',
100         'info_dict': {
101             'id': '2683190193',
102             'ext': 'mp4',
103             'title': 'Gerry Runs a Sweat Shop',
104             'description': 'md5:b457e1c01e8ff408d9d801c1c2cd29b0',
105             'timestamp': 1455071400,
106             'upload_date': '20160210',
107             'uploader': 'CBCC-NEW',
108         },
109         'skip': 'Geo-restricted to Canada',
110     }, {
111         # Redirected from http://www.cbc.ca/player/AudioMobile/All%20in%20a%20Weekend%20Montreal/ID/2657632011/
112         'url': 'http://www.cbc.ca/player/play/2657631896',
113         'md5': 'e5e708c34ae6fca156aafe17c43e8b75',
114         'info_dict': {
115             'id': '2657631896',
116             'ext': 'mp3',
117             'title': 'CBC Montreal is organizing its first ever community hackathon!',
118             'description': 'The modern technology we tend to depend on so heavily, is never without it\'s share of hiccups and headaches. Next weekend - CBC Montreal will be getting members of the public for its first Hackathon.',
119             'timestamp': 1425704400,
120             'upload_date': '20150307',
121             'uploader': 'CBCC-NEW',
122         },
123     }, {
124         # available only when we add `formats=MPEG4,FLV,MP3` to theplatform url
125         'url': 'http://www.cbc.ca/player/play/2164402062',
126         'md5': '17a61eb813539abea40618d6323a7f82',
127         'info_dict': {
128             'id': '2164402062',
129             'ext': 'flv',
130             'title': 'Cancer survivor four times over',
131             'description': 'Tim Mayer has beaten three different forms of cancer four times in five years.',
132             'timestamp': 1320410746,
133             'upload_date': '20111104',
134             'uploader': 'CBCC-NEW',
135         },
136     }]
137
138     def _real_extract(self, url):
139         video_id = self._match_id(url)
140         return {
141             '_type': 'url_transparent',
142             'ie_key': 'ThePlatform',
143             'url': smuggle_url(
144                 'http://link.theplatform.com/s/ExhSPC/media/guid/2655402169/%s?mbr=true&formats=MPEG4,FLV,MP3' % video_id, {
145                     'force_smil_url': True
146                 }),
147             'id': video_id,
148         }