4 import xml
.etree
.ElementTree
6 from .adobepass
import AdobePassIE
7 from .common
import InfoExtractor
9 compat_etree_fromstring
,
13 from ..networking
.exceptions
import HTTPError
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
_url
(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 += '-%dk' % int(tbr)
548 format_id += '-%dp' % 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)
578 headers.pop('Authorization', None) # or else http formats will give error 400
580 f.setdefault('http_headers', {}).update(headers)
582 for text_track in json_data.get('text_tracks', []):
583 if text_track.get('kind') != 'captions':
585 text_track_url = url_or_none(text_track.get('src'))
586 if not text_track_url:
588 lang = (str_or_none(text_track.get('srclang'))
589 or str_or_none(text_track.get('label')) or 'en').lower()
590 subtitles.setdefault(lang, []).append({
591 'url': text_track_url,
595 duration = float_or_none(json_data.get('duration'), 1000)
596 if duration is not None and duration <= 0:
599 common_res = [(160, 90), (320, 180), (480, 720), (640, 360), (768, 432), (1024, 576), (1280, 720), (1366, 768), (1920, 1080)]
600 thumb_base_url = dict_get(json_data, ('poster', 'thumbnail'))
602 'url': re.sub(r'\d+x\d+', f'{w}x{h}', thumb_base_url),
605 } for w, h in common_res] if thumb_base_url else None
610 'description': clean_html(json_data.get('description')),
611 'thumbnails': thumbnails,
612 'duration': duration,
613 'timestamp': parse_iso8601(json_data.get('published_at')),
614 'uploader_id': json_data.get('account_id'),
616 'subtitles': subtitles,
617 'tags': json_data.get('tags', []),
622 class BrightcoveNewIE(BrightcoveNewBaseIE):
623 IE_NAME = 'brightcove:new'
624 _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:[^&]+)'
626 'url': 'http://players.brightcove.net/929656772001/e41d32dc-ec74-459e-a845-6c69f7b724ea_default/index.html?videoId=4463358922001',
627 'md5': 'c8100925723840d4b0d243f7025703be',
629 'id': '4463358922001',
631 'title': 'Meet the man behind Popcorn Time',
632 'description': 'md5:eac376a4fe366edc70279bfb681aea16',
634 'timestamp': 1441391203,
635 'upload_date': '20150904',
636 'uploader_id': '929656772001',
637 'formats': 'mincount:20',
639 'skip': '404 Not Found',
642 'url': 'http://players.brightcove.net/4036320279001/5d112ed9-283f-485f-a7f9-33f42e8bc042_default/index.html?videoId=4279049078001',
644 'id': '4279049078001',
646 'title': 'Titansgrave: Chapter 0',
647 'description': 'Titansgrave: Chapter 0',
648 'duration': 1242.058,
649 'timestamp': 1433556729,
650 'upload_date': '20150606',
651 'uploader_id': '4036320279001',
652 'formats': 'mincount:39',
656 'skip_download': True,
660 'url': 'https://players.brightcove.net/1752604059001/S13cJdUBz_default/index.html?playlistId=5718313430001',
662 'id': '5718313430001',
663 'title': 'No Audio Playlist',
668 'skip_download': True,
671 'url': 'http://players.brightcove.net/5690807595001/HyZNerRl7_default/index.html?playlistId=5743160747001',
672 'only_matching': True,
674 # ref: prefixed video id
675 'url': 'http://players.brightcove.net/3910869709001/21519b5c-4b3b-4363-accb-bdc8f358f823_default/index.html?videoId=ref:7069442',
676 'only_matching': True,
678 # non numeric ref: prefixed video id
679 'url': 'http://players.brightcove.net/710858724001/default_default/index.html?videoId=ref:event-stream-356',
680 'only_matching': True,
682 # unavailable video without message but with error_code
683 'url': 'http://players.brightcove.net/1305187701/c832abfb-641b-44eb-9da0-2fe76786505f_default/index.html?videoId=4377407326001',
684 'only_matching': True,
688 # brightcove player url embed
689 'url': 'https://nbc-2.com/weather/forecast/2022/11/16/forecast-warmest-day-of-the-week/',
690 'md5': '2934d5372b354d27083ccf8575dbfee2',
692 'id': '6315650313112',
693 'title': 'First Alert Forecast: November 15, 2022',
695 'tags': ['nbc2', 'forecast'],
696 'uploader_id': '6146886170001',
697 'thumbnail': r're:^https?://.*\.jpg$',
698 'timestamp': 1668574571,
700 'upload_date': '20221116',
703 # embedded with video tag only
704 'url': 'https://www.gooddishtv.com/tiktok-rapping-chef-mr-pyrex',
706 'id': 'tiktok-rapping-chef-mr-pyrex',
707 'title': 'TikTok\'s Rapping Chef Makes Jambalaya for the Hosts',
708 'thumbnail': r're:^https?://.*\.jpg$',
710 'description': 'Just in time for Mardi Gras',
714 'id': '6299189544001',
716 'title': 'TGD_01-032_5',
717 'thumbnail': r're:^https?://.*\.jpg$',
719 'timestamp': 1646078943,
720 'uploader_id': '1569565978001',
721 'upload_date': '20220228',
726 'id': '6305565995112',
728 'title': 'TGD 01-087 (Airs 05.25.22)_Segment 5',
729 'thumbnail': r're:^https?://.*\.jpg$',
731 'timestamp': 1651604591,
732 'uploader_id': '1569565978001',
733 'upload_date': '20220503',
738 # Brightcove:new type [2].
739 'url': 'http://www.delawaresportszone.com/video-st-thomas-more-earns-first-trip-to-basketball-semis',
740 'md5': '2b35148fcf48da41c9fb4591650784f3',
742 'id': '5348741021001',
744 'upload_date': '20170306',
745 'uploader_id': '4191638492001',
746 'timestamp': 1488769918,
747 'title': 'VIDEO: St. Thomas More earns first trip to basketball semis',
749 'skip': '404 Not Found',
751 # Alternative brightcove <video> attributes
752 '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/',
754 'id': '81095-guillaume-canet-evoque-les-rumeurs-d-infidelite-de-marion-cotillard-avec-brad-pitt-dans-vivement-dimanche',
755 '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",
758 'md5': '732d22ba3d33f2f3fc253c39f8f36523',
760 'id': '5311302538001',
762 'title': "Guillaume Canet évoque les rumeurs d'infidélité de Marion Cotillard avec Brad Pitt dans Vivement Dimanche",
763 'description': "Guillaume Canet évoque les rumeurs d'infidélité de Marion Cotillard avec Brad Pitt dans Vivement Dimanche (France 2, 5 février 2017)",
764 'timestamp': 1486321708,
765 'upload_date': '20170205',
766 'uploader_id': '800000640001',
768 'only_matching': True,
770 'skip': '404 Not Found',
772 # Brightcove URL in single quotes
773 'url': 'http://www.sportsnet.ca/baseball/mlb/sn-presents-russell-martin-world-citizen/',
774 'md5': '4ae374f1f8b91c889c4b9203c8c752af',
776 'id': '4255764656001',
778 'title': 'SN Presents: Russell Martin, World Citizen',
779 '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.',
780 'uploader': 'Rogers Sportsnet',
781 'uploader_id': '1704050871',
782 'upload_date': '20150525',
783 'timestamp': 1432570283,
785 'skip': 'Page no longer has URL, now has javascript',
789 def _extract_url(ie, webpage):
790 urls = BrightcoveNewIE._extract_brightcove_urls(ie, webpage)
791 return urls[0] if urls else None
794 def _extract_brightcove_urls(ie, webpage):
796 # 1. http://docs.brightcove.com/en/video-cloud/brightcove-player/guides/publish-video.html#setvideoiniframe
797 # 2. http://docs.brightcove.com/en/video-cloud/brightcove-player/guides/publish-video.html#tag
798 # 3. http://docs.brightcove.com/en/video-cloud/brightcove-player/guides/publish-video.html#setvideousingjavascript
799 # 4. http://docs.brightcove.com/en/video-cloud/brightcove-player/guides/in-page-embed-player-implementation.html
800 # 5. https://support.brightcove.com/en/video-cloud/docs/dynamically-assigning-videos-player
804 # Look for iframe embeds [1]
805 for _, url in re.findall(
806 r'<iframe[^>]+src=(["\'])((?:https?:)?//players\.brightcove\.net/\d+/[^/]+/index\.html.+?)\1', webpage):
807 entries.append(url if url.startswith('http') else 'http:' + url)
809 # Look for <video> tags [2] and embed_in_page embeds [3]
811 for video, script_tag, account_id, player_id, embed in re.findall(
813 (<video(?
:-js
)?\s
+[^
>]*\bdata
-video
-id\s
*=\s
*['"]?[^>]+>)
816 src=["\'](?:https?:)?//players\.brightcove\.net/
817 (\d+)/([^/]+)_([^/]+)/index(?:\.min)?\.js
821 attrs = extract_attributes(video)
823 # According to examples from [4] it's unclear whether video
id
824 # may be optional and what to do when it is
825 video_id
= attrs
.get('data-video-id')
829 account_id
= account_id
or attrs
.get('data-account')
833 player_id
= player_id
or attrs
.get('data-player') or 'default'
834 embed
= embed
or attrs
.get('data-embed') or 'default'
836 bc_url
= 'http://players.brightcove.net/%s/%s_%s/index.html?videoId=%s' % (
837 account_id
, player_id
, embed
, video_id
)
839 # Some brightcove videos may be embedded with video tag only and
840 # without script tag or any mentioning of brightcove at all. Such
841 # embeds are considered ambiguous since they are matched based only
842 # on data-video-id and data-account attributes and in the wild may
843 # not be brightcove embeds at all. Let's check reconstructed
844 # brightcove URLs in case of such embeds and only process valid
845 # ones. By this we ensure there is indeed a brightcove embed.
846 if not script_tag
and not ie
._is
_valid
_url
(
847 bc_url
, video_id
, 'possible brightcove video'):
850 entries
.append(bc_url
)
854 def _extract_from_webpage(self
, url
, webpage
):
855 bc_urls
= self
._extract
_brightcove
_urls
(self
, webpage
)
856 for bc_url
in bc_urls
:
857 yield self
.url_result(smuggle_url(bc_url
, {'referrer': url
}), BrightcoveNewIE
)
859 def _real_extract(self
, url
):
860 url
, smuggled_data
= unsmuggle_url(url
, {})
861 self
._initialize
_geo
_bypass
({
862 'countries': smuggled_data
.get('geo_countries'),
863 'ip_blocks': smuggled_data
.get('geo_ip_blocks'),
866 account_id
, player_id
, embed
, content_type
, video_id
= self
._match
_valid
_url
(url
).groups()
868 policy_key_id
= '%s_%s' % (account_id
, player_id
)
869 policy_key
= self
.cache
.load('brightcove', policy_key_id
)
870 policy_key_extracted
= False
871 store_pk
= lambda x
: self
.cache
.store('brightcove', policy_key_id
, x
)
873 def extract_policy_key():
874 base_url
= 'http://players.brightcove.net/%s/%s_%s/' % (account_id
, player_id
, embed
)
875 config
= self
._download
_json
(
876 base_url
+ 'config.json', video_id
, fatal
=False) or {}
877 policy_key
= try_get(
878 config
, lambda x
: x
['video_cloud']['policy_key'])
880 webpage
= self
._download
_webpage
(
881 base_url
+ 'index.min.js', video_id
)
883 catalog
= self
._search
_regex
(
884 r
'catalog\(({.+?})\);', webpage
, 'catalog', default
=None)
886 catalog
= self
._parse
_json
(
887 js_to_json(catalog
), video_id
, fatal
=False)
889 policy_key
= catalog
.get('policyKey')
892 policy_key
= self
._search
_regex
(
893 r
'policyKey\s*:\s*(["\'])(?P
<pk
>.+?
)\
1',
894 webpage, 'policy key
', group='pk
')
899 token = smuggled_data.get('token
')
900 api_url = f'https
://{"edge-auth" if token
else "edge"}.api
.brightcove
.com
/playback
/v1
/accounts
/{account_id}
/{content_type}s
/{video_id}
'
901 headers = {'Authorization
': f'Bearer {token}
'} if token else {}
902 referrer = smuggled_data.get('referrer
') # XXX: notice the spelling/case of the key
906 'Origin
': re.search(r'https?
://[^
/]+', referrer).group(0),
911 policy_key = extract_policy_key()
912 policy_key_extracted = True
913 headers['Accept
'] = 'application
/json
;pk
=%s' % policy_key
915 json_data = self._download_json(api_url, video_id, headers=headers)
917 except ExtractorError as e:
918 if isinstance(e.cause, HTTPError) and e.cause.status in (401, 403):
919 json_data = self._parse_json(e.cause.response.read().decode(), video_id)[0]
920 message = json_data.get('message
') or json_data['error_code
']
921 if json_data.get('error_subcode
') == 'CLIENT_GEO
':
922 self.raise_geo_restricted(msg=message)
923 elif json_data.get('error_code
') == 'INVALID_POLICY_KEY
' and not policy_key_extracted:
927 raise ExtractorError(message, expected=True)
930 errors = json_data.get('errors
')
931 if errors and errors[0].get('error_subcode
') == 'TVE_AUTH
':
932 custom_fields = json_data['custom_fields
']
933 tve_token = self._extract_mvpd_auth(
934 smuggled_data['source_url
'], video_id,
935 custom_fields['bcadobepassrequestorid
'],
936 custom_fields['bcadobepassresourceid
'])
937 json_data = self._download_json(
938 api_url, video_id, headers={
939 'Accept
': 'application
/json
;pk
=%s' % policy_key
941 'tveToken
': tve_token,
944 if content_type == 'playlist
':
945 return self.playlist_result(
946 [self._parse_brightcove_metadata(vid, vid.get('id'), headers)
947 for vid in json_data.get('videos
', []) if vid.get('id')],
948 json_data.get('id'), json_data.get('name
'),
949 json_data.get('description
'))
951 return self._parse_brightcove_metadata(
952 json_data, video_id, headers=headers)