2016-02-12 01:10:32 +08:00
# coding: utf-8
from __future__ import unicode_literals
import re
from . common import InfoExtractor
2016-07-26 23:58:50 +08:00
from . . compat import compat_str
2016-05-20 13:53:14 +08:00
from . . utils import (
js_to_json ,
smuggle_url ,
2016-07-26 23:58:50 +08:00
try_get ,
2016-05-20 13:53:14 +08:00
)
2016-02-12 01:10:32 +08:00
class CBCIE ( InfoExtractor ) :
2016-05-20 18:39:54 +08:00
_VALID_URL = r ' https?://(?:www \ .)?cbc \ .ca/(?!player/)(?:[^/]+/)+(?P<id>[^/?#]+) '
2016-02-12 01:10:32 +08:00
_TESTS = [ {
# with mediaId
' url ' : ' http://www.cbc.ca/22minutes/videos/clips-season-23/don-cherry-play-offs ' ,
2016-05-20 13:53:14 +08:00
' md5 ' : ' 97e24d09672fc4cf56256d6faa6c25bc ' ,
2016-02-12 01:10:32 +08:00
' info_dict ' : {
' id ' : ' 2682904050 ' ,
2016-05-20 13:53:14 +08:00
' ext ' : ' mp4 ' ,
2016-02-12 01:10:32 +08:00
' title ' : ' Don Cherry – All-Stars ' ,
' description ' : ' Don Cherry has a bee in his bonnet about AHL player John Scott because that guy’ s got heart. ' ,
2016-05-20 13:53:14 +08:00
' timestamp ' : 1454463000 ,
2016-02-12 01:10:32 +08:00
' upload_date ' : ' 20160203 ' ,
2016-05-20 13:53:14 +08:00
' uploader ' : ' CBCC-NEW ' ,
2016-02-12 01:10:32 +08:00
} ,
2016-07-16 00:02:26 +08:00
' skip ' : ' Geo-restricted to Canada ' ,
2016-02-12 01:10:32 +08:00
} , {
2016-07-26 23:58:50 +08:00
# with clipId, feed available via tpfeed.cbc.ca and feed.theplatform.com
' url ' : ' http://www.cbc.ca/22minutes/videos/22-minutes-update/22-minutes-update-episode-4 ' ,
' md5 ' : ' 162adfa070274b144f4fdc3c3b8207db ' ,
' info_dict ' : {
' id ' : ' 2414435309 ' ,
' ext ' : ' mp4 ' ,
' title ' : ' 22 Minutes Update: What Not To Wear Quebec ' ,
' description ' : " This week ' s latest Canadian top political story is What Not To Wear Quebec. " ,
' upload_date ' : ' 20131025 ' ,
' uploader ' : ' CBCC-NEW ' ,
' timestamp ' : 1382717907 ,
} ,
} , {
# with clipId, feed only available via tpfeed.cbc.ca
2016-02-12 01:10:32 +08:00
' url ' : ' http://www.cbc.ca/archives/entry/1978-robin-williams-freestyles-on-90-minutes-live ' ,
2016-05-20 23:20:05 +08:00
' md5 ' : ' 0274a90b51a9b4971fe005c63f592f12 ' ,
2016-02-12 01:10:32 +08:00
' info_dict ' : {
' id ' : ' 2487345465 ' ,
2016-05-20 13:53:14 +08:00
' ext ' : ' mp4 ' ,
2016-02-12 01:10:32 +08:00
' title ' : ' Robin Williams freestyles on 90 Minutes Live ' ,
' description ' : ' Wacky American comedian Robin Williams shows off his infamous " freestyle " comedic talents while being interviewed on CBC \' s 90 Minutes Live. ' ,
2016-05-20 13:53:14 +08:00
' upload_date ' : ' 19780210 ' ,
2016-04-24 20:44:52 +08:00
' uploader ' : ' CBCC-NEW ' ,
2016-05-20 13:53:14 +08:00
' timestamp ' : 255977160 ,
2016-02-12 01:10:32 +08:00
} ,
} , {
# multiple iframes
' url ' : ' http://www.cbc.ca/natureofthings/blog/birds-eye-view-from-vancouvers-burrard-street-bridge-how-we-got-the-shot ' ,
' playlist ' : [ {
2016-05-20 13:53:14 +08:00
' md5 ' : ' 377572d0b49c4ce0c9ad77470e0b96b4 ' ,
2016-02-12 01:10:32 +08:00
' info_dict ' : {
' id ' : ' 2680832926 ' ,
2016-05-20 13:53:14 +08:00
' ext ' : ' mp4 ' ,
2016-02-12 01:10:32 +08:00
' title ' : ' An Eagle \' s-Eye View Off Burrard Bridge ' ,
' description ' : ' Hercules the eagle flies from Vancouver \' s Burrard Bridge down to a nearby park with a mini-camera strapped to his back. ' ,
2016-05-20 13:53:14 +08:00
' upload_date ' : ' 20160201 ' ,
' timestamp ' : 1454342820 ,
' uploader ' : ' CBCC-NEW ' ,
2016-02-12 01:10:32 +08:00
} ,
} , {
2016-05-20 13:53:14 +08:00
' md5 ' : ' 415a0e3f586113894174dfb31aa5bb1a ' ,
2016-02-12 01:10:32 +08:00
' info_dict ' : {
' id ' : ' 2658915080 ' ,
2016-05-20 13:53:14 +08:00
' ext ' : ' mp4 ' ,
2016-02-12 01:10:32 +08:00
' title ' : ' Fly like an eagle! ' ,
' description ' : ' Eagle equipped with a mini camera flies from the world \' s tallest tower ' ,
2016-05-20 13:53:14 +08:00
' upload_date ' : ' 20150315 ' ,
' timestamp ' : 1426443984 ,
' uploader ' : ' CBCC-NEW ' ,
2016-02-12 01:10:32 +08:00
} ,
} ] ,
2016-07-16 00:02:26 +08:00
' skip ' : ' Geo-restricted to Canada ' ,
2016-02-12 01:10:32 +08:00
} ]
@classmethod
def suitable ( cls , url ) :
return False if CBCPlayerIE . suitable ( url ) else super ( CBCIE , cls ) . suitable ( url )
def _real_extract ( self , url ) :
display_id = self . _match_id ( url )
webpage = self . _download_webpage ( url , display_id )
player_init = self . _search_regex (
r ' CBC \ .APP \ .Caffeine \ .initInstance \ (( { .+?}) \ ); ' , webpage , ' player init ' ,
default = None )
if player_init :
player_info = self . _parse_json ( player_init , display_id , js_to_json )
media_id = player_info . get ( ' mediaId ' )
if not media_id :
clip_id = player_info [ ' clipId ' ]
2016-07-26 23:58:50 +08:00
feed = self . _download_json (
2016-07-27 00:08:08 +08:00
' http://tpfeed.cbc.ca/f/ExhSPC/vms_5akSXx4Ng_Zn?byCustomValue= { :mpsReleases} { %s } ' % clip_id ,
2016-07-26 23:58:50 +08:00
clip_id , fatal = False )
if feed :
media_id = try_get ( feed , lambda x : x [ ' entries ' ] [ 0 ] [ ' guid ' ] , compat_str )
if not media_id :
media_id = self . _download_json (
' http://feed.theplatform.com/f/h9dtGB/punlNGjMlc1F?fields=id&byContent=byReleases % 3DbyId % 253D ' + clip_id ,
clip_id ) [ ' entries ' ] [ 0 ] [ ' id ' ] . split ( ' / ' ) [ - 1 ]
2016-02-12 01:10:32 +08:00
return self . url_result ( ' cbcplayer: %s ' % media_id , ' CBCPlayer ' , media_id )
else :
entries = [ self . url_result ( ' cbcplayer: %s ' % media_id , ' CBCPlayer ' , media_id ) for media_id in re . findall ( r ' <iframe[^>]+src= " [^ " ]+?mediaId=( \ d+) " ' , webpage ) ]
return self . playlist_result ( entries )
class CBCPlayerIE ( InfoExtractor ) :
_VALID_URL = r ' (?:cbcplayer:|https?://(?:www \ .)?cbc \ .ca/(?:player/play/|i/caffeine/syndicate/ \ ?mediaId=))(?P<id> \ d+) '
2016-05-20 19:04:50 +08:00
_TESTS = [ {
2016-02-12 01:10:32 +08:00
' url ' : ' http://www.cbc.ca/player/play/2683190193 ' ,
2016-05-20 23:20:05 +08:00
' md5 ' : ' 64d25f841ddf4ddb28a235338af32e2c ' ,
2016-02-12 01:10:32 +08:00
' info_dict ' : {
' id ' : ' 2683190193 ' ,
2016-05-20 13:53:14 +08:00
' ext ' : ' mp4 ' ,
2016-02-12 01:10:32 +08:00
' title ' : ' Gerry Runs a Sweat Shop ' ,
' description ' : ' md5:b457e1c01e8ff408d9d801c1c2cd29b0 ' ,
2016-05-20 13:53:14 +08:00
' timestamp ' : 1455071400 ,
2016-02-12 01:10:32 +08:00
' upload_date ' : ' 20160210 ' ,
2016-05-20 13:53:14 +08:00
' uploader ' : ' CBCC-NEW ' ,
2016-02-12 01:10:32 +08:00
} ,
2016-07-16 00:02:26 +08:00
' skip ' : ' Geo-restricted to Canada ' ,
2016-05-20 19:04:50 +08:00
} , {
# Redirected from http://www.cbc.ca/player/AudioMobile/All%20in%20a%20Weekend%20Montreal/ID/2657632011/
' url ' : ' http://www.cbc.ca/player/play/2657631896 ' ,
' md5 ' : ' e5e708c34ae6fca156aafe17c43e8b75 ' ,
' info_dict ' : {
' id ' : ' 2657631896 ' ,
' ext ' : ' mp3 ' ,
' t itle ' : ' CBC Montreal is organizing its first ever community hackathon! ' ,
' 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. ' ,
' timestamp ' : 1425704400 ,
' upload_date ' : ' 20150307 ' ,
' uploader ' : ' CBCC-NEW ' ,
} ,
2016-05-20 23:20:05 +08:00
} , {
# available only when we add `formats=MPEG4,FLV,MP3` to theplatform url
' url ' : ' http://www.cbc.ca/player/play/2164402062 ' ,
' md5 ' : ' 17a61eb813539abea40618d6323a7f82 ' ,
' info_dict ' : {
' id ' : ' 2164402062 ' ,
' ext ' : ' flv ' ,
' title ' : ' Cancer survivor four times over ' ,
' description ' : ' Tim Mayer has beaten three different forms of cancer four times in five years. ' ,
' timestamp ' : 1320410746 ,
' upload_date ' : ' 20111104 ' ,
' uploader ' : ' CBCC-NEW ' ,
} ,
2016-05-20 19:04:50 +08:00
} ]
2016-02-12 01:10:32 +08:00
def _real_extract ( self , url ) :
video_id = self . _match_id ( url )
2016-05-20 13:53:14 +08:00
return {
' _type ' : ' url_transparent ' ,
' ie_key ' : ' ThePlatform ' ,
' url ' : smuggle_url (
2016-05-20 23:20:05 +08:00
' http://link.theplatform.com/s/ExhSPC/media/guid/2655402169/ %s ?mbr=true&formats=MPEG4,FLV,MP3 ' % video_id , {
2016-05-20 13:53:14 +08:00
' force_smil_url ' : True
} ) ,
' id ' : video_id ,
}