2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
15 from ..compat
import (
16 compat_etree_fromstring
,
21 class BBCCoUkIE(InfoExtractor
):
23 IE_DESC
= 'BBC iPlayer'
24 _ID_REGEX
= r
'[pb][\da-z]{7}'
27 (?:www\.)?bbc\.co\.uk/
29 programmes/(?!articles/)|
30 iplayer(?:/[^/]+)?/(?:episode/|playlist/)|
37 _MEDIASELECTOR_URLS
= [
38 # Provides HQ HLS streams with even better quality that pc mediaset but fails
39 # with geolocation in some cases when it's even not geo restricted at all (e.g.
40 # http://www.bbc.co.uk/programmes/b06bp7lf). Also may fail with selectionunavailable.
41 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/iptv-all/vpid/%s',
42 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/pc/vpid/%s',
45 _MEDIASELECTION_NS
= 'http://bbc.co.uk/2008/mp/mediaselection'
46 _EMP_PLAYLIST_NS
= 'http://bbc.co.uk/2008/emp/playlist'
55 'url': 'http://www.bbc.co.uk/programmes/b039g8p7',
59 'title': 'Leonard Cohen, Kaleidoscope - BBC Radio 4',
60 'description': 'The Canadian poet and songwriter reflects on his musical career.',
64 'skip_download': True,
68 'url': 'http://www.bbc.co.uk/iplayer/episode/b00yng5w/The_Man_in_Black_Series_3_The_Printed_Name/',
72 'title': 'The Man in Black: Series 3: The Printed Name',
73 'description': "Mark Gatiss introduces Nicholas Pierpan's chilling tale of a writer's devilish pact with a mysterious man. Stars Ewan Bailey.",
78 'skip_download': True,
80 'skip': 'Episode is no longer available on BBC iPlayer Radio',
83 'url': 'http://www.bbc.co.uk/iplayer/episode/b03vhd1f/The_Voice_UK_Series_3_Blind_Auditions_5/',
87 'title': 'The Voice UK: Series 3: Blind Auditions 5',
88 '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.',
93 'skip_download': True,
95 'skip': 'Currently BBC iPlayer TV programmes are available to play in the UK only',
98 'url': 'http://www.bbc.co.uk/iplayer/episode/p026c7jt/tomorrows-worlds-the-unearthly-history-of-science-fiction-2-invasion',
102 'title': "Tomorrow's Worlds: The Unearthly History of Science Fiction",
103 'description': '2. Invasion',
108 'skip_download': True,
110 'skip': 'Currently BBC iPlayer TV programmes are available to play in the UK only',
112 'url': 'http://www.bbc.co.uk/programmes/b04v20dw',
116 'title': 'Pete Tong, The Essential New Tune Special',
117 'description': "Pete has a very special mix - all of 2014's Essential New Tunes!",
122 'skip_download': True,
124 'skip': 'Episode is no longer available on BBC iPlayer Radio',
126 'url': 'http://www.bbc.co.uk/music/clips/p022h44b',
131 'title': 'BBC Proms Music Guides, Rachmaninov: Symphonic Dances',
132 'description': "In this Proms Music Guide, Andrew McGregor looks at Rachmaninov's Symphonic Dances.",
137 'skip_download': True,
140 'url': 'http://www.bbc.co.uk/music/clips/p025c0zz',
145 'title': 'Reading and Leeds Festival, 2014, Rae Morris - Closer (Live on BBC Three)',
146 'description': 'Rae Morris performs Closer for BBC Three at Reading 2014',
151 'skip_download': True,
154 'url': 'http://www.bbc.co.uk/iplayer/episode/b054fn09/ad/natural-world-20152016-2-super-powered-owls',
158 'title': 'Natural World, 2015-2016: 2. Super Powered Owls',
159 'description': 'md5:e4db5c937d0e95a7c6b5e654d429183d',
164 'skip_download': True,
166 'skip': 'geolocation',
168 'url': 'http://www.bbc.co.uk/iplayer/episode/b05zmgwn/royal-academy-summer-exhibition',
172 '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.',
173 'title': 'Royal Academy Summer Exhibition',
178 'skip_download': True,
180 'skip': 'geolocation',
182 # iptv-all mediaset fails with geolocation however there is no geo restriction
183 # for this programme at all
184 'url': 'http://www.bbc.co.uk/programmes/b06rkn85',
188 'title': "Best of the Mini-Mixes 2015: Part 3, Annie Mac's Friday Night - BBC Radio 1",
189 'description': "Annie has part three in the Best of the Mini-Mixes 2015, plus the year's Most Played!",
193 'skip_download': True,
196 # compact player (https://github.com/rg3/youtube-dl/issues/8147)
197 'url': 'http://www.bbc.co.uk/programmes/p028bfkf/player',
201 'title': 'Extract from BBC documentary Look Stranger - Giant Leeks and Magic Brews',
202 'description': 'Extract from BBC documentary Look Stranger - Giant Leeks and Magic Brews',
206 'skip_download': True,
209 'url': 'http://www.bbc.co.uk/iplayer/playlist/p01dvks4',
210 'only_matching': True,
212 'url': 'http://www.bbc.co.uk/music/clips#p02frcc3',
213 'only_matching': True,
215 'url': 'http://www.bbc.co.uk/iplayer/cbeebies/episode/b0480276/bing-14-atchoo',
216 'only_matching': True,
218 'url': 'http://www.bbc.co.uk/radio/player/p03cchwf',
219 'only_matching': True,
223 class MediaSelectionError(Exception):
224 def __init__(self
, id):
227 def _extract_asx_playlist(self
, connection
, programme_id
):
228 asx
= self
._download
_xml
(connection
.get('href'), programme_id
, 'Downloading ASX playlist')
229 return [ref
.get('href') for ref
in asx
.findall('./Entry/ref')]
231 def _extract_connection(self
, connection
, programme_id
):
233 kind
= connection
.get('kind')
234 protocol
= connection
.get('protocol')
235 supplier
= connection
.get('supplier')
236 if protocol
== 'http':
237 href
= connection
.get('href')
238 transfer_format
= connection
.get('transferFormat')
240 if supplier
== 'asx':
241 for i
, ref
in enumerate(self
._extract
_asx
_playlist
(connection
, programme_id
)):
244 'format_id': 'ref%s_%s' % (i
, supplier
),
246 # Skip DASH until supported
247 elif transfer_format
== 'dash':
249 elif transfer_format
== 'hls':
250 formats
.extend(self
._extract
_m
3u8_formats
(
251 href
, programme_id
, ext
='mp4', entry_protocol
='m3u8_native',
252 m3u8_id
=supplier
, fatal
=False))
257 'format_id': supplier
or kind
or protocol
,
259 elif protocol
== 'rtmp':
260 application
= connection
.get('application', 'ondemand')
261 auth_string
= connection
.get('authString')
262 identifier
= connection
.get('identifier')
263 server
= connection
.get('server')
265 'url': '%s://%s/%s?%s' % (protocol
, server
, application
, auth_string
),
266 'play_path': identifier
,
267 'app': '%s?%s' % (application
, auth_string
),
268 'page_url': 'http://www.bbc.co.uk',
269 'player_url': 'http://www.bbc.co.uk/emp/releases/iplayer/revisions/617463_618125_4/617463_618125_4_emp.swf',
272 'format_id': supplier
,
276 def _extract_items(self
, playlist
):
277 return playlist
.findall('./{%s}item' % self
._EMP
_PLAYLIST
_NS
)
279 def _findall_ns(self
, element
, xpath
):
281 for ns
in self
._NAMESPACES
:
282 elements
.extend(element
.findall(xpath
% ns
))
285 def _extract_medias(self
, media_selection
):
286 error
= media_selection
.find('./{%s}error' % self
._MEDIASELECTION
_NS
)
288 media_selection
.find('./{%s}error' % self
._EMP
_PLAYLIST
_NS
)
289 if error
is not None:
290 raise BBCCoUkIE
.MediaSelectionError(error
.get('id'))
291 return self
._findall
_ns
(media_selection
, './{%s}media')
293 def _extract_connections(self
, media
):
294 return self
._findall
_ns
(media
, './{%s}connection')
296 def _extract_video(self
, media
, programme_id
):
298 vbr
= int_or_none(media
.get('bitrate'))
299 vcodec
= media
.get('encoding')
300 service
= media
.get('service')
301 width
= int_or_none(media
.get('width'))
302 height
= int_or_none(media
.get('height'))
303 file_size
= int_or_none(media
.get('media_file_size'))
304 for connection
in self
._extract
_connections
(media
):
305 conn_formats
= self
._extract
_connection
(connection
, programme_id
)
306 for format
in conn_formats
:
312 'filesize': file_size
,
315 format
['format_id'] = '%s_%s' % (service
, format
['format_id'])
316 formats
.extend(conn_formats
)
319 def _extract_audio(self
, media
, programme_id
):
321 abr
= int_or_none(media
.get('bitrate'))
322 acodec
= media
.get('encoding')
323 service
= media
.get('service')
324 for connection
in self
._extract
_connections
(media
):
325 conn_formats
= self
._extract
_connection
(connection
, programme_id
)
326 for format
in conn_formats
:
328 'format_id': '%s_%s' % (service
, format
['format_id']),
332 formats
.extend(conn_formats
)
335 def _get_subtitles(self
, media
, programme_id
):
337 for connection
in self
._extract
_connections
(media
):
338 captions
= self
._download
_xml
(connection
.get('href'), programme_id
, 'Downloading captions')
339 lang
= captions
.get('{http://www.w3.org/XML/1998/namespace}lang', 'en')
342 'url': connection
.get('href'),
348 def _raise_extractor_error(self
, media_selection_error
):
349 raise ExtractorError(
350 '%s returned error: %s' % (self
.IE_NAME
, media_selection_error
.id),
353 def _download_media_selector(self
, programme_id
):
354 last_exception
= None
355 for mediaselector_url
in self
._MEDIASELECTOR
_URLS
:
357 return self
._download
_media
_selector
_url
(
358 mediaselector_url
% programme_id
, programme_id
)
359 except BBCCoUkIE
.MediaSelectionError
as e
:
360 if e
.id in ('notukerror', 'geolocation', 'selectionunavailable'):
363 self
._raise
_extractor
_error
(e
)
364 self
._raise
_extractor
_error
(last_exception
)
366 def _download_media_selector_url(self
, url
, programme_id
=None):
368 media_selection
= self
._download
_xml
(
369 url
, programme_id
, 'Downloading media selection XML')
370 except ExtractorError
as ee
:
371 if isinstance(ee
.cause
, compat_HTTPError
) and ee
.cause
.code
in (403, 404):
372 media_selection
= compat_etree_fromstring(ee
.cause
.read().decode('utf-8'))
375 return self
._process
_media
_selector
(media_selection
, programme_id
)
377 def _process_media_selector(self
, media_selection
, programme_id
):
381 for media
in self
._extract
_medias
(media_selection
):
382 kind
= media
.get('kind')
384 formats
.extend(self
._extract
_audio
(media
, programme_id
))
385 elif kind
== 'video':
386 formats
.extend(self
._extract
_video
(media
, programme_id
))
387 elif kind
== 'captions':
388 subtitles
= self
.extract_subtitles(media
, programme_id
)
389 return formats
, subtitles
391 def _download_playlist(self
, playlist_id
):
393 playlist
= self
._download
_json
(
394 'http://www.bbc.co.uk/programmes/%s/playlist.json' % playlist_id
,
395 playlist_id
, 'Downloading playlist JSON')
397 version
= playlist
.get('defaultAvailableVersion')
399 smp_config
= version
['smpConfig']
400 title
= smp_config
['title']
401 description
= smp_config
['summary']
402 for item
in smp_config
['items']:
404 if kind
!= 'programme' and kind
!= 'radioProgramme':
406 programme_id
= item
.get('vpid')
407 duration
= int_or_none(item
.get('duration'))
408 formats
, subtitles
= self
._download
_media
_selector
(programme_id
)
409 return programme_id
, title
, description
, duration
, formats
, subtitles
410 except ExtractorError
as ee
:
411 if not (isinstance(ee
.cause
, compat_HTTPError
) and ee
.cause
.code
== 404):
414 # fallback to legacy playlist
415 return self
._process
_legacy
_playlist
(playlist_id
)
417 def _process_legacy_playlist_url(self
, url
, display_id
):
418 playlist
= self
._download
_legacy
_playlist
_url
(url
, display_id
)
419 return self
._extract
_from
_legacy
_playlist
(playlist
, display_id
)
421 def _process_legacy_playlist(self
, playlist_id
):
422 return self
._process
_legacy
_playlist
_url
(
423 'http://www.bbc.co.uk/iplayer/playlist/%s' % playlist_id
, playlist_id
)
425 def _download_legacy_playlist_url(self
, url
, playlist_id
=None):
426 return self
._download
_xml
(
427 url
, playlist_id
, 'Downloading legacy playlist XML')
429 def _extract_from_legacy_playlist(self
, playlist
, playlist_id
):
430 no_items
= playlist
.find('./{%s}noItems' % self
._EMP
_PLAYLIST
_NS
)
431 if no_items
is not None:
432 reason
= no_items
.get('reason')
433 if reason
== 'preAvailability':
434 msg
= 'Episode %s is not yet available' % playlist_id
435 elif reason
== 'postAvailability':
436 msg
= 'Episode %s is no longer available' % playlist_id
437 elif reason
== 'noMedia':
438 msg
= 'Episode %s is not currently available' % playlist_id
440 msg
= 'Episode %s is not available: %s' % (playlist_id
, reason
)
441 raise ExtractorError(msg
, expected
=True)
443 for item
in self
._extract
_items
(playlist
):
444 kind
= item
.get('kind')
445 if kind
!= 'programme' and kind
!= 'radioProgramme':
447 title
= playlist
.find('./{%s}title' % self
._EMP
_PLAYLIST
_NS
).text
448 description_el
= playlist
.find('./{%s}summary' % self
._EMP
_PLAYLIST
_NS
)
449 description
= description_el
.text
if description_el
is not None else None
451 def get_programme_id(item
):
452 def get_from_attributes(item
):
453 for p
in('identifier', 'group'):
455 if value
and re
.match(r
'^[pb][\da-z]{7}$', value
):
457 get_from_attributes(item
)
458 mediator
= item
.find('./{%s}mediator' % self
._EMP
_PLAYLIST
_NS
)
459 if mediator
is not None:
460 return get_from_attributes(mediator
)
462 programme_id
= get_programme_id(item
)
463 duration
= int_or_none(item
.get('duration'))
466 formats
, subtitles
= self
._download
_media
_selector
(programme_id
)
468 formats
, subtitles
= self
._process
_media
_selector
(item
, playlist_id
)
469 programme_id
= playlist_id
471 return programme_id
, title
, description
, duration
, formats
, subtitles
473 def _real_extract(self
, url
):
474 group_id
= self
._match
_id
(url
)
476 webpage
= self
._download
_webpage
(url
, group_id
, 'Downloading video page')
481 tviplayer
= self
._search
_regex
(
482 r
'mediator\.bind\(({.+?})\s*,\s*document\.getElementById',
483 webpage
, 'player', default
=None)
486 player
= self
._parse
_json
(tviplayer
, group_id
).get('player', {})
487 duration
= int_or_none(player
.get('duration'))
488 programme_id
= player
.get('vpid')
491 programme_id
= self
._search
_regex
(
492 r
'"vpid"\s*:\s*"(%s)"' % self
._ID
_REGEX
, webpage
, 'vpid', fatal
=False, default
=None)
495 formats
, subtitles
= self
._download
_media
_selector
(programme_id
)
496 title
= self
._og
_search
_title
(webpage
, default
=None) or self
._html
_search
_regex
(
497 (r
'<h2[^>]+id="parent-title"[^>]*>(.+?)</h2>',
498 r
'<div[^>]+class="info"[^>]*>\s*<h1>(.+?)</h1>'), webpage
, 'title')
499 description
= self
._search
_regex
(
500 (r
'<p class="[^"]*medium-description[^"]*">([^<]+)</p>',
501 r
'<div[^>]+class="info_+synopsis"[^>]*>([^<]+)</div>'),
502 webpage
, 'description', default
=None)
504 description
= self
._html
_search
_meta
('description', webpage
)
506 programme_id
, title
, description
, duration
, formats
, subtitles
= self
._download
_playlist
(group_id
)
508 self
._sort
_formats
(formats
)
513 'description': description
,
514 'thumbnail': self
._og
_search
_thumbnail
(webpage
, default
=None),
515 'duration': duration
,
517 'subtitles': subtitles
,
521 class BBCIE(BBCCoUkIE
):
524 _VALID_URL
= r
'https?://(?:www\.)?bbc\.(?:com|co\.uk)/(?:[^/]+/)+(?P<id>[^/#?]+)'
526 _MEDIASELECTOR_URLS
= [
527 # Provides HQ HLS streams but fails with geolocation in some cases when it's
528 # even not geo restricted at all
529 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/iptv-all/vpid/%s',
530 # Provides more formats, namely direct mp4 links, but fails on some videos with
531 # notukerror for non UK (?) users (e.g.
532 # http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret)
533 'http://open.live.bbc.co.uk/mediaselector/4/mtis/stream/%s',
534 # Provides fewer formats, but works everywhere for everybody (hopefully)
535 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/journalism-pc/vpid/%s',
539 # article with multiple videos embedded with data-playable containing vpids
540 'url': 'http://www.bbc.com/news/world-europe-32668511',
542 'id': 'world-europe-32668511',
543 'title': 'Russia stages massive WW2 parade despite Western boycott',
544 'description': 'md5:00ff61976f6081841f759a08bf78cc9c',
548 # article with multiple videos embedded with data-playable (more videos)
549 'url': 'http://www.bbc.com/news/business-28299555',
551 'id': 'business-28299555',
552 'title': 'Farnborough Airshow: Video highlights',
553 'description': 'BBC reports and video highlights at the Farnborough Airshow.',
558 # article with multiple videos embedded with `new SMP()`
560 'url': 'http://www.bbc.co.uk/blogs/adamcurtis/entries/3662a707-0af9-3149-963f-47bea720b460',
562 'id': '3662a707-0af9-3149-963f-47bea720b460',
565 'playlist_count': 18,
567 # single video embedded with data-playable containing vpid
568 'url': 'http://www.bbc.com/news/world-europe-32041533',
572 'title': 'Aerial footage showed the site of the crash in the Alps - courtesy BFM TV',
573 'description': 'md5:2868290467291b37feda7863f7a83f54',
575 'timestamp': 1427219242,
576 'upload_date': '20150324',
580 'skip_download': True,
583 # article with single video embedded with data-playable containing XML playlist
584 # with direct video links as progressiveDownloadUrl (for now these are extracted)
585 # and playlist with f4m and m3u8 as streamingUrl
586 'url': 'http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu',
588 'id': '150615_telabyad_kentin_cogu',
590 'title': "YPG: Tel Abyad'ın tamamı kontrolümüzde",
591 'timestamp': 1434397334,
592 'upload_date': '20150615',
595 'skip_download': True,
598 # single video embedded with data-playable containing XML playlists (regional section)
599 'url': 'http://www.bbc.com/mundo/video_fotos/2015/06/150619_video_honduras_militares_hospitales_corrupcion_aw',
601 'id': '150619_video_honduras_militares_hospitales_corrupcion_aw',
603 'title': 'Honduras militariza sus hospitales por nuevo escándalo de corrupción',
604 'timestamp': 1434713142,
605 'upload_date': '20150619',
608 'skip_download': True,
611 # single video from video playlist embedded with vxp-playlist-data JSON
612 'url': 'http://www.bbc.com/news/video_and_audio/must_see/33376376',
616 'title': '''Judge Mindy Glazer: "I'm sorry to see you here... I always wondered what happened to you"''',
618 'description': '''Judge Mindy Glazer: "I'm sorry to see you here... I always wondered what happened to you"''',
621 'skip_download': True,
624 # single video story with digitalData
625 'url': 'http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret',
629 'title': 'Sri Lanka’s spicy secret',
630 'description': 'As a new train line to Jaffna opens up the country’s north, travellers can experience a truly distinct slice of Tamil culture.',
631 'timestamp': 1437674293,
632 'upload_date': '20150723',
636 'skip_download': True,
639 # single video story without digitalData
640 'url': 'http://www.bbc.com/autos/story/20130513-hyundais-rock-star',
644 'title': 'Hyundai Santa Fe Sport: Rock star',
645 'description': 'md5:b042a26142c4154a6e472933cf20793d',
646 'timestamp': 1415867444,
647 'upload_date': '20141113',
651 'skip_download': True,
654 # single video with playlist.sxml URL in playlist param
655 'url': 'http://www.bbc.com/sport/0/football/33653409',
659 'title': 'Transfers: Cristiano Ronaldo to Man Utd, Arsenal to spend?',
660 'description': 'BBC Sport\'s David Ornstein has the latest transfer gossip, including rumours of a Manchester United return for Cristiano Ronaldo.',
665 'skip_download': True,
668 # article with multiple videos embedded with playlist.sxml in playlist param
669 'url': 'http://www.bbc.com/sport/0/football/34475836',
672 'title': 'Jurgen Klopp: Furious football from a witty and winning coach',
676 # school report article with single video
677 'url': 'http://www.bbc.co.uk/schoolreport/35744779',
680 'title': 'School which breaks down barriers in Jerusalem',
684 # single video with playlist URL from weather section
685 'url': 'http://www.bbc.com/weather/features/33601775',
686 'only_matching': True,
688 # custom redirection to www.bbc.com
689 'url': 'http://www.bbc.co.uk/news/science-environment-33661876',
690 'only_matching': True,
694 def suitable(cls
, url
):
695 return False if BBCCoUkIE
.suitable(url
) or BBCCoUkArticleIE
.suitable(url
) else super(BBCIE
, cls
).suitable(url
)
697 def _extract_from_media_meta(self
, media_meta
, video_id
):
698 # Direct links to media in media metadata (e.g.
699 # http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu)
700 # TODO: there are also f4m and m3u8 streams incorporated in playlist.sxml
701 source_files
= media_meta
.get('sourceFiles')
705 'format_id': format_id
,
706 'ext': f
.get('encoding'),
707 'tbr': float_or_none(f
.get('bitrate'), 1000),
708 'filesize': int_or_none(f
.get('filesize')),
709 } for format_id
, f
in source_files
.items() if f
.get('url')], []
711 programme_id
= media_meta
.get('externalId')
713 return self
._download
_media
_selector
(programme_id
)
715 # Process playlist.sxml as legacy playlist
716 href
= media_meta
.get('href')
718 playlist
= self
._download
_legacy
_playlist
_url
(href
)
719 _
, _
, _
, _
, formats
, subtitles
= self
._extract
_from
_legacy
_playlist
(playlist
, video_id
)
720 return formats
, subtitles
724 def _extract_from_playlist_sxml(self
, url
, playlist_id
, timestamp
):
725 programme_id
, title
, description
, duration
, formats
, subtitles
= \
726 self
._process
_legacy
_playlist
_url
(url
, playlist_id
)
727 self
._sort
_formats
(formats
)
731 'description': description
,
732 'duration': duration
,
733 'timestamp': timestamp
,
735 'subtitles': subtitles
,
738 def _real_extract(self
, url
):
739 playlist_id
= self
._match
_id
(url
)
741 webpage
= self
._download
_webpage
(url
, playlist_id
)
743 json_ld_info
= self
._search
_json
_ld
(webpage
, playlist_id
, default
=None)
744 timestamp
= json_ld_info
.get('timestamp')
746 playlist_title
= json_ld_info
.get('title')
747 if not playlist_title
:
748 playlist_title
= self
._og
_search
_title
(
749 webpage
, default
=None) or self
._html
_search
_regex
(
750 r
'<title>(.+?)</title>', webpage
, 'playlist title', default
=None)
752 playlist_title
= re
.sub(r
'(.+)\s*-\s*BBC.*?$', r
'\1', playlist_title
).strip()
754 playlist_description
= json_ld_info
.get(
755 'description') or self
._og
_search
_description
(webpage
, default
=None)
758 timestamp
= parse_iso8601(self
._search
_regex
(
759 [r
'<meta[^>]+property="article:published_time"[^>]+content="([^"]+)"',
760 r
'itemprop="datePublished"[^>]+datetime="([^"]+)"',
761 r
'"datePublished":\s*"([^"]+)'],
762 webpage
, 'date', default
=None))
766 # article with multiple videos embedded with playlist.sxml (e.g.
767 # http://www.bbc.com/sport/0/football/34475836)
768 playlists
= re
.findall(r
'<param[^>]+name="playlist"[^>]+value="([^"]+)"', webpage
)
769 playlists
.extend(re
.findall(r
'data-media-id="([^"]+/playlist\.sxml)"', webpage
))
772 self
._extract
_from
_playlist
_sxml
(playlist_url
, playlist_id
, timestamp
)
773 for playlist_url
in playlists
]
775 # news article with multiple videos embedded with data-playable
776 data_playables
= re
.findall(r
'data-playable=(["\'])({.+?}
)\
1', webpage)
778 for _, data_playable_json in data_playables:
779 data_playable = self._parse_json(
780 unescapeHTML(data_playable_json), playlist_id, fatal=False)
781 if not data_playable:
783 settings = data_playable.get('settings
', {})
785 # data-playable with video vpid in settings.playlistObject.items (e.g.
786 # http://www.bbc.com/news/world-us-canada-34473351)
787 playlist_object = settings.get('playlistObject
', {})
789 items = playlist_object.get('items
')
790 if items and isinstance(items, list):
791 title = playlist_object['title
']
792 description = playlist_object.get('summary
')
793 duration = int_or_none(items[0].get('duration
'))
794 programme_id = items[0].get('vpid
')
795 formats, subtitles = self._download_media_selector(programme_id)
796 self._sort_formats(formats)
800 'description
': description,
801 'timestamp
': timestamp,
802 'duration
': duration,
804 'subtitles
': subtitles,
807 # data-playable without vpid but with a playlist.sxml URLs
808 # in otherSettings.playlist (e.g.
809 # http://www.bbc.com/turkce/multimedya/2015/10/151010_vid_ankara_patlama_ani)
810 playlist = data_playable.get('otherSettings
', {}).get('playlist', {})
812 entries.append(self._extract_from_playlist_sxml(
813 playlist.get('progressiveDownloadUrl
'), playlist_id, timestamp))
816 return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)
818 # single video story (e.g. http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret)
819 programme_id = self._search_regex(
820 [r'data
-video
-player
-vpid
="(%s)"' % self._ID_REGEX,
821 r'<param
[^
>]+name
="externalIdentifier"[^
>]+value
="(%s)"' % self._ID_REGEX,
822 r'videoId\s
*:\s
*["\'](%s)["\']' % self._ID_REGEX],
823 webpage, 'vpid
', default=None)
826 formats, subtitles = self._download_media_selector(programme_id)
827 self._sort_formats(formats)
828 # digitalData may be missing (e.g. http://www.bbc.com/autos/story/20130513-hyundais-rock-star)
829 digital_data = self._parse_json(
831 r'var\s
+digitalData\s
*=\s
*({.+?}
);?
\n', webpage, 'digital data
', default='{}'),
832 programme_id, fatal=False)
833 page_info = digital_data.get('page
', {}).get('pageInfo', {})
834 title = page_info.get('pageName
') or self._og_search_title(webpage)
835 description = page_info.get('description
') or self._og_search_description(webpage)
836 timestamp = parse_iso8601(page_info.get('publicationDate
')) or timestamp
840 'description
': description,
841 'timestamp
': timestamp,
843 'subtitles
': subtitles,
846 def extract_all(pattern):
847 return list(filter(None, map(
848 lambda s: self._parse_json(s, playlist_id, fatal=False),
849 re.findall(pattern, webpage))))
851 # Multiple video article (e.g.
852 # http://www.bbc.co.uk/blogs/adamcurtis/entries/3662a707-0af9-3149-963f-47bea720b460)
853 EMBED_URL = r'https?
://(?
:www\
.)?bbc\
.co\
.uk
/(?
:[^
/]+/)+%s(?
:\b[^
"]+)?' % self._ID_REGEX
855 for match in extract_all(r'new\s+SMP\(({.+?})\)'):
856 embed_url = match.get('playerSettings', {}).get('externalEmbedUrl')
857 if embed_url and re.match(EMBED_URL, embed_url):
858 entries.append(embed_url)
859 entries.extend(re.findall(
860 r'setPlaylist\("(%s)"\)' % EMBED_URL, webpage))
862 return self.playlist_result(
863 [self.url_result(entry, 'BBCCoUk') for entry in entries],
864 playlist_id, playlist_title, playlist_description)
866 # Multiple video article (e.g. http://www.bbc.com/news/world-europe-32668511)
867 medias = extract_all(r"data
-media
-meta
='({[^']+})'")
870 # Single video article (e.g. http://www.bbc.com/news/video_and_audio/international)
871 media_asset = self._search_regex(
872 r'mediaAssetPage\.init\(\s*({.+?}), "/',
873 webpage, 'media asset
', default=None)
875 media_asset_page = self._parse_json(media_asset, playlist_id, fatal=False)
877 for video in media_asset_page.get('videos
', {}).values():
878 medias.extend(video.values())
881 # Multiple video playlist with single `now playing` entry (e.g.
882 # http://www.bbc.com/news/video_and_audio/must_see/33767813)
883 vxp_playlist = self._parse_json(
885 r'<script
[^
>]+class="vxp-playlist-data"[^
>]+type="application/json"[^
>]*>([^
<]+)</script
>',
886 webpage, 'playlist data
'),
889 for item in vxp_playlist:
890 media = item.get('media
')
893 playlist_medias.append(media)
894 # Download single video if found media with asset id matching the video id from URL
895 if item.get('advert
', {}).get('assetId
') == playlist_id:
898 # Fallback to the whole playlist
900 medias = playlist_medias
903 for num, media_meta in enumerate(medias, start=1):
904 formats, subtitles = self._extract_from_media_meta(media_meta, playlist_id)
907 self._sort_formats(formats)
909 video_id = media_meta.get('externalId
')
911 video_id = playlist_id if len(medias) == 1 else '%s-%s' % (playlist_id, num)
913 title = media_meta.get('caption
')
915 title = playlist_title if len(medias) == 1 else '%s - Video
%s' % (playlist_title, num)
917 duration = int_or_none(media_meta.get('durationInSeconds
')) or parse_duration(media_meta.get('duration
'))
920 for image in media_meta.get('images
', {}).values():
921 images.extend(image.values())
922 if 'image
' in media_meta:
923 images.append(media_meta['image
'])
926 'url
': image.get('href
'),
927 'width
': int_or_none(image.get('width
')),
928 'height
': int_or_none(image.get('height
')),
929 } for image in images]
934 'thumbnails
': thumbnails,
935 'duration
': duration,
936 'timestamp
': timestamp,
938 'subtitles
': subtitles,
941 return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)
944 class BBCCoUkArticleIE(InfoExtractor):
945 _VALID_URL = r'https?
://www
.bbc
.co
.uk
/programmes
/articles
/(?P
<id>[a
-zA
-Z0
-9]+)'
946 IE_NAME = 'bbc
.co
.uk
:article
'
947 IE_DESC = 'BBC articles
'
950 'url
': 'http
://www
.bbc
.co
.uk
/programmes
/articles
/3jNQLTMrPlYGTBn0WV6M2MS
/not-your
-typical
-role
-model
-ada
-lovelace
-the
-19th
-century
-programmer
',
952 'id': '3jNQLTMrPlYGTBn0WV6M2MS
',
953 'title
': 'Calculating Ada
: The Countess of Computing
- Not your typical role model
: Ada Lovelace the
19th century programmer
- BBC Four
',
954 'description
': 'Hannah Fry reveals some of her surprising discoveries about Ada Lovelace during filming
.',
957 'add_ie
': ['BBCCoUk
'],
960 def _real_extract(self, url):
961 playlist_id = self._match_id(url)
963 webpage = self._download_webpage(url, playlist_id)
965 title = self._og_search_title(webpage)
966 description = self._og_search_description(webpage).strip()
968 entries = [self.url_result(programme_url) for programme_url in re.findall(
969 r'<div
[^
>]+typeof
="Clip"[^
>]+resource
="([^"]+)"', webpage)]
971 return self.playlist_result(entries, playlist_id, title, description)