]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/brightcove.py
2b7ddcae8d866bf2b3ff37a70d62a860a74a18c5
4 import xml
. etree
. ElementTree
6 from . adobepass
import AdobePassIE
7 from . common
import InfoExtractor
9 compat_etree_fromstring
,
38 class BrightcoveLegacyIE ( InfoExtractor
):
39 IE_NAME
= 'brightcove:legacy'
40 _VALID_URL
= r
'(?:https?://.*brightcove\.com/(services|viewer).*?\?|brightcove:)(?P<query>.*)'
44 # From http://www.8tv.cat/8aldia/videos/xavier-sala-i-martin-aquesta-tarda-a-8-al-dia/
45 'url' : 'http://c.brightcove.com/services/viewer/htmlFederated?playerID=1654948606001&flashID=myExperience&%40videoPlayer=2371591881001' ,
46 'md5' : '5423e113865d26e40624dce2e4b45d95' ,
47 'note' : 'Test Brightcove downloads and detection in GenericIE' ,
49 'id' : '2371591881001' ,
51 'title' : 'Xavier Sala i Martín: “Un banc que no presta és un banc zombi que no serveix per a res”' ,
53 'description' : 'md5:a950cc4285c43e44d763d036710cd9cd' ,
54 'timestamp' : 1368213670 ,
55 'upload_date' : '20130510' ,
56 'uploader_id' : '1589608506001' ,
58 'skip' : 'The player has been deactivated by the content owner' ,
61 # From http://medianetwork.oracle.com/video/player/1785452137001
62 'url' : 'http://c.brightcove.com/services/viewer/htmlFederated?playerID=1217746023001&flashID=myPlayer&%40videoPlayer=1785452137001' ,
64 'id' : '1785452137001' ,
66 'title' : 'JVMLS 2012: Arrays 2.0 - Opportunities and Challenges' ,
67 'description' : 'John Rose speaks at the JVM Language Summit, August 1, 2012.' ,
69 'timestamp' : 1344975024 ,
70 'upload_date' : '20120814' ,
71 'uploader_id' : '1460825906' ,
73 'skip' : 'video not playable' ,
76 # From http://mashable.com/2013/10/26/thermoelectric-bracelet-lets-you-control-your-body-temperature/
77 'url' : 'http://c.brightcove.com/services/viewer/federated_f9?&playerID=1265504713001&publisherID=AQ%7E%7E%2CAAABBzUwv1E%7E%2CxP-xFHVUstiMFlNYfvF4G9yFnNaqCw_9&videoID=2750934548001' ,
79 'id' : '2750934548001' ,
81 'title' : 'This Bracelet Acts as a Personal Thermostat' ,
82 'description' : 'md5:547b78c64f4112766ccf4e151c20b6a0' ,
83 # 'uploader': 'Mashable',
84 'timestamp' : 1382041798 ,
85 'upload_date' : '20131017' ,
86 'uploader_id' : '1130468786001' ,
90 # test that the default referer works
91 # from http://national.ballet.ca/interact/video/Lost_in_Motion_II/
92 'url' : 'http://link.brightcove.com/services/player/bcpid756015033001?bckey=AQ~~,AAAApYJi_Ck~,GxhXCegT1Dp39ilhXuxMJxasUhVNZiil&bctid=2878862109001' ,
94 'id' : '2878862109001' ,
96 'title' : 'Lost in Motion II' ,
97 'description' : 'md5:363109c02998fee92ec02211bd8000df' ,
98 'uploader' : 'National Ballet of Canada' ,
100 'skip' : 'Video gone' ,
103 # test flv videos served by akamaihd.net
104 # From http://www.redbull.com/en/bike/stories/1331655643987/replay-uci-dh-world-cup-2014-from-fort-william
105 'url' : 'http://c.brightcove.com/services/viewer/htmlFederated?%40videoPlayer=ref%3Aevent-stream-356&linkBaseURL=http%3A%2F%2Fwww.redbull.com%2Fen%2Fbike%2Fvideos%2F1331655630249%2Freplay-uci-fort-william-2014-dh&playerKey=AQ%7E%7E%2CAAAApYJ7UqE%7E%2Cxqr_zXk0I-zzNndy8NlHogrCb5QdyZRf&playerID=1398061561001#__youtubedl_smuggle=%7B%22Referer%22%3A+%22http%3A%2F%2Fwww.redbull.com%2Fen%2Fbike%2Fstories%2F1331655643987%2Freplay-uci-dh-world-cup-2014-from-fort-william%22%7D' ,
106 # The md5 checksum changes on each download
108 'id' : '3750436379001' ,
110 'title' : 'UCI MTB World Cup 2014: Fort William, UK - Downhill Finals' ,
111 'uploader' : 'RBTV Old (do not use)' ,
112 'description' : 'UCI MTB World Cup 2014: Fort William, UK - Downhill Finals' ,
113 'timestamp' : 1409122195 ,
114 'upload_date' : '20140827' ,
115 'uploader_id' : '710858724001' ,
117 'skip' : 'Video gone' ,
120 # playlist with 'videoList'
121 # from http://support.brightcove.com/en/video-cloud/docs/playlist-support-single-video-players
122 'url' : 'http://c.brightcove.com/services/viewer/htmlFederated?playerID=3550052898001&playerKey=AQ%7E%7E%2CAAABmA9XpXk%7E%2C-Kp7jNgisre1fG5OdqpAFUTcs0lP_ZoL' ,
125 'id' : '3550319591001' ,
127 'playlist_mincount' : 7 ,
128 'skip' : 'Unsupported URL' ,
131 # playlist with 'playlistTab' (https://github.com/ytdl-org/youtube-dl/issues/9965)
132 'url' : 'http://c.brightcove.com/services/json/experience/runtime/?command=get_programming_for_experience&playerKey=AQ%7E%7E,AAABXlLMdok%7E,NJ4EoMlZ4rZdx9eU1rkMVd8EaYPBBUlg' ,
134 'id' : '1522758701001' ,
135 'title' : 'Lesson 08' ,
137 'playlist_mincount' : 10 ,
138 'skip' : 'Unsupported URL' ,
141 # playerID inferred from bcpid
142 # from http://www.un.org/chinese/News/story.asp?NewsID=27724
143 'url' : 'https://link.brightcove.com/services/player/bcpid1722935254001/?bctid=5360463607001&autoStart=false&secureConnections=true&width=650&height=350' ,
144 'only_matching' : True , # Tested in GenericIE
149 # embedded brightcove video
150 # it also tests brightcove videos that need to set the 'Referer'
151 # in the http requests
152 'url' : 'http://www.bfmtv.com/video/bfmbusiness/cours-bourse/cours-bourse-l-analyse-technique-154522/' ,
154 'id' : '2765128793001' ,
156 'title' : 'Le cours de bourse : l’analyse technique' ,
157 'description' : 'md5:7e9ad046e968cb2d1114004aba466fd9' ,
158 'uploader' : 'BFM BUSINESS' ,
161 'skip_download' : True ,
163 'skip' : '404 Not Found' ,
165 # embedded with itemprop embedURL and video id spelled as `idVideo`
166 'url' : 'http://bfmbusiness.bfmtv.com/mediaplayer/chroniques/olivier-delamarche/' ,
168 'id' : '5255628253001' ,
170 'title' : 'md5:37c519b1128915607601e75a87995fc0' ,
171 'description' : 'md5:37f7f888b434bb8f8cc8dbd4f7a4cf26' ,
172 'uploader' : 'BFM BUSINESS' ,
173 'uploader_id' : '876450612001' ,
174 'timestamp' : 1482255315 ,
175 'upload_date' : '20161220' ,
178 'skip_download' : True ,
180 'skip' : 'Redirects, page gone' ,
182 # https://github.com/ytdl-org/youtube-dl/issues/2253
183 'url' : 'http://bcove.me/i6nfkrc3' ,
184 'md5' : '0ba9446db037002366bab3b3eb30c88c' ,
186 'id' : '3101154703001' ,
188 'title' : 'Still no power' ,
189 'uploader' : 'thestar.com' ,
190 'description' : 'Mississauga resident David Farmer is still out of power as a result of the ice storm a month ago. To keep the house warm, Farmer cuts wood from his property for a wood burning stove downstairs.' ,
192 'skip' : 'video gone' ,
194 # https://github.com/ytdl-org/youtube-dl/issues/3541
195 'url' : 'http://www.kijk.nl/sbs6/leermijvrouwenkennen/videos/jqMiXKAYan2S/aflevering-1' ,
197 'id' : '3866516442001' ,
199 'title' : 'Leer mij vrouwen kennen: Aflevering 1' ,
200 'description' : 'Leer mij vrouwen kennen: Aflevering 1' ,
201 'uploader' : 'SBS Broadcasting' ,
203 'skip' : 'Restricted to Netherlands, 404 Not Found' ,
205 'skip_download' : True , # m3u8 download
208 # Brightcove video in <iframe>
209 'url' : 'http://www.un.org/chinese/News/story.asp?NewsID=27724' ,
210 'md5' : '36d74ef5e37c8b4a2ce92880d208b968' ,
212 'id' : '5360463607001' ,
214 'title' : '叙利亚失明儿童在废墟上演唱《心跳》 呼吁获得正常童年生活' ,
215 'description' : '联合国儿童基金会中东和北非区域大使、作曲家扎德·迪拉尼(Zade Dirani)在3月15日叙利亚冲突爆发7周年纪念日之际发布了为叙利亚谱写的歌曲《心跳》(HEARTBEAT),为受到六年冲突影响的叙利亚儿童发出强烈呐喊,呼吁世界做出共同努力,使叙利亚儿童重新获得享有正常童年生活的权利。' ,
216 'uploader' : 'United Nations' ,
217 'uploader_id' : '1362235914001' ,
218 'timestamp' : 1489593889 ,
219 'upload_date' : '20170315' ,
221 'skip' : '404 Not Found' ,
223 # Brightcove with UUID in videoPlayer
224 'url' : 'http://www8.hp.com/cn/zh/home.html' ,
226 'id' : '5255815316001' ,
228 'title' : 'Sprocket Video - China' ,
229 'description' : 'Sprocket Video - China' ,
230 'uploader' : 'HP-Video Gallery' ,
231 'timestamp' : 1482263210 ,
232 'upload_date' : '20161220' ,
233 'uploader_id' : '1107601872001' ,
236 'skip_download' : True , # m3u8 download
238 'skip' : 'video rotates...weekly?' ,
240 # Multiple brightcove videos
241 # https://github.com/ytdl-org/youtube-dl/issues/2283
242 'url' : 'http://www.newyorker.com/online/blogs/newsdesk/2014/01/always-never-nuclear-command-and-control.html' ,
244 'id' : 'always-never' ,
245 'title' : 'Always / Never - The New Yorker' ,
249 'extract_flat' : False ,
250 'skip_download' : True ,
252 'skip' : 'Redirects, page gone' ,
254 # BrightcoveInPageEmbed embed
255 'url' : 'http://www.geekandsundry.com/tabletop-bonus-wils-final-thoughts-on-dread/' ,
257 'id' : '4238694884001' ,
259 'title' : 'Tabletop: Dread, Last Thoughts' ,
260 'description' : 'Tabletop: Dread, Last Thoughts' ,
263 'skip' : 'Redirects, page gone' ,
265 # Brightcove embed, with no valid 'renditions' but valid 'IOSRenditions'
266 # This video can't be played in browsers if Flash disabled and UA set to iPhone, which is actually a false alarm
267 'url' : 'https://dl.dropboxusercontent.com/u/29092637/interview.html' ,
269 'id' : '4785848093001' ,
271 'title' : 'The Cardinal Pell Interview' ,
272 'description' : 'Sky News Contributor Andrew Bolt interviews George Pell in Rome, following the Cardinal \' s evidence before the Royal Commission into Child Abuse. ' ,
273 'uploader' : 'GlobeCast Australia - GlobeStream' ,
274 'uploader_id' : '2733773828001' ,
275 'upload_date' : '20160304' ,
276 'timestamp' : 1457083087 ,
280 'skip_download' : True ,
282 'skip' : '404 Not Found' ,
284 # Brightcove embed with whitespace around attribute names
285 'url' : 'http://www.stack.com/video/3167554373001/learn-to-hit-open-three-pointers-with-damian-lillard-s-baseline-drift-drill' ,
287 'id' : '3167554373001' ,
289 'title' : "Learn to Hit Open Three-Pointers With Damian Lillard's Baseline Drift Drill" ,
290 'description' : 'md5:57bacb0e0f29349de4972bfda3191713' ,
291 'uploader_id' : '1079349493' ,
292 'upload_date' : '20140207' ,
293 'timestamp' : 1391810548 ,
296 'skip_download' : True ,
302 def _build_brightcove_url ( cls
, object_str
):
304 Build a Brightcove url from a xml string containing
305 <object class="BrightcoveExperience"> {params} </object>
308 # Fix up some stupid HTML, see https://github.com/ytdl-org/youtube-dl/issues/1553
309 object_str
= re
. sub ( r
'(<param(?:\s+[a-zA-Z0-9_]+="[^"]*")*)>' ,
310 lambda m
: m
. group ( 1 ) + '/>' , object_str
)
311 # Fix up some stupid XML, see https://github.com/ytdl-org/youtube-dl/issues/1608
312 object_str
= object_str
. replace ( '<--' , '<!--' )
313 # remove namespace to simplify extraction
314 object_str
= re
. sub ( r
'(<object[^>]*)(xmlns=".*?")' , r
'\1' , object_str
)
315 object_str
= fix_xml_ampersands ( object_str
)
318 object_doc
= compat_etree_fromstring ( object_str
. encode ( 'utf-8' ))
319 except xml
. etree
. ElementTree
. ParseError
:
322 fv_el
= find_xpath_attr ( object_doc
, './param' , 'name' , 'flashVars' )
323 if fv_el
is not None :
326 for k
, v
in compat_parse_qs ( fv_el
. attrib
[ 'value' ]). items ())
330 data_url
= object_doc
. attrib
. get ( 'data' , '' )
331 data_url_params
= parse_qs ( data_url
)
333 def find_param ( name
):
334 if name
in flashvars
:
335 return flashvars
[ name
]
336 node
= find_xpath_attr ( object_doc
, './param' , 'name' , name
)
338 return node
. attrib
[ 'value' ]
339 return data_url_params
. get ( name
)
343 playerID
= find_param ( 'playerID' ) or find_param ( 'playerId' )
345 raise ExtractorError ( 'Cannot find player ID' )
346 params
[ 'playerID' ] = playerID
348 playerKey
= find_param ( 'playerKey' )
349 # Not all pages define this value
350 if playerKey
is not None :
351 params
[ 'playerKey' ] = playerKey
352 # These fields hold the id of the video
353 videoPlayer
= find_param ( '@videoPlayer' ) or find_param ( 'videoId' ) or find_param ( 'videoID' ) or find_param ( '@videoList' )
354 if videoPlayer
is not None :
355 if isinstance ( videoPlayer
, list ):
356 videoPlayer
= videoPlayer
[ 0 ]
357 videoPlayer
= videoPlayer
. strip ()
358 # UUID is also possible for videoPlayer (e.g.
359 # http://www.popcornflix.com/hoodies-vs-hooligans/7f2d2b87-bbf2-4623-acfb-ea942b4f01dd
360 # or http://www8.hp.com/cn/zh/home.html)
362 r
'^(?:\d+|[\da-fA-F] {8} -?[\da-fA-F] {4} -?[\da-fA-F] {4} -?[\da-fA-F] {4} -?[\da-fA-F] {12} )$' ,
363 videoPlayer
) or videoPlayer
. startswith ( 'ref:' )):
365 params
[ '@videoPlayer' ] = videoPlayer
366 linkBase
= find_param ( 'linkBaseURL' )
367 if linkBase
is not None :
368 params
[ 'linkBaseURL' ] = linkBase
369 return cls
._ make
_ brightcove
_u rl
( params
)
372 def _build_brightcove_url_from_js ( cls
, object_js
):
373 # The layout of JS is as follows:
374 # customBC.createVideo = function (width, height, playerID, playerKey, videoPlayer, VideoRandomID) {
375 # // build Brightcove <object /> XML
378 r
'''(?x)customBC\.createVideo\(
379 .*? # skipping width and height
380 ["\' ]( ?P
< playerID
> \d
+)[ " \' ]\s*,\s* # playerID
381 [" \' ]( ?P
< playerKey
> AQ
[ ^
" \' ] {48} )[^" \' ]*[ " \' ]\s*,\s* # playerKey begins with AQ and is 50 characters
382 # in length, however it's appended to itself
383 # in places, so truncate
384 [" \' ]( ?P
< videoID
> \d
+)[ " \' ] # @videoPlayer
387 return cls._make_brightcove_url(m.groupdict())
390 def _make_brightcove_url(cls, params):
391 return update_url_query(
392 'http://c.brightcove.com/services/viewer/htmlFederated', params)
395 def _extract_brightcove_url(cls, webpage):
396 """Try to extract the brightcove url from the webpage, returns None
399 urls = cls._extract_brightcove_urls(webpage)
400 return urls[0] if urls else None
403 def _extract_brightcove_urls(cls, webpage):
404 """Return a list of all Brightcove URLs from the webpage """
409 (?:property|itemprop)=([ \' " ])( ?
: og
: video|embedURL
) \
1 [ ^
>]+
410 content
=([ \' "])(?P<url>https?://(?:secure|c)\.brightcove.com/(?:(?!\2).)+)\2
413 url = unescapeHTML(url_m.group('url'))
414 # Some sites don't add it, we can't download with this url, for example:
415 # http://www.ktvu.com/videos/news/raw-video-caltrain-releases-video-of-man-almost/vCTZdY/
416 if 'playerKey' in url or 'videoId' in url or 'idVideo' in url:
419 matches = re.findall(
422 [^>]+?class=[ \' " ][ ^
>]* ?BrightcoveExperience
.* ?
[ \' "] |
423 [^>]*?>\s*<param\s+name=" movie
"\s+value=" https?
://[ ^
/]* brightcove\
. com
/
424 ).+ ?
> \s
*</ object > ''',
427 return list(filter(None, [cls._build_brightcove_url(m) for m in matches]))
429 matches = re.findall(r'(customBC\.createVideo\(.+?\);)', webpage)
431 return list(filter(None, [
432 cls._build_brightcove_url_from_js(custom_bc)
433 for custom_bc in matches]))
434 return [src for _, src in re.findall(
435 r'<iframe[^>]+src=([ \' "])((?:https?:)?//link\.brightcove\.com/services/player/(?!\1).+)\1', webpage)]
437 def _extract_from_webpage(self, url, webpage):
438 bc_urls = self._extract_brightcove_urls(webpage)
439 for bc_url in bc_urls:
440 yield self.url_result(smuggle_url(bc_url, {'Referer': url} ), BrightcoveLegacyIE)
442 def _real_extract(self, url):
443 url, smuggled_data = unsmuggle_url(url, {})
445 # Change the 'videoId' and others field to '@videoPlayer'
446 url = re.sub(r'(?<=[?&])(videoI(d|D)|idVideo|bctid)', '%40videoPlayer', url)
447 # Change bckey (used by bcove.me urls) to playerKey
448 url = re.sub(r'(?<=[?&])bckey', 'playerKey', url)
449 mobj = self._match_valid_url(url)
450 query_str = mobj.group('query')
451 query = compat_urlparse.parse_qs(query_str)
453 videoPlayer = query.get('@videoPlayer')
455 # We set the original url as the default 'Referer' header
456 referer = query.get('linkBaseURL', [None])[0] or smuggled_data.get('Referer', url)
457 video_id = videoPlayer[0]
458 if 'playerID' not in query:
459 mobj = re.search(r'/bcpid(\d+)', url)
461 query['playerID'] = [mobj.group(1)]
462 publisher_id = query.get('publisherId')
463 if publisher_id and publisher_id[0].isdigit():
464 publisher_id = publisher_id[0]
466 player_key = query.get('playerKey')
467 if player_key and ',' in player_key[0]:
468 player_key = player_key[0]
470 player_id = query.get('playerID')
471 if player_id and player_id[0].isdigit():
474 headers['Referer'] = referer
475 player_page = self._download_webpage(
476 'http://link.brightcove.com/services/player/bcpid' + player_id[0],
477 video_id, headers=headers, fatal=False)
479 player_key = self._search_regex(
480 r'<param\s+name="playerKey"\s+value="([\w~,-]+)"',
481 player_page, 'player key', fatal=False)
483 enc_pub_id = player_key.split(',')[1].replace('~', '=')
484 publisher_id = struct.unpack('>Q', base64.urlsafe_b64decode(enc_pub_id))[0]
486 brightcove_new_url = 'http://players.brightcove.net/ %s /default_default/index.html?videoId= %s ' % (publisher_id, video_id)
488 brightcove_new_url = smuggle_url(brightcove_new_url, {'referrer': referer} )
489 return self.url_result(brightcove_new_url, BrightcoveNewIE.ie_key(), video_id)
490 # TODO: figure out if it's possible to extract playlistId from playerKey
491 # elif 'playerKey' in query:
492 # player_key = query['playerKey']
493 # return self._get_playlist_info(player_key[0])
494 raise UnsupportedError(url)
497 class BrightcoveNewBaseIE(AdobePassIE):
498 def _parse_brightcove_metadata(self, json_data, video_id, headers={}):
499 title = json_data['name'].strip()
501 formats, subtitles = [], {}
502 sources = json_data.get('sources') or []
503 for source in sources:
504 container = source.get('container')
505 ext = mimetype2ext(source.get('type'))
506 src = source.get('src')
507 if ext == 'm3u8' or container == 'M2TS':
510 fmts, subs = self._extract_m3u8_formats_and_subtitles(
511 src, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)
512 subtitles = self._merge_subtitles(subtitles, subs)
516 fmts, subs = self._extract_mpd_formats_and_subtitles(src, video_id, 'dash', fatal=False)
517 subtitles = self._merge_subtitles(subtitles, subs)
519 streaming_src = source.get('streaming_src')
520 stream_name, app_name = source.get('stream_name'), source.get('app_name')
521 if not src and not streaming_src and (not stream_name or not app_name):
523 tbr = float_or_none(source.get('avg_bitrate'), 1000)
524 height = int_or_none(source.get('height'))
525 width = int_or_none(source.get('width'))
528 'filesize': int_or_none(source.get('size')),
529 'container': container,
530 'ext': ext or container.lower(),
532 if width == 0 and height == 0:
540 'vcodec': source.get('codec'),
543 def build_format_id(kind):
546 format_id += '- %d k' % int(tbr)
548 format_id += '- %d p' % height
551 if src or streaming_src:
553 'url': src or streaming_src,
554 'format_id': build_format_id('http' if src else 'http-streaming'),
555 'source_preference': 0 if src else -1,
560 'play_path': stream_name,
561 'format_id': build_format_id('rtmp'),
565 # https://support.brightcove.com/playback-api-video-fields-reference#key_systems_object
566 if container == 'WVM' or source.get('key_systems') or ext == 'ism':
572 errors = json_data.get('errors')
575 self.raise_no_formats(
576 error.get('message') or error.get('error_subcode') or error['error_code'], expected=True)
579 f.setdefault('http_headers', {}).update(headers)
581 for text_track in json_data.get('text_tracks', []):
582 if text_track.get('kind') != 'captions':
584 text_track_url = url_or_none(text_track.get('src'))
585 if not text_track_url:
587 lang = (str_or_none(text_track.get('srclang'))
588 or str_or_none(text_track.get('label')) or 'en').lower()
589 subtitles.setdefault(lang, []).append({
590 'url': text_track_url,
594 duration = float_or_none(json_data.get('duration'), 1000)
595 if duration is not None and duration <= 0:
598 common_res = [(160, 90), (320, 180), (480, 720), (640, 360), (768, 432), (1024, 576), (1280, 720), (1366, 768), (1920, 1080)]
599 thumb_base_url = dict_get(json_data, ('poster', 'thumbnail'))
601 'url': re.sub(r'\d+x\d+', f' {w} x {h} ', thumb_base_url),
604 } for w, h in common_res] if thumb_base_url else None
609 'description': clean_html(json_data.get('description')),
610 'thumbnails': thumbnails,
611 'duration': duration,
612 'timestamp': parse_iso8601(json_data.get('published_at')),
613 'uploader_id': json_data.get('account_id'),
615 'subtitles': subtitles,
616 'tags': json_data.get('tags', []),
621 class BrightcoveNewIE(BrightcoveNewBaseIE):
622 IE_NAME = 'brightcove:new'
623 _VALID_URL = r'https?://players\.brightcove\.net/(?P<account_id>\d+)/(?P<player_id>[^/]+)_(?P<embed>[^/]+)/index\.html \? .*(?P<content_type>video|playlist)Id=(?P<video_id>\d+|ref:[^&]+)'
625 'url': 'http://players.brightcove.net/929656772001/e41d32dc-ec74-459e-a845-6c69f7b724ea_default/index.html?videoId=4463358922001',
626 'md5': 'c8100925723840d4b0d243f7025703be',
628 'id': '4463358922001',
630 'title': 'Meet the man behind Popcorn Time',
631 'description': 'md5:eac376a4fe366edc70279bfb681aea16',
633 'timestamp': 1441391203,
634 'upload_date': '20150904',
635 'uploader_id': '929656772001',
636 'formats': 'mincount:20',
638 'skip': '404 Not Found',
641 'url': 'http://players.brightcove.net/4036320279001/5d112ed9-283f-485f-a7f9-33f42e8bc042_default/index.html?videoId=4279049078001',
643 'id': '4279049078001',
645 'title': 'Titansgrave: Chapter 0',
646 'description': 'Titansgrave: Chapter 0',
647 'duration': 1242.058,
648 'timestamp': 1433556729,
649 'upload_date': '20150606',
650 'uploader_id': '4036320279001',
651 'formats': 'mincount:39',
655 'skip_download': True,
659 'url': 'https://players.brightcove.net/1752604059001/S13cJdUBz_default/index.html?playlistId=5718313430001',
661 'id': '5718313430001',
662 'title': 'No Audio Playlist',
667 'skip_download': True,
670 'url': 'http://players.brightcove.net/5690807595001/HyZNerRl7_default/index.html?playlistId=5743160747001',
671 'only_matching': True,
673 # ref: prefixed video id
674 'url': 'http://players.brightcove.net/3910869709001/21519b5c-4b3b-4363-accb-bdc8f358f823_default/index.html?videoId=ref:7069442',
675 'only_matching': True,
677 # non numeric ref: prefixed video id
678 'url': 'http://players.brightcove.net/710858724001/default_default/index.html?videoId=ref:event-stream-356',
679 'only_matching': True,
681 # unavailable video without message but with error_code
682 'url': 'http://players.brightcove.net/1305187701/c832abfb-641b-44eb-9da0-2fe76786505f_default/index.html?videoId=4377407326001',
683 'only_matching': True,
687 # brightcove player url embed
688 'url': 'https://nbc-2.com/weather/forecast/2022/11/16/forecast-warmest-day-of-the-week/',
689 'md5': '2934d5372b354d27083ccf8575dbfee2',
691 'id': '6315650313112',
692 'title': 'First Alert Forecast: November 15, 2022',
694 'tags': ['nbc2', 'forecast'],
695 'uploader_id': '6146886170001',
696 'thumbnail': r're:^https?://.*\.jpg$',
697 'timestamp': 1668574571,
699 'upload_date': '20221116',
702 # embedded with video tag only
703 'url': 'https://www.gooddishtv.com/tiktok-rapping-chef-mr-pyrex',
705 'id': 'tiktok-rapping-chef-mr-pyrex',
706 'title': 'TikTok \' s Rapping Chef Makes Jambalaya for the Hosts',
707 'thumbnail': r're:^https?://.*\.jpg$',
709 'description': 'Just in time for Mardi Gras',
713 'id': '6299189544001',
715 'title': 'TGD_01-032_5',
716 'thumbnail': r're:^https?://.*\.jpg$',
718 'timestamp': 1646078943,
719 'uploader_id': '1569565978001',
720 'upload_date': '20220228',
725 'id': '6305565995112',
727 'title': 'TGD 01-087 (Airs 05.25.22)_Segment 5',
728 'thumbnail': r're:^https?://.*\.jpg$',
730 'timestamp': 1651604591,
731 'uploader_id': '1569565978001',
732 'upload_date': '20220503',
737 # Brightcove:new type [2].
738 'url': 'http://www.delawaresportszone.com/video-st-thomas-more-earns-first-trip-to-basketball-semis',
739 'md5': '2b35148fcf48da41c9fb4591650784f3',
741 'id': '5348741021001',
743 'upload_date': '20170306',
744 'uploader_id': '4191638492001',
745 'timestamp': 1488769918,
746 'title': 'VIDEO: St. Thomas More earns first trip to basketball semis',
748 'skip': '404 Not Found',
750 # Alternative brightcove <video> attributes
751 'url': 'http://www.programme-tv.net/videos/extraits/81095-guillaume-canet-evoque-les-rumeurs-d-infidelite-de-marion-cotillard-avec-brad-pitt-dans-vivement-dimanche/',
753 'id': '81095-guillaume-canet-evoque-les-rumeurs-d-infidelite-de-marion-cotillard-avec-brad-pitt-dans-vivement-dimanche',
754 'title': "Guillaume Canet évoque les rumeurs d'infidélité de Marion Cotillard avec Brad Pitt dans Vivement Dimanche, Extraits : toutes les vidéos avec Télé-Loisirs",
757 'md5': '732d22ba3d33f2f3fc253c39f8f36523',
759 'id': '5311302538001',
761 'title': "Guillaume Canet évoque les rumeurs d'infidélité de Marion Cotillard avec Brad Pitt dans Vivement Dimanche",
762 'description': "Guillaume Canet évoque les rumeurs d'infidélité de Marion Cotillard avec Brad Pitt dans Vivement Dimanche (France 2, 5 février 2017)",
763 'timestamp': 1486321708,
764 'upload_date': '20170205',
765 'uploader_id': '800000640001',
767 'only_matching': True,
769 'skip': '404 Not Found',
771 # Brightcove URL in single quotes
772 'url': 'http://www.sportsnet.ca/baseball/mlb/sn-presents-russell-martin-world-citizen/',
773 'md5': '4ae374f1f8b91c889c4b9203c8c752af',
775 'id': '4255764656001',
777 'title': 'SN Presents: Russell Martin, World Citizen',
778 'description': 'To understand why he was the Toronto Blue Jays’ top off-season priority is to appreciate his background and upbringing in Montreal, where he first developed his baseball skills. Written and narrated by Stephen Brunt.',
779 'uploader': 'Rogers Sportsnet',
780 'uploader_id': '1704050871',
781 'upload_date': '20150525',
782 'timestamp': 1432570283,
784 'skip': 'Page no longer has URL, now has javascript',
788 def _extract_url(ie, webpage):
789 urls = BrightcoveNewIE._extract_brightcove_urls(ie, webpage)
790 return urls[0] if urls else None
793 def _extract_brightcove_urls(ie, webpage):
795 # 1. http://docs.brightcove.com/en/video-cloud/brightcove-player/guides/publish-video.html#setvideoiniframe
796 # 2. http://docs.brightcove.com/en/video-cloud/brightcove-player/guides/publish-video.html#tag
797 # 3. http://docs.brightcove.com/en/video-cloud/brightcove-player/guides/publish-video.html#setvideousingjavascript
798 # 4. http://docs.brightcove.com/en/video-cloud/brightcove-player/guides/in-page-embed-player-implementation.html
799 # 5. https://support.brightcove.com/en/video-cloud/docs/dynamically-assigning-videos-player
803 # Look for iframe embeds [1]
804 for _, url in re.findall(
805 r'<iframe[^>]+src=([" \' ])((?:https?:)?//players\.brightcove\.net/\d+/[^/]+/index\.html.+?)\1', webpage):
806 entries.append(url if url.startswith('http') else 'http:' + url)
808 # Look for <video> tags [2] and embed_in_page embeds [3]
810 for video, script_tag, account_id, player_id, embed in re.findall(
812 (< video ( ?
:- js
) ?\s
+[ ^
>]* \b data
- video
- id \s
*= \s
*[ '"]?[^>]+>)
815 src=[" \' ](?:https?:)?//players\.brightcove\.net/
816 (\d+)/([^/]+)_([^/]+)/index(?:\.min)?\.js
820 attrs = extract_attributes(video)
822 # According to examples from [4] it' s unclear whether video
id
823 # may be optional and what to do when it is
824 video_id
= attrs
. get ( 'data-video-id' )
828 account_id
= account_id
or attrs
. get ( 'data-account' )
832 player_id
= player_id
or attrs
. get ( 'data-player' ) or 'default'
833 embed
= embed
or attrs
. get ( 'data-embed' ) or 'default'
835 bc_url
= 'http://players.brightcove.net/ %s / %s _ %s /index.html?videoId= %s ' % (
836 account_id
, player_id
, embed
, video_id
)
838 # Some brightcove videos may be embedded with video tag only and
839 # without script tag or any mentioning of brightcove at all. Such
840 # embeds are considered ambiguous since they are matched based only
841 # on data-video-id and data-account attributes and in the wild may
842 # not be brightcove embeds at all. Let's check reconstructed
843 # brightcove URLs in case of such embeds and only process valid
844 # ones. By this we ensure there is indeed a brightcove embed.
845 if not script_tag
and not ie
._ is
_ valid
_u rl
(
846 bc_url
, video_id
, 'possible brightcove video' ):
849 entries
. append ( bc_url
)
853 def _extract_from_webpage ( self
, url
, webpage
):
854 bc_urls
= self
._ extract
_ brightcove
_u rls
( self
, webpage
)
855 for bc_url
in bc_urls
:
856 yield self
. url_result ( smuggle_url ( bc_url
, {'referrer': url}
), BrightcoveNewIE
)
858 def _real_extract ( self
, url
):
859 url
, smuggled_data
= unsmuggle_url ( url
, {})
860 self
._ initialize
_ geo
_ bypass
({
861 'countries' : smuggled_data
. get ( 'geo_countries' ),
862 'ip_blocks' : smuggled_data
. get ( 'geo_ip_blocks' ),
865 account_id
, player_id
, embed
, content_type
, video_id
= self
._ match
_ valid
_u rl
( url
). groups ()
867 policy_key_id
= ' %s _ %s ' % ( account_id
, player_id
)
868 policy_key
= self
. cache
. load ( 'brightcove' , policy_key_id
)
869 policy_key_extracted
= False
870 store_pk
= lambda x
: self
. cache
. store ( 'brightcove' , policy_key_id
, x
)
872 def extract_policy_key ():
873 base_url
= 'http://players.brightcove.net/ %s / %s _ %s /' % ( account_id
, player_id
, embed
)
874 config
= self
._ download
_ json
(
875 base_url
+ 'config.json' , video_id
, fatal
= False ) or {}
876 policy_key
= try_get (
877 config
, lambda x
: x
[ 'video_cloud' ][ 'policy_key' ])
879 webpage
= self
._ download
_ webpage
(
880 base_url
+ 'index.min.js' , video_id
)
882 catalog
= self
._ search
_ regex
(
883 r
'catalog\(( {.+?} )\);' , webpage
, 'catalog' , default
= None )
885 catalog
= self
._ parse
_ json
(
886 js_to_json ( catalog
), video_id
, fatal
= False )
888 policy_key
= catalog
. get ( 'policyKey' )
891 policy_key
= self
._ search
_ regex
(
892 r
'policyKey\s*:\s*(["\' ])( ?P
< pk
>.+ ?
) \
1 ',
893 webpage, ' policy key
', group=' pk
')
898 api_url = ' https
:// edge
. api
. brightcove
. com
/ playback
/ v1
/ accounts
/ %s/ %ss/ %s ' % (account_id, content_type, video_id)
900 referrer = smuggled_data.get(' referrer
') # XXX: notice the spelling/case of the key
904 ' Origin
': re.search(r' https?
://[ ^
/]+ ', referrer).group(0),
909 policy_key = extract_policy_key()
910 policy_key_extracted = True
911 headers[' Accept
'] = ' application
/ json
; pk
= %s ' % policy_key
913 json_data = self._download_json(api_url, video_id, headers=headers)
915 except ExtractorError as e:
916 if isinstance(e.cause, compat_HTTPError) and e.cause.code in (401, 403):
917 json_data = self._parse_json(e.cause.read().decode(), video_id)[0]
918 message = json_data.get(' message
') or json_data[' error_code
']
919 if json_data.get(' error_subcode
') == ' CLIENT_GEO
':
920 self.raise_geo_restricted(msg=message)
921 elif json_data.get(' error_code
') == ' INVALID_POLICY_KEY
' and not policy_key_extracted:
925 raise ExtractorError(message, expected=True)
928 errors = json_data.get(' errors
')
929 if errors and errors[0].get(' error_subcode
') == ' TVE_AUTH
':
930 custom_fields = json_data[' custom_fields
']
931 tve_token = self._extract_mvpd_auth(
932 smuggled_data[' source_url
'], video_id,
933 custom_fields[' bcadobepassrequestorid
'],
934 custom_fields[' bcadobepassresourceid
'])
935 json_data = self._download_json(
936 api_url, video_id, headers={
937 ' Accept
': ' application
/ json
; pk
= %s ' % policy_key
939 ' tveToken
': tve_token,
942 if content_type == ' playlist
':
943 return self.playlist_result(
944 [self._parse_brightcove_metadata(vid, vid.get(' id '), headers)
945 for vid in json_data.get(' videos
', []) if vid.get(' id ')],
946 json_data.get(' id '), json_data.get(' name
'),
947 json_data.get(' description
'))
949 return self._parse_brightcove_metadata(
950 json_data, video_id, headers=headers)