5 import xml
.etree
.ElementTree
7 from .adobepass
import AdobePassIE
8 from .common
import InfoExtractor
9 from ..compat
import compat_etree_fromstring
10 from ..networking
.exceptions
import HTTPError
35 class BrightcoveLegacyIE(InfoExtractor
):
36 IE_NAME
= 'brightcove:legacy'
37 _VALID_URL
= r
'(?:https?://.*brightcove\.com/(services|viewer).*?\?|brightcove:)(?P<query>.*)'
41 # From http://www.8tv.cat/8aldia/videos/xavier-sala-i-martin-aquesta-tarda-a-8-al-dia/
42 'url': 'http://c.brightcove.com/services/viewer/htmlFederated?playerID=1654948606001&flashID=myExperience&%40videoPlayer=2371591881001',
43 'md5': '5423e113865d26e40624dce2e4b45d95',
44 'note': 'Test Brightcove downloads and detection in GenericIE',
46 'id': '2371591881001',
48 'title': 'Xavier Sala i Martín: “Un banc que no presta és un banc zombi que no serveix per a res”',
50 'description': 'md5:a950cc4285c43e44d763d036710cd9cd',
51 'timestamp': 1368213670,
52 'upload_date': '20130510',
53 'uploader_id': '1589608506001',
55 'skip': 'The player has been deactivated by the content owner',
58 # From http://medianetwork.oracle.com/video/player/1785452137001
59 'url': 'http://c.brightcove.com/services/viewer/htmlFederated?playerID=1217746023001&flashID=myPlayer&%40videoPlayer=1785452137001',
61 'id': '1785452137001',
63 'title': 'JVMLS 2012: Arrays 2.0 - Opportunities and Challenges',
64 'description': 'John Rose speaks at the JVM Language Summit, August 1, 2012.',
66 'timestamp': 1344975024,
67 'upload_date': '20120814',
68 'uploader_id': '1460825906',
70 'skip': 'video not playable',
73 # From http://mashable.com/2013/10/26/thermoelectric-bracelet-lets-you-control-your-body-temperature/
74 'url': 'http://c.brightcove.com/services/viewer/federated_f9?&playerID=1265504713001&publisherID=AQ%7E%7E%2CAAABBzUwv1E%7E%2CxP-xFHVUstiMFlNYfvF4G9yFnNaqCw_9&videoID=2750934548001',
76 'id': '2750934548001',
78 'title': 'This Bracelet Acts as a Personal Thermostat',
79 'description': 'md5:547b78c64f4112766ccf4e151c20b6a0',
80 # 'uploader': 'Mashable',
81 'timestamp': 1382041798,
82 'upload_date': '20131017',
83 'uploader_id': '1130468786001',
87 # test that the default referer works
88 # from http://national.ballet.ca/interact/video/Lost_in_Motion_II/
89 'url': 'http://link.brightcove.com/services/player/bcpid756015033001?bckey=AQ~~,AAAApYJi_Ck~,GxhXCegT1Dp39ilhXuxMJxasUhVNZiil&bctid=2878862109001',
91 'id': '2878862109001',
93 'title': 'Lost in Motion II',
94 'description': 'md5:363109c02998fee92ec02211bd8000df',
95 'uploader': 'National Ballet of Canada',
100 # test flv videos served by akamaihd.net
101 # From http://www.redbull.com/en/bike/stories/1331655643987/replay-uci-dh-world-cup-2014-from-fort-william
102 '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',
103 # The md5 checksum changes on each download
105 'id': '3750436379001',
107 'title': 'UCI MTB World Cup 2014: Fort William, UK - Downhill Finals',
108 'uploader': 'RBTV Old (do not use)',
109 'description': 'UCI MTB World Cup 2014: Fort William, UK - Downhill Finals',
110 'timestamp': 1409122195,
111 'upload_date': '20140827',
112 'uploader_id': '710858724001',
114 'skip': 'Video gone',
117 # playlist with 'videoList'
118 # from http://support.brightcove.com/en/video-cloud/docs/playlist-support-single-video-players
119 'url': 'http://c.brightcove.com/services/viewer/htmlFederated?playerID=3550052898001&playerKey=AQ%7E%7E%2CAAABmA9XpXk%7E%2C-Kp7jNgisre1fG5OdqpAFUTcs0lP_ZoL',
122 'id': '3550319591001',
124 'playlist_mincount': 7,
125 'skip': 'Unsupported URL',
128 # playlist with 'playlistTab' (https://github.com/ytdl-org/youtube-dl/issues/9965)
129 'url': 'http://c.brightcove.com/services/json/experience/runtime/?command=get_programming_for_experience&playerKey=AQ%7E%7E,AAABXlLMdok%7E,NJ4EoMlZ4rZdx9eU1rkMVd8EaYPBBUlg',
131 'id': '1522758701001',
132 'title': 'Lesson 08',
134 'playlist_mincount': 10,
135 'skip': 'Unsupported URL',
138 # playerID inferred from bcpid
139 # from http://www.un.org/chinese/News/story.asp?NewsID=27724
140 'url': 'https://link.brightcove.com/services/player/bcpid1722935254001/?bctid=5360463607001&autoStart=false&secureConnections=true&width=650&height=350',
141 'only_matching': True, # Tested in GenericIE
146 # embedded brightcove video
147 # it also tests brightcove videos that need to set the 'Referer'
148 # in the http requests
149 'url': 'http://www.bfmtv.com/video/bfmbusiness/cours-bourse/cours-bourse-l-analyse-technique-154522/',
151 'id': '2765128793001',
153 'title': 'Le cours de bourse : l’analyse technique',
154 'description': 'md5:7e9ad046e968cb2d1114004aba466fd9',
155 'uploader': 'BFM BUSINESS',
158 'skip_download': True,
160 'skip': '404 Not Found',
162 # embedded with itemprop embedURL and video id spelled as `idVideo`
163 'url': 'http://bfmbusiness.bfmtv.com/mediaplayer/chroniques/olivier-delamarche/',
165 'id': '5255628253001',
167 'title': 'md5:37c519b1128915607601e75a87995fc0',
168 'description': 'md5:37f7f888b434bb8f8cc8dbd4f7a4cf26',
169 'uploader': 'BFM BUSINESS',
170 'uploader_id': '876450612001',
171 'timestamp': 1482255315,
172 'upload_date': '20161220',
175 'skip_download': True,
177 'skip': 'Redirects, page gone',
179 # https://github.com/ytdl-org/youtube-dl/issues/2253
180 'url': 'http://bcove.me/i6nfkrc3',
181 'md5': '0ba9446db037002366bab3b3eb30c88c',
183 'id': '3101154703001',
185 'title': 'Still no power',
186 'uploader': 'thestar.com',
187 '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.',
189 'skip': 'video gone',
191 # https://github.com/ytdl-org/youtube-dl/issues/3541
192 'url': 'http://www.kijk.nl/sbs6/leermijvrouwenkennen/videos/jqMiXKAYan2S/aflevering-1',
194 'id': '3866516442001',
196 'title': 'Leer mij vrouwen kennen: Aflevering 1',
197 'description': 'Leer mij vrouwen kennen: Aflevering 1',
198 'uploader': 'SBS Broadcasting',
200 'skip': 'Restricted to Netherlands, 404 Not Found',
202 'skip_download': True, # m3u8 download
205 # Brightcove video in <iframe>
206 'url': 'http://www.un.org/chinese/News/story.asp?NewsID=27724',
207 'md5': '36d74ef5e37c8b4a2ce92880d208b968',
209 'id': '5360463607001',
211 'title': '叙利亚失明儿童在废墟上演唱《心跳》 呼吁获得正常童年生活',
212 'description': '联合国儿童基金会中东和北非区域大使、作曲家扎德·迪拉尼(Zade Dirani)在3月15日叙利亚冲突爆发7周年纪念日之际发布了为叙利亚谱写的歌曲《心跳》(HEARTBEAT),为受到六年冲突影响的叙利亚儿童发出强烈呐喊,呼吁世界做出共同努力,使叙利亚儿童重新获得享有正常童年生活的权利。',
213 'uploader': 'United Nations',
214 'uploader_id': '1362235914001',
215 'timestamp': 1489593889,
216 'upload_date': '20170315',
218 'skip': '404 Not Found',
220 # Brightcove with UUID in videoPlayer
221 'url': 'http://www8.hp.com/cn/zh/home.html',
223 'id': '5255815316001',
225 'title': 'Sprocket Video - China',
226 'description': 'Sprocket Video - China',
227 'uploader': 'HP-Video Gallery',
228 'timestamp': 1482263210,
229 'upload_date': '20161220',
230 'uploader_id': '1107601872001',
233 'skip_download': True, # m3u8 download
235 'skip': 'video rotates...weekly?',
237 # Multiple brightcove videos
238 # https://github.com/ytdl-org/youtube-dl/issues/2283
239 'url': 'http://www.newyorker.com/online/blogs/newsdesk/2014/01/always-never-nuclear-command-and-control.html',
241 'id': 'always-never',
242 'title': 'Always / Never - The New Yorker',
246 'extract_flat': False,
247 'skip_download': True,
249 'skip': 'Redirects, page gone',
251 # BrightcoveInPageEmbed embed
252 'url': 'http://www.geekandsundry.com/tabletop-bonus-wils-final-thoughts-on-dread/',
254 'id': '4238694884001',
256 'title': 'Tabletop: Dread, Last Thoughts',
257 'description': 'Tabletop: Dread, Last Thoughts',
260 'skip': 'Redirects, page gone',
262 # Brightcove embed, with no valid 'renditions' but valid 'IOSRenditions'
263 # This video can't be played in browsers if Flash disabled and UA set to iPhone, which is actually a false alarm
264 'url': 'https://dl.dropboxusercontent.com/u/29092637/interview.html',
266 'id': '4785848093001',
268 'title': 'The Cardinal Pell Interview',
269 'description': 'Sky News Contributor Andrew Bolt interviews George Pell in Rome, following the Cardinal\'s evidence before the Royal Commission into Child Abuse. ',
270 'uploader': 'GlobeCast Australia - GlobeStream',
271 'uploader_id': '2733773828001',
272 'upload_date': '20160304',
273 'timestamp': 1457083087,
277 'skip_download': True,
279 'skip': '404 Not Found',
281 # Brightcove embed with whitespace around attribute names
282 'url': 'http://www.stack.com/video/3167554373001/learn-to-hit-open-three-pointers-with-damian-lillard-s-baseline-drift-drill',
284 'id': '3167554373001',
286 'title': "Learn to Hit Open Three-Pointers With Damian Lillard's Baseline Drift Drill",
287 'description': 'md5:57bacb0e0f29349de4972bfda3191713',
288 'uploader_id': '1079349493',
289 'upload_date': '20140207',
290 'timestamp': 1391810548,
293 'skip_download': True,
299 def _build_brightcove_url(cls
, object_str
):
301 Build a Brightcove url from a xml string containing
302 <object class="BrightcoveExperience">{params}</object>
305 # Fix up some stupid HTML, see https://github.com/ytdl-org/youtube-dl/issues/1553
306 object_str
= re
.sub(r
'(<param(?:\s+[a-zA-Z0-9_]+="[^"]*")*)>',
307 lambda m
: m
.group(1) + '/>', object_str
)
308 # Fix up some stupid XML, see https://github.com/ytdl-org/youtube-dl/issues/1608
309 object_str
= object_str
.replace('<--', '<!--')
310 # remove namespace to simplify extraction
311 object_str
= re
.sub(r
'(<object[^>]*)(xmlns=".*?")', r
'\1', object_str
)
312 object_str
= fix_xml_ampersands(object_str
)
315 object_doc
= compat_etree_fromstring(object_str
.encode())
316 except xml
.etree
.ElementTree
.ParseError
:
319 fv_el
= find_xpath_attr(object_doc
, './param', 'name', 'flashVars')
320 if fv_el
is not None:
323 for k
, v
in urllib
.parse
.parse_qs(fv_el
.attrib
['value']).items())
327 data_url
= object_doc
.attrib
.get('data', '')
328 data_url_params
= parse_qs(data_url
)
330 def find_param(name
):
331 if name
in flashvars
:
332 return flashvars
[name
]
333 node
= find_xpath_attr(object_doc
, './param', 'name', name
)
335 return node
.attrib
['value']
336 return data_url_params
.get(name
)
340 player_id
= find_param('playerID') or find_param('playerId')
341 if player_id
is None:
342 raise ExtractorError('Cannot find player ID')
343 params
['playerID'] = player_id
345 player_key
= find_param('playerKey')
346 # Not all pages define this value
347 if player_key
is not None:
348 params
['playerKey'] = player_key
349 # These fields hold the id of the video
350 video_player
= find_param('@videoPlayer') or find_param('videoId') or find_param('videoID') or find_param('@videoList')
351 if video_player
is not None:
352 if isinstance(video_player
, list):
353 video_player
= video_player
[0]
354 video_player
= video_player
.strip()
355 # UUID is also possible for videoPlayer (e.g.
356 # http://www.popcornflix.com/hoodies-vs-hooligans/7f2d2b87-bbf2-4623-acfb-ea942b4f01dd
357 # or http://www8.hp.com/cn/zh/home.html)
359 r
'^(?:\d+|[\da-fA-F]{8}-?[\da-fA-F]{4}-?[\da-fA-F]{4}-?[\da-fA-F]{4}-?[\da-fA-F]{12})$',
360 video_player
) or video_player
.startswith('ref:')):
362 params
['@videoPlayer'] = video_player
363 link_base
= find_param('linkBaseURL')
364 if link_base
is not None:
365 params
['linkBaseURL'] = link_base
366 return cls
._make
_brightcove
_url
(params
)
369 def _build_brightcove_url_from_js(cls
, object_js
):
370 # The layout of JS is as follows:
371 # customBC.createVideo = function (width, height, playerID, playerKey, videoPlayer, VideoRandomID) {
372 # // build Brightcove <object /> XML
375 r
'''(?x)customBC\.createVideo\(
376 .*? # skipping width and height
377 ["\'](?P
<playerID
>\d
+)["\']\s*,\s* # playerID
378 ["\'](?P
<playerKey
>AQ
[^
"\']{48})[^"\']*["\']\s*,\s* # playerKey begins with AQ and is 50 characters
379 # in length, however it's appended to itself
380 # in places, so truncate
381 ["\'](?P
<videoID
>\d
+)["\'] # @videoPlayer
384 return cls._make_brightcove_url(m.groupdict())
387 def _make_brightcove_url(cls, params):
388 return update_url_query(
389 'https://c.brightcove.com/services/viewer/htmlFederated', params)
392 def _extract_brightcove_url(cls, webpage):
393 """Try to extract the brightcove url from the webpage, returns None
396 urls = cls._extract_brightcove_urls(webpage)
397 return urls[0] if urls else None
400 def _extract_brightcove_urls(cls, webpage):
401 """Return a list of all Brightcove URLs from the webpage """
406 (?:property|itemprop)=([\'"])(?
:og
:video|embedURL
)\
1[^
>]+
407 content
=([\'"])(?P<url>https?://(?:secure|c)\.brightcove.com/(?:(?!\2).)+)\2
410 url = unescapeHTML(url_m.group('url'))
411 # Some sites don't add it, we can't download with this url, for example:
412 # http://www.ktvu.com/videos/news/raw-video-caltrain-releases-video-of-man-almost/vCTZdY/
413 if 'playerKey' in url or 'videoId' in url or 'idVideo' in url:
416 matches = re.findall(
419 [^>]+?class=[\'"][^
>]*?BrightcoveExperience
.*?
[\'"] |
420 [^>]*?>\s*<param\s+name="movie
"\s+value="https?
://[^
/]*brightcove\
.com
/
421 ).+?
>\s
*</object>''',
424 return list(filter(None, [cls._build_brightcove_url(m) for m in matches]))
426 matches = re.findall(r'(customBC\.createVideo\(.+?\);)', webpage)
428 return list(filter(None, [
429 cls._build_brightcove_url_from_js(custom_bc)
430 for custom_bc in matches]))
431 return [src for _, src in re.findall(
432 r'<iframe[^>]+src=([\'"])((?:https?:)?//link\.brightcove\.com/services/player/(?!\1).+)\1', webpage)]
434 def _extract_from_webpage(self, url, webpage):
435 bc_urls = self._extract_brightcove_urls(webpage)
436 for bc_url in bc_urls:
437 yield self.url_result(smuggle_url(bc_url, {'Referer': url}), BrightcoveLegacyIE)
439 def _real_extract(self, url):
440 url, smuggled_data = unsmuggle_url(url, {})
442 # Change the 'videoId' and others field to '@videoPlayer'
443 url = re.sub(r'(?<=[?&])(videoI(d|D)|idVideo|bctid)', '%40videoPlayer', url)
444 # Change bckey (used by bcove.me urls) to playerKey
445 url = re.sub(r'(?<=[?&])bckey', 'playerKey', url)
446 mobj = self._match_valid_url(url)
447 query_str = mobj.group('query')
448 query = urllib.parse.parse_qs(query_str)
450 video_player = query.get('@videoPlayer')
452 # We set the original url as the default 'Referer' header
453 referer = query.get('linkBaseURL', [None])[0] or smuggled_data.get('Referer', url)
454 video_id = video_player[0]
455 if 'playerID' not in query:
456 mobj = re.search(r'/bcpid(\d+)', url)
458 query['playerID'] = [mobj.group(1)]
459 publisher_id = query.get('publisherId')
460 if publisher_id and publisher_id[0].isdigit():
461 publisher_id = publisher_id[0]
463 player_key = query.get('playerKey')
464 if player_key and ',' in player_key[0]:
465 player_key = player_key[0]
467 player_id = query.get('playerID')
468 if player_id and player_id[0].isdigit():
471 headers['Referer'] = referer
472 player_page = self._download_webpage(
473 'https://link.brightcove.com/services/player/bcpid' + player_id[0],
474 video_id, headers=headers, fatal=False)
476 player_key = self._search_regex(
477 r'<param\s+name="playerKey"\s+value="([\w~,-]+)"',
478 player_page, 'player key', fatal=False)
480 enc_pub_id = player_key.split(',')[1].replace('~', '=')
481 publisher_id = struct.unpack('>Q', base64.urlsafe_b64decode(enc_pub_id))[0]
483 brightcove_new_url = f'https://players.brightcove.net/{publisher_id}/default_default/index.html?videoId={video_id}'
485 brightcove_new_url = smuggle_url(brightcove_new_url, {'referrer': referer})
486 return self.url_result(brightcove_new_url, BrightcoveNewIE.ie_key(), video_id)
487 # TODO: figure out if it's possible to extract playlistId from playerKey
488 # elif 'playerKey' in query:
489 # player_key = query['playerKey']
490 # return self._get_playlist_info(player_key[0])
491 raise UnsupportedError(url)
494 class BrightcoveNewBaseIE(AdobePassIE):
495 def _parse_brightcove_metadata(self, json_data, video_id, headers={}):
496 title = json_data['name'].strip()
498 formats, subtitles = [], {}
499 sources = json_data.get('sources') or []
500 for source in sources:
501 container = source.get('container')
502 ext = mimetype2ext(source.get('type'))
503 src = source.get('src')
504 if ext == 'm3u8' or container == 'M2TS':
507 fmts, subs = self._extract_m3u8_formats_and_subtitles(
508 src, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)
509 subtitles = self._merge_subtitles(subtitles, subs)
513 fmts, subs = self._extract_mpd_formats_and_subtitles(src, video_id, 'dash', fatal=False)
514 subtitles = self._merge_subtitles(subtitles, subs)
516 streaming_src = source.get('streaming_src')
517 stream_name, app_name = source.get('stream_name'), source.get('app_name')
518 if not src and not streaming_src and (not stream_name or not app_name):
520 tbr = float_or_none(source.get('avg_bitrate'), 1000)
521 height = int_or_none(source.get('height'))
522 width = int_or_none(source.get('width'))
525 'filesize': int_or_none(source.get('size')),
526 'container': container,
527 'ext': ext or container.lower(),
529 if width == 0 and height == 0:
537 'vcodec': source.get('codec'),
540 def build_format_id(kind):
543 format_id += f'-{int(tbr)}k'
545 format_id += f'-{height}p'
548 if src or streaming_src:
550 'url': src or streaming_src,
551 'format_id': build_format_id('http' if src else 'http-streaming'),
552 'source_preference': 0 if src else -1,
557 'play_path': stream_name,
558 'format_id': build_format_id('rtmp'),
562 # https://support.brightcove.com/playback-api-video-fields-reference#key_systems_object
563 if container == 'WVM' or source.get('key_systems') or ext == 'ism':
569 errors = json_data.get('errors')
572 self.raise_no_formats(
573 error.get('message') or error.get('error_subcode') or error['error_code'], expected=True)
575 headers.pop('Authorization', None) # or else http formats will give error 400
577 f.setdefault('http_headers', {}).update(headers)
579 for text_track in json_data.get('text_tracks', []):
580 if text_track.get('kind') != 'captions':
582 text_track_url = url_or_none(text_track.get('src'))
583 if not text_track_url:
585 lang = (str_or_none(text_track.get('srclang'))
586 or str_or_none(text_track.get('label')) or 'en').lower()
587 subtitles.setdefault(lang, []).append({
588 'url': text_track_url,
592 duration = float_or_none(json_data.get('duration'), 1000)
593 if duration is not None and duration <= 0:
596 common_res = [(160, 90), (320, 180), (480, 720), (640, 360), (768, 432), (1024, 576), (1280, 720), (1366, 768), (1920, 1080)]
597 thumb_base_url = dict_get(json_data, ('poster', 'thumbnail'))
599 'url': re.sub(r'\d+x\d+', f'{w}x{h}', thumb_base_url),
602 } for w, h in common_res] if thumb_base_url else None
607 'description': clean_html(json_data.get('description')),
608 'thumbnails': thumbnails,
609 'duration': duration,
610 'timestamp': parse_iso8601(json_data.get('published_at')),
611 'uploader_id': json_data.get('account_id'),
613 'subtitles': subtitles,
614 'tags': json_data.get('tags', []),
619 class BrightcoveNewIE(BrightcoveNewBaseIE):
620 IE_NAME = 'brightcove:new'
621 _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:[^&]+)'
623 'url': 'http://players.brightcove.net/929656772001/e41d32dc-ec74-459e-a845-6c69f7b724ea_default/index.html?videoId=4463358922001',
624 'md5': 'c8100925723840d4b0d243f7025703be',
626 'id': '4463358922001',
628 'title': 'Meet the man behind Popcorn Time',
629 'description': 'md5:eac376a4fe366edc70279bfb681aea16',
631 'timestamp': 1441391203,
632 'upload_date': '20150904',
633 'uploader_id': '929656772001',
634 'formats': 'mincount:20',
636 'skip': '404 Not Found',
639 'url': 'http://players.brightcove.net/4036320279001/5d112ed9-283f-485f-a7f9-33f42e8bc042_default/index.html?videoId=4279049078001',
641 'id': '4279049078001',
643 'title': 'Titansgrave: Chapter 0',
644 'description': 'Titansgrave: Chapter 0',
645 'duration': 1242.058,
646 'timestamp': 1433556729,
647 'upload_date': '20150606',
648 'uploader_id': '4036320279001',
649 'formats': 'mincount:39',
653 'skip_download': True,
657 'url': 'https://players.brightcove.net/1752604059001/S13cJdUBz_default/index.html?playlistId=5718313430001',
659 'id': '5718313430001',
660 'title': 'No Audio Playlist',
665 'skip_download': True,
668 'url': 'http://players.brightcove.net/5690807595001/HyZNerRl7_default/index.html?playlistId=5743160747001',
669 'only_matching': True,
671 # ref: prefixed video id
672 'url': 'http://players.brightcove.net/3910869709001/21519b5c-4b3b-4363-accb-bdc8f358f823_default/index.html?videoId=ref:7069442',
673 'only_matching': True,
675 # non numeric ref: prefixed video id
676 'url': 'http://players.brightcove.net/710858724001/default_default/index.html?videoId=ref:event-stream-356',
677 'only_matching': True,
679 # unavailable video without message but with error_code
680 'url': 'http://players.brightcove.net/1305187701/c832abfb-641b-44eb-9da0-2fe76786505f_default/index.html?videoId=4377407326001',
681 'only_matching': True,
685 # brightcove player url embed
686 'url': 'https://nbc-2.com/weather/forecast/2022/11/16/forecast-warmest-day-of-the-week/',
687 'md5': '2934d5372b354d27083ccf8575dbfee2',
689 'id': '6315650313112',
690 'title': 'First Alert Forecast: November 15, 2022',
692 'tags': ['nbc2', 'forecast'],
693 'uploader_id': '6146886170001',
694 'thumbnail': r're:^https?://.*\.jpg$',
695 'timestamp': 1668574571,
697 'upload_date': '20221116',
700 # embedded with video tag only
701 'url': 'https://www.gooddishtv.com/tiktok-rapping-chef-mr-pyrex',
703 'id': 'tiktok-rapping-chef-mr-pyrex',
704 'title': 'TikTok\'s Rapping Chef Makes Jambalaya for the Hosts',
705 'thumbnail': r're:^https?://.*\.jpg$',
707 'description': 'Just in time for Mardi Gras',
711 'id': '6299189544001',
713 'title': 'TGD_01-032_5',
714 'thumbnail': r're:^https?://.*\.jpg$',
716 'timestamp': 1646078943,
717 'uploader_id': '1569565978001',
718 'upload_date': '20220228',
723 'id': '6305565995112',
725 'title': 'TGD 01-087 (Airs 05.25.22)_Segment 5',
726 'thumbnail': r're:^https?://.*\.jpg$',
728 'timestamp': 1651604591,
729 'uploader_id': '1569565978001',
730 'upload_date': '20220503',
735 # Brightcove:new type [2].
736 'url': 'http://www.delawaresportszone.com/video-st-thomas-more-earns-first-trip-to-basketball-semis',
737 'md5': '2b35148fcf48da41c9fb4591650784f3',
739 'id': '5348741021001',
741 'upload_date': '20170306',
742 'uploader_id': '4191638492001',
743 'timestamp': 1488769918,
744 'title': 'VIDEO: St. Thomas More earns first trip to basketball semis',
746 'skip': '404 Not Found',
748 # Alternative brightcove <video> attributes
749 '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/',
751 'id': '81095-guillaume-canet-evoque-les-rumeurs-d-infidelite-de-marion-cotillard-avec-brad-pitt-dans-vivement-dimanche',
752 '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",
755 'md5': '732d22ba3d33f2f3fc253c39f8f36523',
757 'id': '5311302538001',
759 'title': "Guillaume Canet évoque les rumeurs d'infidélité de Marion Cotillard avec Brad Pitt dans Vivement Dimanche",
760 'description': "Guillaume Canet évoque les rumeurs d'infidélité de Marion Cotillard avec Brad Pitt dans Vivement Dimanche (France 2, 5 février 2017)",
761 'timestamp': 1486321708,
762 'upload_date': '20170205',
763 'uploader_id': '800000640001',
765 'only_matching': True,
767 'skip': '404 Not Found',
769 # Brightcove URL in single quotes
770 'url': 'http://www.sportsnet.ca/baseball/mlb/sn-presents-russell-martin-world-citizen/',
771 'md5': '4ae374f1f8b91c889c4b9203c8c752af',
773 'id': '4255764656001',
775 'title': 'SN Presents: Russell Martin, World Citizen',
776 '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.',
777 'uploader': 'Rogers Sportsnet',
778 'uploader_id': '1704050871',
779 'upload_date': '20150525',
780 'timestamp': 1432570283,
782 'skip': 'Page no longer has URL, now has javascript',
786 def _extract_url(ie, webpage):
787 urls = BrightcoveNewIE._extract_brightcove_urls(ie, webpage)
788 return urls[0] if urls else None
791 def _extract_brightcove_urls(ie, webpage):
793 # 1. http://docs.brightcove.com/en/video-cloud/brightcove-player/guides/publish-video.html#setvideoiniframe
794 # 2. http://docs.brightcove.com/en/video-cloud/brightcove-player/guides/publish-video.html#tag
795 # 3. http://docs.brightcove.com/en/video-cloud/brightcove-player/guides/publish-video.html#setvideousingjavascript
796 # 4. http://docs.brightcove.com/en/video-cloud/brightcove-player/guides/in-page-embed-player-implementation.html
797 # 5. https://support.brightcove.com/en/video-cloud/docs/dynamically-assigning-videos-player
801 # Look for iframe embeds [1]
802 for _, url in re.findall(
803 r'<iframe[^>]+src=(["\'])((?:https?:)?//players\.brightcove\.net/\d+/[^/]+/index\.html.+?)\1', webpage):
804 entries.append(url if url.startswith(('http:', 'https:')) else 'https:' + url)
806 # Look for <video> tags [2] and embed_in_page embeds [3]
808 for video, script_tag, account_id, player_id, embed in re.findall(
810 (<video(?
:-js
)?\s
+[^
>]*\bdata
-video
-id\s
*=\s
*['"]?[^>]+>)
813 src=["\'](?:https?:)?//players\.brightcove\.net/
814 (\d+)/([^/]+)_([^/]+)/index(?:\.min)?\.js
818 attrs = extract_attributes(video)
820 # According to examples from [4] it's unclear whether video
id
821 # may be optional and what to do when it is
822 video_id
= attrs
.get('data-video-id')
826 account_id
= account_id
or attrs
.get('data-account')
830 player_id
= player_id
or attrs
.get('data-player') or 'default'
831 embed
= embed
or attrs
.get('data-embed') or 'default'
833 bc_url
= f
'https://players.brightcove.net/{account_id}/{player_id}_{embed}/index.html?videoId={video_id}'
835 # Some brightcove videos may be embedded with video tag only and
836 # without script tag or any mentioning of brightcove at all. Such
837 # embeds are considered ambiguous since they are matched based only
838 # on data-video-id and data-account attributes and in the wild may
839 # not be brightcove embeds at all. Let's check reconstructed
840 # brightcove URLs in case of such embeds and only process valid
841 # ones. By this we ensure there is indeed a brightcove embed.
842 if not script_tag
and not ie
._is
_valid
_url
(
843 bc_url
, video_id
, 'possible brightcove video'):
846 entries
.append(bc_url
)
850 def _extract_from_webpage(self
, url
, webpage
):
851 bc_urls
= self
._extract
_brightcove
_urls
(self
, webpage
)
852 for bc_url
in bc_urls
:
853 yield self
.url_result(smuggle_url(bc_url
, {'referrer': url}
), BrightcoveNewIE
)
855 def _real_extract(self
, url
):
856 url
, smuggled_data
= unsmuggle_url(url
, {})
857 self
._initialize
_geo
_bypass
({
858 'countries': smuggled_data
.get('geo_countries'),
859 'ip_blocks': smuggled_data
.get('geo_ip_blocks'),
862 account_id
, player_id
, embed
, content_type
, video_id
= self
._match
_valid
_url
(url
).groups()
864 policy_key_id
= f
'{account_id}_{player_id}'
865 policy_key
= self
.cache
.load('brightcove', policy_key_id
)
866 policy_key_extracted
= False
867 store_pk
= lambda x
: self
.cache
.store('brightcove', policy_key_id
, x
)
869 def extract_policy_key():
870 base_url
= f
'https://players.brightcove.net/{account_id}/{player_id}_{embed}/'
871 config
= self
._download
_json
(
872 base_url
+ 'config.json', video_id
, fatal
=False) or {}
873 policy_key
= try_get(
874 config
, lambda x
: x
['video_cloud']['policy_key'])
876 webpage
= self
._download
_webpage
(
877 base_url
+ 'index.min.js', video_id
)
879 catalog
= self
._search
_regex
(
880 r
'catalog\(({.+?})\);', webpage
, 'catalog', default
=None)
882 catalog
= self
._parse
_json
(
883 js_to_json(catalog
), video_id
, fatal
=False)
885 policy_key
= catalog
.get('policyKey')
888 policy_key
= self
._search
_regex
(
889 r
'policyKey\s*:\s*(["\'])(?P
<pk
>.+?
)\
1',
890 webpage, 'policy key
', group='pk
')
895 token = smuggled_data.get('token
')
896 api_url = f'https
://{"edge-auth" if token else "edge"}
.api
.brightcove
.com
/playback
/v1
/accounts
/{account_id}
/{content_type}s
/{video_id}
'
897 headers = {'Authorization': f'Bearer {token}'} if token
else {}
898 referrer
= smuggled_data
.get('referrer') # XXX: notice the spelling/case of the key
902 'Origin': re
.search(r
'https?://[^/]+', referrer
).group(0),
907 policy_key
= extract_policy_key()
908 policy_key_extracted
= True
909 headers
['Accept'] = f
'application/json;pk={policy_key}'
911 json_data
= self
._download
_json
(api_url
, video_id
, headers
=headers
)
913 except ExtractorError
as e
:
914 if isinstance(e
.cause
, HTTPError
) and e
.cause
.status
in (401, 403):
915 json_data
= self
._parse
_json
(e
.cause
.response
.read().decode(), video_id
)[0]
916 message
= json_data
.get('message') or json_data
['error_code']
917 if json_data
.get('error_subcode') == 'CLIENT_GEO':
918 self
.raise_geo_restricted(msg
=message
)
919 elif json_data
.get('error_code') == 'INVALID_POLICY_KEY' and not policy_key_extracted
:
923 raise ExtractorError(message
, expected
=True)
926 errors
= json_data
.get('errors')
927 if errors
and errors
[0].get('error_subcode') == 'TVE_AUTH':
928 custom_fields
= json_data
['custom_fields']
929 tve_token
= self
._extract
_mvpd
_auth
(
930 smuggled_data
['source_url'], video_id
,
931 custom_fields
['bcadobepassrequestorid'],
932 custom_fields
['bcadobepassresourceid'])
933 json_data
= self
._download
_json
(
934 api_url
, video_id
, headers
={
935 'Accept': f
'application/json;pk={policy_key}',
937 'tveToken': tve_token
,
940 if content_type
== 'playlist':
941 return self
.playlist_result(
942 [self
._parse
_brightcove
_metadata
(vid
, vid
.get('id'), headers
)
943 for vid
in json_data
.get('videos', []) if vid
.get('id')],
944 json_data
.get('id'), json_data
.get('name'),
945 json_data
.get('description'))
947 return self
._parse
_brightcove
_metadata
(
948 json_data
, video_id
, headers
=headers
)