]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/cbc.py
2 from __future__
import unicode_literals
6 from . common
import InfoExtractor
7 from .. compat
import compat_str
23 class CBCIE ( InfoExtractor
):
25 _VALID_URL
= r
'https?://(?:www\.)?cbc\.ca/(?!player/)(?:[^/]+/)+(?P<id>[^/?#]+)'
28 'url' : 'http://www.cbc.ca/22minutes/videos/clips-season-23/don-cherry-play-offs' ,
29 'md5' : '97e24d09672fc4cf56256d6faa6c25bc' ,
33 'title' : 'Don Cherry – All-Stars' ,
34 'description' : 'Don Cherry has a bee in his bonnet about AHL player John Scott because that guy’s got heart.' ,
35 'timestamp' : 1454463000 ,
36 'upload_date' : '20160203' ,
37 'uploader' : 'CBCC-NEW' ,
39 'skip' : 'Geo-restricted to Canada' ,
41 # with clipId, feed available via tpfeed.cbc.ca and feed.theplatform.com
42 'url' : 'http://www.cbc.ca/22minutes/videos/22-minutes-update/22-minutes-update-episode-4' ,
43 'md5' : '162adfa070274b144f4fdc3c3b8207db' ,
47 'title' : '22 Minutes Update: What Not To Wear Quebec' ,
48 'description' : "This week's latest Canadian top political story is What Not To Wear Quebec." ,
49 'upload_date' : '20131025' ,
50 'uploader' : 'CBCC-NEW' ,
51 'timestamp' : 1382717907 ,
54 # with clipId, feed only available via tpfeed.cbc.ca
55 'url' : 'http://www.cbc.ca/archives/entry/1978-robin-williams-freestyles-on-90-minutes-live' ,
56 'md5' : '0274a90b51a9b4971fe005c63f592f12' ,
60 'title' : 'Robin Williams freestyles on 90 Minutes Live' ,
61 'description' : 'Wacky American comedian Robin Williams shows off his infamous "freestyle" comedic talents while being interviewed on CBC \' s 90 Minutes Live.' ,
62 'upload_date' : '19780210' ,
63 'uploader' : 'CBCC-NEW' ,
64 'timestamp' : 255977160 ,
68 'url' : 'http://www.cbc.ca/natureofthings/blog/birds-eye-view-from-vancouvers-burrard-street-bridge-how-we-got-the-shot' ,
70 'md5' : '377572d0b49c4ce0c9ad77470e0b96b4' ,
74 'title' : 'An Eagle \' s-Eye View Off Burrard Bridge' ,
75 'description' : 'Hercules the eagle flies from Vancouver \' s Burrard Bridge down to a nearby park with a mini-camera strapped to his back.' ,
76 'upload_date' : '20160201' ,
77 'timestamp' : 1454342820 ,
78 'uploader' : 'CBCC-NEW' ,
81 'md5' : '415a0e3f586113894174dfb31aa5bb1a' ,
85 'title' : 'Fly like an eagle!' ,
86 'description' : 'Eagle equipped with a mini camera flies from the world \' s tallest tower' ,
87 'upload_date' : '20150315' ,
88 'timestamp' : 1426443984 ,
89 'uploader' : 'CBCC-NEW' ,
92 'skip' : 'Geo-restricted to Canada' ,
94 # multiple CBC.APP.Caffeine.initInstance(...)
95 'url' : 'http://www.cbc.ca/news/canada/calgary/dog-indoor-exercise-winter-1.3928238' ,
97 'title' : 'Keep Rover active during the deep freeze with doggie pushups and other fun indoor tasks' ,
98 'id' : 'dog-indoor-exercise-winter-1.3928238' ,
100 'playlist_mincount' : 6 ,
104 def suitable ( cls
, url
):
105 return False if CBCPlayerIE
. suitable ( url
) else super ( CBCIE
, cls
). suitable ( url
)
107 def _extract_player_init ( self
, player_init
, display_id
):
108 player_info
= self
._ parse
_ json
( player_init
, display_id
, js_to_json
)
109 media_id
= player_info
. get ( 'mediaId' )
111 clip_id
= player_info
[ 'clipId' ]
112 feed
= self
._ download
_ json
(
113 'http://tpfeed.cbc.ca/f/ExhSPC/vms_5akSXx4Ng_Zn?byCustomValue= {:mpsReleases} { %s }' % clip_id
,
114 clip_id
, fatal
= False )
116 media_id
= try_get ( feed
, lambda x
: x
[ 'entries' ][ 0 ][ 'guid' ], compat_str
)
118 media_id
= self
._ download
_ json
(
119 'http://feed.theplatform.com/f/h9dtGB/punlNGjMlc1F?fields=id&byContent=byReleases%3DbyId%253D' + clip_id
,
120 clip_id
)[ 'entries' ][ 0 ][ 'id' ]. split ( '/' )[- 1 ]
121 return self
. url_result ( 'cbcplayer: %s ' % media_id
, 'CBCPlayer' , media_id
)
123 def _real_extract ( self
, url
):
124 display_id
= self
._ match
_ id
( url
)
125 webpage
= self
._ download
_ webpage
( url
, display_id
)
127 self
._ extract
_ player
_ init
( player_init
, display_id
)
128 for player_init
in re
. findall ( r
'CBC\.APP\.Caffeine\.initInstance\(({.+?})\);' , webpage
)]
130 self
. url_result ( 'cbcplayer: %s ' % media_id
, 'CBCPlayer' , media_id
)
131 for media_id
in re
. findall ( r
'<iframe[^>]+src="[^"]+?mediaId=(\d+)"' , webpage
)])
132 return self
. playlist_result (
134 self
._ og
_ search
_ title
( webpage
, fatal
= False ),
135 self
._ og
_ search
_ description
( webpage
))
138 class CBCPlayerIE ( InfoExtractor
):
139 IE_NAME
= 'cbc.ca:player'
140 _VALID_URL
= r
'(?:cbcplayer:|https?://(?:www\.)?cbc\.ca/(?:player/play/|i/caffeine/syndicate/\?mediaId=))(?P<id>\d+)'
142 'url' : 'http://www.cbc.ca/player/play/2683190193' ,
143 'md5' : '64d25f841ddf4ddb28a235338af32e2c' ,
147 'title' : 'Gerry Runs a Sweat Shop' ,
148 'description' : 'md5:b457e1c01e8ff408d9d801c1c2cd29b0' ,
149 'timestamp' : 1455071400 ,
150 'upload_date' : '20160210' ,
151 'uploader' : 'CBCC-NEW' ,
153 'skip' : 'Geo-restricted to Canada' ,
155 # Redirected from http://www.cbc.ca/player/AudioMobile/All%20in%20a%20Weekend%20Montreal/ID/2657632011/
156 'url' : 'http://www.cbc.ca/player/play/2657631896' ,
157 'md5' : 'e5e708c34ae6fca156aafe17c43e8b75' ,
161 'title' : 'CBC Montreal is organizing its first ever community hackathon!' ,
162 '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.' ,
163 'timestamp' : 1425704400 ,
164 'upload_date' : '20150307' ,
165 'uploader' : 'CBCC-NEW' ,
168 # available only when we add `formats=MPEG4,FLV,MP3` to theplatform url
169 'url' : 'http://www.cbc.ca/player/play/2164402062' ,
170 'md5' : '17a61eb813539abea40618d6323a7f82' ,
174 'title' : 'Cancer survivor four times over' ,
175 'description' : 'Tim Mayer has beaten three different forms of cancer four times in five years.' ,
176 'timestamp' : 1320410746 ,
177 'upload_date' : '20111104' ,
178 'uploader' : 'CBCC-NEW' ,
182 def _real_extract ( self
, url
):
183 video_id
= self
._ match
_ id
( url
)
185 '_type' : 'url_transparent' ,
186 'ie_key' : 'ThePlatform' ,
188 'http://link.theplatform.com/s/ExhSPC/media/guid/2655402169/ %s ?mbr=true&formats=MPEG4,FLV,MP3' % video_id
, {
189 'force_smil_url' : True
195 class CBCWatchBaseIE ( InfoExtractor
):
198 _API_BASE_URL
= 'https://api-cbc.cloud.clearleap.com/cloffice/client/'
200 'media' : 'http://search.yahoo.com/mrss/' ,
201 'clearleap' : 'http://www.clearleap.com/namespace/clearleap/1.0/' ,
204 def _call_api ( self
, path
, video_id
):
205 url
= path
if path
. startswith ( 'http' ) else self
._ API
_ BASE
_U RL
+ path
206 result
= self
._ download
_ xml
( url
, video_id
, headers
={
207 'X-Clearleap-DeviceId' : self
._ device
_ id
,
208 'X-Clearleap-DeviceToken' : self
._ device
_ token
,
210 error_message
= xpath_text ( result
, 'userMessage' ) or xpath_text ( result
, 'systemMessage' )
212 raise ExtractorError ( ' %s said: %s ' % ( self
. IE_NAME
, error_message
))
215 def _real_initialize ( self
):
216 if not self
._ device
_ id
or not self
._ device
_ token
:
217 device
= self
._ downloader
. cache
. load ( 'cbcwatch' , 'device' ) or {}
218 self
._ device
_ id
, self
._ device
_ token
= device
. get ( 'id' ), device
. get ( 'token' )
219 if not self
._ device
_ id
or not self
._ device
_ token
:
220 result
= self
._ download
_ xml
(
221 self
._ API
_ BASE
_U RL
+ 'device/register' ,
222 None , data
= b
'<device><type>web</type></device>' )
223 self
._ device
_ id
= xpath_text ( result
, 'deviceId' , fatal
= True )
224 self
._ device
_ token
= xpath_text ( result
, 'deviceToken' , fatal
= True )
225 self
._ downloader
. cache
. store (
226 'cbcwatch' , 'device' , {
227 'id' : self
._ device
_ id
,
228 'token' : self
._ device
_ token
,
231 def _parse_rss_feed ( self
, rss
):
232 channel
= xpath_element ( rss
, 'channel' , fatal
= True )
235 return xpath_with_ns ( path
, self
._ NS
_ MAP
)
238 for item
in channel
. findall ( 'item' ):
239 guid
= xpath_text ( item
, 'guid' , fatal
= True )
240 title
= xpath_text ( item
, 'title' , fatal
= True )
242 media_group
= xpath_element ( item
, _add_ns ( 'media:group' ), fatal
= True )
243 content
= xpath_element ( media_group
, _add_ns ( 'media:content' ), fatal
= True )
244 content_url
= content
. attrib
[ 'url' ]
247 for thumbnail
in media_group
. findall ( _add_ns ( 'media:thumbnail' )):
248 thumbnail_url
= thumbnail
. get ( 'url' )
249 if not thumbnail_url
:
252 'id' : thumbnail
. get ( 'profile' ),
253 'url' : thumbnail_url
,
254 'width' : int_or_none ( thumbnail
. get ( 'width' )),
255 'height' : int_or_none ( thumbnail
. get ( 'height' )),
259 release_date
= find_xpath_attr (
260 item
, _add_ns ( 'media:credit' ), 'role' , 'releaseDate' )
261 if release_date
is not None :
262 timestamp
= parse_iso8601 ( release_date
. text
)
265 '_type' : 'url_transparent' ,
269 'description' : xpath_text ( item
, 'description' ),
270 'timestamp' : timestamp
,
271 'duration' : int_or_none ( content
. get ( 'duration' )),
272 'age_limit' : parse_age_limit ( xpath_text ( item
, _add_ns ( 'media:rating' ))),
273 'episode' : xpath_text ( item
, _add_ns ( 'clearleap:episode' )),
274 'episode_number' : int_or_none ( xpath_text ( item
, _add_ns ( 'clearleap:episodeInSeason' ))),
275 'series' : xpath_text ( item
, _add_ns ( 'clearleap:series' )),
276 'season_number' : int_or_none ( xpath_text ( item
, _add_ns ( 'clearleap:season' ))),
277 'thumbnails' : thumbnails
,
278 'ie_key' : 'CBCWatchVideo' ,
281 return self
. playlist_result (
282 entries
, xpath_text ( channel
, 'guid' ),
283 xpath_text ( channel
, 'title' ),
284 xpath_text ( channel
, 'description' ))
287 class CBCWatchVideoIE ( CBCWatchBaseIE
):
288 IE_NAME
= 'cbc.ca:watch:video'
289 _VALID_URL
= r
'https?://api-cbc\.cloud\.clearleap\.com/cloffice/client/web/play/?\?.*?\bcontentId=(?P<id>[\da-f] {8} -[\da-f] {4} -[\da-f] {4} -[\da-f] {4} -[\da-f] {12} )'
291 def _real_extract ( self
, url
):
292 video_id
= self
._ match
_ id
( url
)
293 result
= self
._ call
_ api
( url
, video_id
)
295 m3u8_url
= xpath_text ( result
, 'url' , fatal
= True )
296 formats
= self
._ extract
_ m
3u8_ formats
( re
. sub ( r
'/([^/]+)/[^/?]+\.m3u8' , r
'/\1/\1.m3u8' , m3u8_url
), video_id
, 'mp4' , fatal
= False )
298 formats
= self
._ extract
_ m
3u8_ formats
( m3u8_url
, video_id
, 'mp4' )
300 format_id
= f
. get ( 'format_id' )
301 if format_id
. startswith ( 'AAC' ):
303 elif format_id
. startswith ( 'AC3' ):
305 self
._ sort
_ formats
( formats
)
313 rss
= xpath_element ( result
, 'rss' )
315 info
. update ( self
._ parse
_ rss
_ feed
( rss
)[ 'entries' ][ 0 ])
322 class CBCWatchIE ( CBCWatchBaseIE
):
323 IE_NAME
= 'cbc.ca:watch'
324 _VALID_URL
= r
'https?://watch\.cbc\.ca/(?:[^/]+/)+(?P<id>[0-9a-f-]+)'
326 'url' : 'http://watch.cbc.ca/doc-zone/season-6/customer-disservice/38e815a-009e3ab12e4' ,
328 'id' : '38e815a-009e3ab12e4' ,
330 'title' : 'Customer (Dis)Service' ,
331 'description' : 'md5:8bdd6913a0fe03d4b2a17ebe169c7c87' ,
332 'upload_date' : '20160219' ,
333 'timestamp' : 1455840000 ,
337 'skip_download' : True ,
338 'format' : 'bestvideo' ,
340 'skip' : 'Geo-restricted to Canada' ,
342 'url' : 'http://watch.cbc.ca/arthur/all/1ed4b385-cd84-49cf-95f0-80f004680057' ,
344 'id' : '1ed4b385-cd84-49cf-95f0-80f004680057' ,
346 'description' : 'Arthur, the sweetest 8-year-old aardvark, and his pals solve all kinds of problems with humour, kindness and teamwork.' ,
348 'playlist_mincount' : 30 ,
349 'skip' : 'Geo-restricted to Canada' ,
352 def _real_extract ( self
, url
):
353 video_id
= self
._ match
_ id
( url
)
354 rss
= self
._ call
_ api
( 'web/browse/' + video_id
, video_id
)
355 return self
._ parse
_ rss
_ feed
( rss
)