2 from __future__ import unicode_literals
5 import xml.etree.ElementTree
7 from .common import InfoExtractor
17 from ..compat import compat_HTTPError
20 class BBCCoUkIE(InfoExtractor):
22 IE_DESC = 'BBC iPlayer'
23 _VALID_URL = r'https?://(?:www\.)?bbc\.co\.uk/(?:(?:(?:programmes|iplayer(?:/[^/]+)?/(?:episode|playlist))/)|music/clips[/#])(?P<id>[\da-z]{8})'
25 _MEDIASELECTOR_URLS = [
26 # Provides HQ HLS streams with even better quality that pc mediaset but fails
27 # with geolocation in some cases when it's even not geo restricted at all (e.g.
28 # http://www.bbc.co.uk/programmes/b06bp7lf)
29 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/iptv-all/vpid/%s',
30 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/pc/vpid/%s',
33 _MEDIASELECTION_NS = 'http://bbc.co.uk/2008/mp/mediaselection'
34 _EMP_PLAYLIST_NS = 'http://bbc.co.uk/2008/emp/playlist'
43 'url': 'http://www.bbc.co.uk/programmes/b039g8p7',
47 'title': 'Kaleidoscope, Leonard Cohen',
48 'description': 'The Canadian poet and songwriter reflects on his musical career.',
53 'skip_download': True,
57 'url': 'http://www.bbc.co.uk/iplayer/episode/b00yng5w/The_Man_in_Black_Series_3_The_Printed_Name/',
61 'title': 'The Man in Black: Series 3: The Printed Name',
62 'description': "Mark Gatiss introduces Nicholas Pierpan's chilling tale of a writer's devilish pact with a mysterious man. Stars Ewan Bailey.",
67 'skip_download': True,
69 'skip': 'Episode is no longer available on BBC iPlayer Radio',
72 'url': 'http://www.bbc.co.uk/iplayer/episode/b03vhd1f/The_Voice_UK_Series_3_Blind_Auditions_5/',
76 'title': 'The Voice UK: Series 3: Blind Auditions 5',
77 'description': "Emma Willis and Marvin Humes present the fifth set of blind auditions in the singing competition, as the coaches continue to build their teams based on voice alone.",
82 'skip_download': True,
84 'skip': 'Currently BBC iPlayer TV programmes are available to play in the UK only',
87 'url': 'http://www.bbc.co.uk/iplayer/episode/p026c7jt/tomorrows-worlds-the-unearthly-history-of-science-fiction-2-invasion',
91 'title': "Tomorrow's Worlds: The Unearthly History of Science Fiction",
92 'description': '2. Invasion',
97 'skip_download': True,
99 'skip': 'Currently BBC iPlayer TV programmes are available to play in the UK only',
101 'url': 'http://www.bbc.co.uk/programmes/b04v20dw',
105 'title': 'Pete Tong, The Essential New Tune Special',
106 'description': "Pete has a very special mix - all of 2014's Essential New Tunes!",
111 'skip_download': True,
114 'url': 'http://www.bbc.co.uk/music/clips/p02frcc3',
119 'title': 'Pete Tong, Past, Present and Future Special, Madeon - After Hours mix',
120 'description': 'French house superstar Madeon takes us out of the club and onto the after party.',
125 'skip_download': True,
128 'url': 'http://www.bbc.co.uk/music/clips/p025c0zz',
133 'title': 'Reading and Leeds Festival, 2014, Rae Morris - Closer (Live on BBC Three)',
134 'description': 'Rae Morris performs Closer for BBC Three at Reading 2014',
139 'skip_download': True,
142 'url': 'http://www.bbc.co.uk/iplayer/episode/b054fn09/ad/natural-world-20152016-2-super-powered-owls',
146 'title': 'Natural World, 2015-2016: 2. Super Powered Owls',
147 'description': 'md5:e4db5c937d0e95a7c6b5e654d429183d',
152 'skip_download': True,
154 'skip': 'geolocation',
156 'url': 'http://www.bbc.co.uk/iplayer/episode/b05zmgwn/royal-academy-summer-exhibition',
160 'description': 'Kirsty Wark and Morgan Quaintance visit the Royal Academy as it prepares for its annual artistic extravaganza, meeting people who have come together to make the show unique.',
161 'title': 'Royal Academy Summer Exhibition',
166 'skip_download': True,
168 'skip': 'geolocation',
170 # iptv-all mediaset fails with geolocation however there is no geo restriction
171 # for this programme at all
172 'url': 'http://www.bbc.co.uk/programmes/b06bp7lf',
176 'title': "Annie Mac's Friday Night, B.Traits sits in for Annie",
177 'description': 'B.Traits sits in for Annie Mac with a Mini-Mix from Disclosure.',
182 'skip_download': True,
185 'url': 'http://www.bbc.co.uk/iplayer/playlist/p01dvks4',
186 'only_matching': True,
188 'url': 'http://www.bbc.co.uk/music/clips#p02frcc3',
189 'only_matching': True,
191 'url': 'http://www.bbc.co.uk/iplayer/cbeebies/episode/b0480276/bing-14-atchoo',
192 'only_matching': True,
196 class MediaSelectionError(Exception):
197 def __init__(self, id):
200 def _extract_asx_playlist(self, connection, programme_id):
201 asx = self._download_xml(connection.get('href'), programme_id, 'Downloading ASX playlist')
202 return [ref.get('href') for ref in asx.findall('./Entry/ref')]
204 def _extract_connection(self, connection, programme_id):
206 kind = connection.get('kind')
207 protocol = connection.get('protocol')
208 supplier = connection.get('supplier')
209 if protocol == 'http':
210 href = connection.get('href')
211 transfer_format = connection.get('transferFormat')
213 if supplier == 'asx':
214 for i, ref in enumerate(self._extract_asx_playlist(connection, programme_id)):
217 'format_id': 'ref%s_%s' % (i, supplier),
219 # Skip DASH until supported
220 elif transfer_format == 'dash':
222 elif transfer_format == 'hls':
223 m3u8_formats = self._extract_m3u8_formats(
224 href, programme_id, ext='mp4', entry_protocol='m3u8_native',
225 m3u8_id=supplier, fatal=False)
227 formats.extend(m3u8_formats)
232 'format_id': supplier or kind or protocol,
234 elif protocol == 'rtmp':
235 application = connection.get('application', 'ondemand')
236 auth_string = connection.get('authString')
237 identifier = connection.get('identifier')
238 server = connection.get('server')
240 'url': '%s://%s/%s?%s' % (protocol, server, application, auth_string),
241 'play_path': identifier,
242 'app': '%s?%s' % (application, auth_string),
243 'page_url': 'http://www.bbc.co.uk',
244 'player_url': 'http://www.bbc.co.uk/emp/releases/iplayer/revisions/617463_618125_4/617463_618125_4_emp.swf',
247 'format_id': supplier,
251 def _extract_items(self, playlist):
252 return playlist.findall('./{%s}item' % self._EMP_PLAYLIST_NS)
254 def _findall_ns(self, element, xpath):
256 for ns in self._NAMESPACES:
257 elements.extend(element.findall(xpath % ns))
260 def _extract_medias(self, media_selection):
261 error = media_selection.find('./{%s}error' % self._MEDIASELECTION_NS)
263 media_selection.find('./{%s}error' % self._EMP_PLAYLIST_NS)
264 if error is not None:
265 raise BBCCoUkIE.MediaSelectionError(error.get('id'))
266 return self._findall_ns(media_selection, './{%s}media')
268 def _extract_connections(self, media):
269 return self._findall_ns(media, './{%s}connection')
271 def _extract_video(self, media, programme_id):
273 vbr = int_or_none(media.get('bitrate'))
274 vcodec = media.get('encoding')
275 service = media.get('service')
276 width = int_or_none(media.get('width'))
277 height = int_or_none(media.get('height'))
278 file_size = int_or_none(media.get('media_file_size'))
279 for connection in self._extract_connections(media):
280 conn_formats = self._extract_connection(connection, programme_id)
281 for format in conn_formats:
287 'filesize': file_size,
290 format['format_id'] = '%s_%s' % (service, format['format_id'])
291 formats.extend(conn_formats)
294 def _extract_audio(self, media, programme_id):
296 abr = int_or_none(media.get('bitrate'))
297 acodec = media.get('encoding')
298 service = media.get('service')
299 for connection in self._extract_connections(media):
300 conn_formats = self._extract_connection(connection, programme_id)
301 for format in conn_formats:
303 'format_id': '%s_%s' % (service, format['format_id']),
307 formats.extend(conn_formats)
310 def _get_subtitles(self, media, programme_id):
312 for connection in self._extract_connections(media):
313 captions = self._download_xml(connection.get('href'), programme_id, 'Downloading captions')
314 lang = captions.get('{http://www.w3.org/XML/1998/namespace}lang', 'en')
317 'url': connection.get('href'),
323 def _raise_extractor_error(self, media_selection_error):
324 raise ExtractorError(
325 '%s returned error: %s' % (self.IE_NAME, media_selection_error.id),
328 def _download_media_selector(self, programme_id):
329 last_exception = None
330 for mediaselector_url in self._MEDIASELECTOR_URLS:
332 return self._download_media_selector_url(
333 mediaselector_url % programme_id, programme_id)
334 except BBCCoUkIE.MediaSelectionError as e:
335 if e.id in ('notukerror', 'geolocation'):
338 self._raise_extractor_error(e)
339 self._raise_extractor_error(last_exception)
341 def _download_media_selector_url(self, url, programme_id=None):
343 media_selection = self._download_xml(
344 url, programme_id, 'Downloading media selection XML')
345 except ExtractorError as ee:
346 if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
347 media_selection = xml.etree.ElementTree.fromstring(ee.cause.read().decode('utf-8'))
350 return self._process_media_selector(media_selection, programme_id)
352 def _process_media_selector(self, media_selection, programme_id):
356 for media in self._extract_medias(media_selection):
357 kind = media.get('kind')
359 formats.extend(self._extract_audio(media, programme_id))
360 elif kind == 'video':
361 formats.extend(self._extract_video(media, programme_id))
362 elif kind == 'captions':
363 subtitles = self.extract_subtitles(media, programme_id)
364 return formats, subtitles
366 def _download_playlist(self, playlist_id):
368 playlist = self._download_json(
369 'http://www.bbc.co.uk/programmes/%s/playlist.json' % playlist_id,
370 playlist_id, 'Downloading playlist JSON')
372 version = playlist.get('defaultAvailableVersion')
374 smp_config = version['smpConfig']
375 title = smp_config['title']
376 description = smp_config['summary']
377 for item in smp_config['items']:
379 if kind != 'programme' and kind != 'radioProgramme':
381 programme_id = item.get('vpid')
382 duration = int_or_none(item.get('duration'))
383 formats, subtitles = self._download_media_selector(programme_id)
384 return programme_id, title, description, duration, formats, subtitles
385 except ExtractorError as ee:
386 if not (isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 404):
389 # fallback to legacy playlist
390 return self._process_legacy_playlist(playlist_id)
392 def _process_legacy_playlist_url(self, url, display_id):
393 playlist = self._download_legacy_playlist_url(url, display_id)
394 return self._extract_from_legacy_playlist(playlist, display_id)
396 def _process_legacy_playlist(self, playlist_id):
397 return self._process_legacy_playlist_url(
398 'http://www.bbc.co.uk/iplayer/playlist/%s' % playlist_id, playlist_id)
400 def _download_legacy_playlist_url(self, url, playlist_id=None):
401 return self._download_xml(
402 url, playlist_id, 'Downloading legacy playlist XML')
404 def _extract_from_legacy_playlist(self, playlist, playlist_id):
405 no_items = playlist.find('./{%s}noItems' % self._EMP_PLAYLIST_NS)
406 if no_items is not None:
407 reason = no_items.get('reason')
408 if reason == 'preAvailability':
409 msg = 'Episode %s is not yet available' % playlist_id
410 elif reason == 'postAvailability':
411 msg = 'Episode %s is no longer available' % playlist_id
412 elif reason == 'noMedia':
413 msg = 'Episode %s is not currently available' % playlist_id
415 msg = 'Episode %s is not available: %s' % (playlist_id, reason)
416 raise ExtractorError(msg, expected=True)
418 for item in self._extract_items(playlist):
419 kind = item.get('kind')
420 if kind != 'programme' and kind != 'radioProgramme':
422 title = playlist.find('./{%s}title' % self._EMP_PLAYLIST_NS).text
423 description_el = playlist.find('./{%s}summary' % self._EMP_PLAYLIST_NS)
424 description = description_el.text if description_el is not None else None
426 def get_programme_id(item):
427 def get_from_attributes(item):
428 for p in('identifier', 'group'):
430 if value and re.match(r'^[pb][\da-z]{7}$', value):
432 get_from_attributes(item)
433 mediator = item.find('./{%s}mediator' % self._EMP_PLAYLIST_NS)
434 if mediator is not None:
435 return get_from_attributes(mediator)
437 programme_id = get_programme_id(item)
438 duration = int_or_none(item.get('duration'))
441 formats, subtitles = self._download_media_selector(programme_id)
443 formats, subtitles = self._process_media_selector(item, playlist_id)
444 programme_id = playlist_id
446 return programme_id, title, description, duration, formats, subtitles
448 def _real_extract(self, url):
449 group_id = self._match_id(url)
451 webpage = self._download_webpage(url, group_id, 'Downloading video page')
455 tviplayer = self._search_regex(
456 r'mediator\.bind\(({.+?})\s*,\s*document\.getElementById',
457 webpage, 'player', default=None)
460 player = self._parse_json(tviplayer, group_id).get('player', {})
461 duration = int_or_none(player.get('duration'))
462 programme_id = player.get('vpid')
465 programme_id = self._search_regex(
466 r'"vpid"\s*:\s*"([\da-z]{8})"', webpage, 'vpid', fatal=False, default=None)
469 formats, subtitles = self._download_media_selector(programme_id)
470 title = self._og_search_title(webpage)
471 description = self._search_regex(
472 r'<p class="[^"]*medium-description[^"]*">([^<]+)</p>',
473 webpage, 'description', fatal=False)
475 programme_id, title, description, duration, formats, subtitles = self._download_playlist(group_id)
477 self._sort_formats(formats)
482 'description': description,
483 'thumbnail': self._og_search_thumbnail(webpage, default=None),
484 'duration': duration,
486 'subtitles': subtitles,
490 class BBCIE(BBCCoUkIE):
493 _VALID_URL = r'https?://(?:www\.)?bbc\.(?:com|co\.uk)/(?:[^/]+/)+(?P<id>[^/#?]+)'
495 _MEDIASELECTOR_URLS = [
496 # Provides HQ HLS streams but fails with geolocation in some cases when it's
497 # even not geo restricted at all
498 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/iptv-all/vpid/%s',
499 # Provides more formats, namely direct mp4 links, but fails on some videos with
500 # notukerror for non UK (?) users (e.g.
501 # http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret)
502 'http://open.live.bbc.co.uk/mediaselector/4/mtis/stream/%s',
503 # Provides fewer formats, but works everywhere for everybody (hopefully)
504 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/journalism-pc/vpid/%s',
508 # article with multiple videos embedded with data-playable containing vpids
509 'url': 'http://www.bbc.com/news/world-europe-32668511',
511 'id': 'world-europe-32668511',
512 'title': 'Russia stages massive WW2 parade despite Western boycott',
513 'description': 'md5:00ff61976f6081841f759a08bf78cc9c',
517 # article with multiple videos embedded with data-playable (more videos)
518 'url': 'http://www.bbc.com/news/business-28299555',
520 'id': 'business-28299555',
521 'title': 'Farnborough Airshow: Video highlights',
522 'description': 'BBC reports and video highlights at the Farnborough Airshow.',
527 # article with multiple videos embedded with `new SMP()`
529 'url': 'http://www.bbc.co.uk/blogs/adamcurtis/entries/3662a707-0af9-3149-963f-47bea720b460',
531 'id': '3662a707-0af9-3149-963f-47bea720b460',
532 'title': 'BBC Blogs - Adam Curtis - BUGGER',
534 'playlist_count': 18,
536 # single video embedded with data-playable containing vpid
537 'url': 'http://www.bbc.com/news/world-europe-32041533',
541 'title': 'Aerial footage showed the site of the crash in the Alps - courtesy BFM TV',
542 'description': 'md5:2868290467291b37feda7863f7a83f54',
544 'timestamp': 1427219242,
545 'upload_date': '20150324',
549 'skip_download': True,
552 # article with single video embedded with data-playable containing XML playlist
553 # with direct video links as progressiveDownloadUrl (for now these are extracted)
554 # and playlist with f4m and m3u8 as streamingUrl
555 'url': 'http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu',
557 'id': '150615_telabyad_kentin_cogu',
559 'title': "YPG: Tel Abyad'ın tamamı kontrolümüzde",
560 'timestamp': 1434397334,
561 'upload_date': '20150615',
564 'skip_download': True,
567 # single video embedded with data-playable containing XML playlists (regional section)
568 'url': 'http://www.bbc.com/mundo/video_fotos/2015/06/150619_video_honduras_militares_hospitales_corrupcion_aw',
570 'id': '150619_video_honduras_militares_hospitales_corrupcion_aw',
572 'title': 'Honduras militariza sus hospitales por nuevo escándalo de corrupción',
573 'timestamp': 1434713142,
574 'upload_date': '20150619',
577 'skip_download': True,
580 # single video from video playlist embedded with vxp-playlist-data JSON
581 'url': 'http://www.bbc.com/news/video_and_audio/must_see/33376376',
585 'title': '''Judge Mindy Glazer: "I'm sorry to see you here... I always wondered what happened to you"''',
589 'skip_download': True,
592 # single video story with digitalData
593 'url': 'http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret',
597 'title': 'Sri Lanka’s spicy secret',
598 'description': 'As a new train line to Jaffna opens up the country’s north, travellers can experience a truly distinct slice of Tamil culture.',
599 'timestamp': 1437674293,
600 'upload_date': '20150723',
604 'skip_download': True,
607 # single video story without digitalData
608 'url': 'http://www.bbc.com/autos/story/20130513-hyundais-rock-star',
612 'title': 'Hyundai Santa Fe Sport: Rock star',
613 'description': 'md5:b042a26142c4154a6e472933cf20793d',
614 'timestamp': 1415867444,
615 'upload_date': '20141113',
619 'skip_download': True,
622 # single video with playlist.sxml URL in playlist param
623 'url': 'http://www.bbc.com/sport/0/football/33653409',
627 'title': 'Transfers: Cristiano Ronaldo to Man Utd, Arsenal to spend?',
632 'skip_download': True,
635 # article with multiple videos embedded with playlist.sxml in playlist param
636 'url': 'http://www.bbc.com/sport/0/football/34475836',
639 'title': 'What Liverpool can expect from Klopp',
643 # single video with playlist URL from weather section
644 'url': 'http://www.bbc.com/weather/features/33601775',
645 'only_matching': True,
647 # custom redirection to www.bbc.com
648 'url': 'http://www.bbc.co.uk/news/science-environment-33661876',
649 'only_matching': True,
653 def suitable(cls, url):
654 return False if BBCCoUkIE.suitable(url) else super(BBCIE, cls).suitable(url)
656 def _extract_from_media_meta(self, media_meta, video_id):
657 # Direct links to media in media metadata (e.g.
658 # http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu)
659 # TODO: there are also f4m and m3u8 streams incorporated in playlist.sxml
660 source_files = media_meta.get('sourceFiles')
664 'format_id': format_id,
665 'ext': f.get('encoding'),
666 'tbr': float_or_none(f.get('bitrate'), 1000),
667 'filesize': int_or_none(f.get('filesize')),
668 } for format_id, f in source_files.items() if f.get('url')], []
670 programme_id = media_meta.get('externalId')
672 return self._download_media_selector(programme_id)
674 # Process playlist.sxml as legacy playlist
675 href = media_meta.get('href')
677 playlist = self._download_legacy_playlist_url(href)
678 _, _, _, _, formats, subtitles = self._extract_from_legacy_playlist(playlist, video_id)
679 return formats, subtitles
683 def _extract_from_playlist_sxml(self, url, playlist_id, timestamp):
684 programme_id, title, description, duration, formats, subtitles = \
685 self._process_legacy_playlist_url(url, playlist_id)
686 self._sort_formats(formats)
690 'description': description,
691 'duration': duration,
692 'timestamp': timestamp,
694 'subtitles': subtitles,
697 def _real_extract(self, url):
698 playlist_id = self._match_id(url)
700 webpage = self._download_webpage(url, playlist_id)
703 playlist_title = None
704 playlist_description = None
706 ld = self._parse_json(
708 r'(?s)<script type="application/ld\+json">(.+?)</script>',
709 webpage, 'ld json', default='{}'),
710 playlist_id, fatal=False)
712 timestamp = parse_iso8601(ld.get('datePublished'))
713 playlist_title = ld.get('headline')
714 playlist_description = ld.get('articleBody')
717 timestamp = parse_iso8601(self._search_regex(
718 [r'<meta[^>]+property="article:published_time"[^>]+content="([^"]+)"',
719 r'itemprop="datePublished"[^>]+datetime="([^"]+)"',
720 r'"datePublished":\s*"([^"]+)'],
721 webpage, 'date', default=None))
725 # article with multiple videos embedded with playlist.sxml (e.g.
726 # http://www.bbc.com/sport/0/football/34475836)
727 playlists = re.findall(r'<param[^>]+name="playlist"[^>]+value="([^"]+)"', webpage)
730 self._extract_from_playlist_sxml(playlist_url, playlist_id, timestamp)
731 for playlist_url in playlists]
733 # news article with multiple videos embedded with data-playable
734 data_playables = re.findall(r'data-playable=(["\'])({.+?})\1', webpage)
736 for _, data_playable_json in data_playables:
737 data_playable = self._parse_json(
738 unescapeHTML(data_playable_json), playlist_id, fatal=False)
739 if not data_playable:
741 settings = data_playable.get('settings', {})
743 # data-playable with video vpid in settings.playlistObject.items (e.g.
744 # http://www.bbc.com/news/world-us-canada-34473351)
745 playlist_object = settings.get('playlistObject', {})
747 items = playlist_object.get('items')
748 if items and isinstance(items, list):
749 title = playlist_object['title']
750 description = playlist_object.get('summary')
751 duration = int_or_none(items[0].get('duration'))
752 programme_id = items[0].get('vpid')
753 formats, subtitles = self._download_media_selector(programme_id)
754 self._sort_formats(formats)
758 'description': description,
759 'timestamp': timestamp,
760 'duration': duration,
762 'subtitles': subtitles,
765 # data-playable without vpid but with a playlist.sxml URLs
766 # in otherSettings.playlist (e.g.
767 # http://www.bbc.com/turkce/multimedya/2015/10/151010_vid_ankara_patlama_ani)
768 playlist = data_playable.get('otherSettings', {}).get('playlist', {})
770 entries.append(self._extract_from_playlist_sxml(
771 playlist.get('progressiveDownloadUrl'), playlist_id, timestamp))
774 playlist_title = playlist_title or remove_end(self._og_search_title(webpage), ' - BBC News')
775 playlist_description = playlist_description or self._og_search_description(webpage, default=None)
776 return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)
778 # single video story (e.g. http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret)
779 programme_id = self._search_regex(
780 [r'data-video-player-vpid="([\da-z]{8})"',
781 r'<param[^>]+name="externalIdentifier"[^>]+value="([\da-z]{8})"'],
782 webpage, 'vpid', default=None)
785 formats, subtitles = self._download_media_selector(programme_id)
786 self._sort_formats(formats)
787 # digitalData may be missing (e.g. http://www.bbc.com/autos/story/20130513-hyundais-rock-star)
788 digital_data = self._parse_json(
790 r'var\s+digitalData\s*=\s*({.+?});?\n', webpage, 'digital data', default='{}'),
791 programme_id, fatal=False)
792 page_info = digital_data.get('page', {}).get('pageInfo', {})
793 title = page_info.get('pageName') or self._og_search_title(webpage)
794 description = page_info.get('description') or self._og_search_description(webpage)
795 timestamp = parse_iso8601(page_info.get('publicationDate')) or timestamp
799 'description': description,
800 'timestamp': timestamp,
802 'subtitles': subtitles,
805 playlist_title = self._html_search_regex(
806 r'<title>(.*?)(?:\s*-\s*BBC [^ ]+)?</title>', webpage, 'playlist title')
807 playlist_description = self._og_search_description(webpage, default=None)
809 def extract_all(pattern):
810 return list(filter(None, map(
811 lambda s: self._parse_json(s, playlist_id, fatal=False),
812 re.findall(pattern, webpage))))
814 # Multiple video article (e.g.
815 # http://www.bbc.co.uk/blogs/adamcurtis/entries/3662a707-0af9-3149-963f-47bea720b460)
816 EMBED_URL = r'https?://(?:www\.)?bbc\.co\.uk/(?:[^/]+/)+[\da-z]{8}(?:\b[^"]+)?'
818 for match in extract_all(r'new\s+SMP\(({.+?})\)'):
819 embed_url = match.get('playerSettings', {}).get('externalEmbedUrl')
820 if embed_url and re.match(EMBED_URL, embed_url):
821 entries.append(embed_url)
822 entries.extend(re.findall(
823 r'setPlaylist\("(%s)"\)' % EMBED_URL, webpage))
825 return self.playlist_result(
826 [self.url_result(entry, 'BBCCoUk') for entry in entries],
827 playlist_id, playlist_title, playlist_description)
829 # Multiple video article (e.g. http://www.bbc.com/news/world-europe-32668511)
830 medias = extract_all(r"data-media-meta='({[^']+})'")
833 # Single video article (e.g. http://www.bbc.com/news/video_and_audio/international)
834 media_asset = self._search_regex(
835 r'mediaAssetPage\.init\(\s*({.+?}), "/',
836 webpage, 'media asset', default=None)
838 media_asset_page = self._parse_json(media_asset, playlist_id, fatal=False)
840 for video in media_asset_page.get('videos', {}).values():
841 medias.extend(video.values())
844 # Multiple video playlist with single `now playing` entry (e.g.
845 # http://www.bbc.com/news/video_and_audio/must_see/33767813)
846 vxp_playlist = self._parse_json(
848 r'<script[^>]+class="vxp-playlist-data"[^>]+type="application/json"[^>]*>([^<]+)</script>',
849 webpage, 'playlist data'),
852 for item in vxp_playlist:
853 media = item.get('media')
856 playlist_medias.append(media)
857 # Download single video if found media with asset id matching the video id from URL
858 if item.get('advert', {}).get('assetId') == playlist_id:
861 # Fallback to the whole playlist
863 medias = playlist_medias
866 for num, media_meta in enumerate(medias, start=1):
867 formats, subtitles = self._extract_from_media_meta(media_meta, playlist_id)
870 self._sort_formats(formats)
872 video_id = media_meta.get('externalId')
874 video_id = playlist_id if len(medias) == 1 else '%s-%s' % (playlist_id, num)
876 title = media_meta.get('caption')
878 title = playlist_title if len(medias) == 1 else '%s - Video %s' % (playlist_title, num)
880 duration = int_or_none(media_meta.get('durationInSeconds')) or parse_duration(media_meta.get('duration'))
883 for image in media_meta.get('images', {}).values():
884 images.extend(image.values())
885 if 'image' in media_meta:
886 images.append(media_meta['image'])
889 'url': image.get('href'),
890 'width': int_or_none(image.get('width')),
891 'height': int_or_none(image.get('height')),
892 } for image in images]
897 'thumbnails': thumbnails,
898 'duration': duration,
899 'timestamp': timestamp,
901 'subtitles': subtitles,
904 return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)