2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
16 from ..compat
import (
17 compat_etree_fromstring
,
22 class BBCCoUkIE(InfoExtractor
):
24 IE_DESC
= 'BBC iPlayer'
25 _ID_REGEX
= r
'[pb][\da-z]{7}'
26 _VALID_URL
= r
'https?://(?:www\.)?bbc\.co\.uk/(?:(?:programmes/(?!articles/)|iplayer(?:/[^/]+)?/(?:episode/|playlist/))|music/clips[/#])(?P<id>%s)' % _ID_REGEX
28 _MEDIASELECTOR_URLS
= [
29 # Provides HQ HLS streams with even better quality that pc mediaset but fails
30 # with geolocation in some cases when it's even not geo restricted at all (e.g.
31 # http://www.bbc.co.uk/programmes/b06bp7lf). Also may fail with selectionunavailable.
32 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/iptv-all/vpid/%s',
33 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/pc/vpid/%s',
36 _MEDIASELECTION_NS
= 'http://bbc.co.uk/2008/mp/mediaselection'
37 _EMP_PLAYLIST_NS
= 'http://bbc.co.uk/2008/emp/playlist'
46 'url': 'http://www.bbc.co.uk/programmes/b039g8p7',
50 'title': 'Kaleidoscope, Leonard Cohen',
51 'description': 'The Canadian poet and songwriter reflects on his musical career.',
56 'skip_download': True,
60 'url': 'http://www.bbc.co.uk/iplayer/episode/b00yng5w/The_Man_in_Black_Series_3_The_Printed_Name/',
64 'title': 'The Man in Black: Series 3: The Printed Name',
65 'description': "Mark Gatiss introduces Nicholas Pierpan's chilling tale of a writer's devilish pact with a mysterious man. Stars Ewan Bailey.",
70 'skip_download': True,
72 'skip': 'Episode is no longer available on BBC iPlayer Radio',
75 'url': 'http://www.bbc.co.uk/iplayer/episode/b03vhd1f/The_Voice_UK_Series_3_Blind_Auditions_5/',
79 'title': 'The Voice UK: Series 3: Blind Auditions 5',
80 '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.",
85 'skip_download': True,
87 'skip': 'Currently BBC iPlayer TV programmes are available to play in the UK only',
90 'url': 'http://www.bbc.co.uk/iplayer/episode/p026c7jt/tomorrows-worlds-the-unearthly-history-of-science-fiction-2-invasion',
94 'title': "Tomorrow's Worlds: The Unearthly History of Science Fiction",
95 'description': '2. Invasion',
100 'skip_download': True,
102 'skip': 'Currently BBC iPlayer TV programmes are available to play in the UK only',
104 'url': 'http://www.bbc.co.uk/programmes/b04v20dw',
108 'title': 'Pete Tong, The Essential New Tune Special',
109 'description': "Pete has a very special mix - all of 2014's Essential New Tunes!",
114 'skip_download': True,
117 'url': 'http://www.bbc.co.uk/music/clips/p02frcc3',
122 'title': 'Pete Tong, Past, Present and Future Special, Madeon - After Hours mix',
123 'description': 'French house superstar Madeon takes us out of the club and onto the after party.',
128 'skip_download': True,
131 'url': 'http://www.bbc.co.uk/music/clips/p025c0zz',
136 'title': 'Reading and Leeds Festival, 2014, Rae Morris - Closer (Live on BBC Three)',
137 'description': 'Rae Morris performs Closer for BBC Three at Reading 2014',
142 'skip_download': True,
145 'url': 'http://www.bbc.co.uk/iplayer/episode/b054fn09/ad/natural-world-20152016-2-super-powered-owls',
149 'title': 'Natural World, 2015-2016: 2. Super Powered Owls',
150 'description': 'md5:e4db5c937d0e95a7c6b5e654d429183d',
155 'skip_download': True,
157 'skip': 'geolocation',
159 'url': 'http://www.bbc.co.uk/iplayer/episode/b05zmgwn/royal-academy-summer-exhibition',
163 '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.',
164 'title': 'Royal Academy Summer Exhibition',
169 'skip_download': True,
171 'skip': 'geolocation',
173 # iptv-all mediaset fails with geolocation however there is no geo restriction
174 # for this programme at all
175 'url': 'http://www.bbc.co.uk/programmes/b06bp7lf',
179 'title': "Annie Mac's Friday Night, B.Traits sits in for Annie",
180 'description': 'B.Traits sits in for Annie Mac with a Mini-Mix from Disclosure.',
185 'skip_download': True,
188 'url': 'http://www.bbc.co.uk/iplayer/playlist/p01dvks4',
189 'only_matching': True,
191 'url': 'http://www.bbc.co.uk/music/clips#p02frcc3',
192 'only_matching': True,
194 'url': 'http://www.bbc.co.uk/iplayer/cbeebies/episode/b0480276/bing-14-atchoo',
195 'only_matching': True,
199 class MediaSelectionError(Exception):
200 def __init__(self
, id):
203 def _extract_asx_playlist(self
, connection
, programme_id
):
204 asx
= self
._download
_xml
(connection
.get('href'), programme_id
, 'Downloading ASX playlist')
205 return [ref
.get('href') for ref
in asx
.findall('./Entry/ref')]
207 def _extract_connection(self
, connection
, programme_id
):
209 kind
= connection
.get('kind')
210 protocol
= connection
.get('protocol')
211 supplier
= connection
.get('supplier')
212 if protocol
== 'http':
213 href
= connection
.get('href')
214 transfer_format
= connection
.get('transferFormat')
216 if supplier
== 'asx':
217 for i
, ref
in enumerate(self
._extract
_asx
_playlist
(connection
, programme_id
)):
220 'format_id': 'ref%s_%s' % (i
, supplier
),
222 # Skip DASH until supported
223 elif transfer_format
== 'dash':
225 elif transfer_format
== 'hls':
226 m3u8_formats
= self
._extract
_m
3u8_formats
(
227 href
, programme_id
, ext
='mp4', entry_protocol
='m3u8_native',
228 m3u8_id
=supplier
, fatal
=False)
230 formats
.extend(m3u8_formats
)
235 'format_id': supplier
or kind
or protocol
,
237 elif protocol
== 'rtmp':
238 application
= connection
.get('application', 'ondemand')
239 auth_string
= connection
.get('authString')
240 identifier
= connection
.get('identifier')
241 server
= connection
.get('server')
243 'url': '%s://%s/%s?%s' % (protocol
, server
, application
, auth_string
),
244 'play_path': identifier
,
245 'app': '%s?%s' % (application
, auth_string
),
246 'page_url': 'http://www.bbc.co.uk',
247 'player_url': 'http://www.bbc.co.uk/emp/releases/iplayer/revisions/617463_618125_4/617463_618125_4_emp.swf',
250 'format_id': supplier
,
254 def _extract_items(self
, playlist
):
255 return playlist
.findall('./{%s}item' % self
._EMP
_PLAYLIST
_NS
)
257 def _findall_ns(self
, element
, xpath
):
259 for ns
in self
._NAMESPACES
:
260 elements
.extend(element
.findall(xpath
% ns
))
263 def _extract_medias(self
, media_selection
):
264 error
= media_selection
.find('./{%s}error' % self
._MEDIASELECTION
_NS
)
266 media_selection
.find('./{%s}error' % self
._EMP
_PLAYLIST
_NS
)
267 if error
is not None:
268 raise BBCCoUkIE
.MediaSelectionError(error
.get('id'))
269 return self
._findall
_ns
(media_selection
, './{%s}media')
271 def _extract_connections(self
, media
):
272 return self
._findall
_ns
(media
, './{%s}connection')
274 def _extract_video(self
, media
, programme_id
):
276 vbr
= int_or_none(media
.get('bitrate'))
277 vcodec
= media
.get('encoding')
278 service
= media
.get('service')
279 width
= int_or_none(media
.get('width'))
280 height
= int_or_none(media
.get('height'))
281 file_size
= int_or_none(media
.get('media_file_size'))
282 for connection
in self
._extract
_connections
(media
):
283 conn_formats
= self
._extract
_connection
(connection
, programme_id
)
284 for format
in conn_formats
:
290 'filesize': file_size
,
293 format
['format_id'] = '%s_%s' % (service
, format
['format_id'])
294 formats
.extend(conn_formats
)
297 def _extract_audio(self
, media
, programme_id
):
299 abr
= int_or_none(media
.get('bitrate'))
300 acodec
= media
.get('encoding')
301 service
= media
.get('service')
302 for connection
in self
._extract
_connections
(media
):
303 conn_formats
= self
._extract
_connection
(connection
, programme_id
)
304 for format
in conn_formats
:
306 'format_id': '%s_%s' % (service
, format
['format_id']),
310 formats
.extend(conn_formats
)
313 def _get_subtitles(self
, media
, programme_id
):
315 for connection
in self
._extract
_connections
(media
):
316 captions
= self
._download
_xml
(connection
.get('href'), programme_id
, 'Downloading captions')
317 lang
= captions
.get('{http://www.w3.org/XML/1998/namespace}lang', 'en')
320 'url': connection
.get('href'),
326 def _raise_extractor_error(self
, media_selection_error
):
327 raise ExtractorError(
328 '%s returned error: %s' % (self
.IE_NAME
, media_selection_error
.id),
331 def _download_media_selector(self
, programme_id
):
332 last_exception
= None
333 for mediaselector_url
in self
._MEDIASELECTOR
_URLS
:
335 return self
._download
_media
_selector
_url
(
336 mediaselector_url
% programme_id
, programme_id
)
337 except BBCCoUkIE
.MediaSelectionError
as e
:
338 if e
.id in ('notukerror', 'geolocation', 'selectionunavailable'):
341 self
._raise
_extractor
_error
(e
)
342 self
._raise
_extractor
_error
(last_exception
)
344 def _download_media_selector_url(self
, url
, programme_id
=None):
346 media_selection
= self
._download
_xml
(
347 url
, programme_id
, 'Downloading media selection XML')
348 except ExtractorError
as ee
:
349 if isinstance(ee
.cause
, compat_HTTPError
) and ee
.cause
.code
in (403, 404):
350 media_selection
= compat_etree_fromstring(ee
.cause
.read().decode('utf-8'))
353 return self
._process
_media
_selector
(media_selection
, programme_id
)
355 def _process_media_selector(self
, media_selection
, programme_id
):
359 for media
in self
._extract
_medias
(media_selection
):
360 kind
= media
.get('kind')
362 formats
.extend(self
._extract
_audio
(media
, programme_id
))
363 elif kind
== 'video':
364 formats
.extend(self
._extract
_video
(media
, programme_id
))
365 elif kind
== 'captions':
366 subtitles
= self
.extract_subtitles(media
, programme_id
)
367 return formats
, subtitles
369 def _download_playlist(self
, playlist_id
):
371 playlist
= self
._download
_json
(
372 'http://www.bbc.co.uk/programmes/%s/playlist.json' % playlist_id
,
373 playlist_id
, 'Downloading playlist JSON')
375 version
= playlist
.get('defaultAvailableVersion')
377 smp_config
= version
['smpConfig']
378 title
= smp_config
['title']
379 description
= smp_config
['summary']
380 for item
in smp_config
['items']:
382 if kind
!= 'programme' and kind
!= 'radioProgramme':
384 programme_id
= item
.get('vpid')
385 duration
= int_or_none(item
.get('duration'))
386 formats
, subtitles
= self
._download
_media
_selector
(programme_id
)
387 return programme_id
, title
, description
, duration
, formats
, subtitles
388 except ExtractorError
as ee
:
389 if not (isinstance(ee
.cause
, compat_HTTPError
) and ee
.cause
.code
== 404):
392 # fallback to legacy playlist
393 return self
._process
_legacy
_playlist
(playlist_id
)
395 def _process_legacy_playlist_url(self
, url
, display_id
):
396 playlist
= self
._download
_legacy
_playlist
_url
(url
, display_id
)
397 return self
._extract
_from
_legacy
_playlist
(playlist
, display_id
)
399 def _process_legacy_playlist(self
, playlist_id
):
400 return self
._process
_legacy
_playlist
_url
(
401 'http://www.bbc.co.uk/iplayer/playlist/%s' % playlist_id
, playlist_id
)
403 def _download_legacy_playlist_url(self
, url
, playlist_id
=None):
404 return self
._download
_xml
(
405 url
, playlist_id
, 'Downloading legacy playlist XML')
407 def _extract_from_legacy_playlist(self
, playlist
, playlist_id
):
408 no_items
= playlist
.find('./{%s}noItems' % self
._EMP
_PLAYLIST
_NS
)
409 if no_items
is not None:
410 reason
= no_items
.get('reason')
411 if reason
== 'preAvailability':
412 msg
= 'Episode %s is not yet available' % playlist_id
413 elif reason
== 'postAvailability':
414 msg
= 'Episode %s is no longer available' % playlist_id
415 elif reason
== 'noMedia':
416 msg
= 'Episode %s is not currently available' % playlist_id
418 msg
= 'Episode %s is not available: %s' % (playlist_id
, reason
)
419 raise ExtractorError(msg
, expected
=True)
421 for item
in self
._extract
_items
(playlist
):
422 kind
= item
.get('kind')
423 if kind
!= 'programme' and kind
!= 'radioProgramme':
425 title
= playlist
.find('./{%s}title' % self
._EMP
_PLAYLIST
_NS
).text
426 description_el
= playlist
.find('./{%s}summary' % self
._EMP
_PLAYLIST
_NS
)
427 description
= description_el
.text
if description_el
is not None else None
429 def get_programme_id(item
):
430 def get_from_attributes(item
):
431 for p
in('identifier', 'group'):
433 if value
and re
.match(r
'^[pb][\da-z]{7}$', value
):
435 get_from_attributes(item
)
436 mediator
= item
.find('./{%s}mediator' % self
._EMP
_PLAYLIST
_NS
)
437 if mediator
is not None:
438 return get_from_attributes(mediator
)
440 programme_id
= get_programme_id(item
)
441 duration
= int_or_none(item
.get('duration'))
444 formats
, subtitles
= self
._download
_media
_selector
(programme_id
)
446 formats
, subtitles
= self
._process
_media
_selector
(item
, playlist_id
)
447 programme_id
= playlist_id
449 return programme_id
, title
, description
, duration
, formats
, subtitles
451 def _real_extract(self
, url
):
452 group_id
= self
._match
_id
(url
)
454 webpage
= self
._download
_webpage
(url
, group_id
, 'Downloading video page')
458 tviplayer
= self
._search
_regex
(
459 r
'mediator\.bind\(({.+?})\s*,\s*document\.getElementById',
460 webpage
, 'player', default
=None)
463 player
= self
._parse
_json
(tviplayer
, group_id
).get('player', {})
464 duration
= int_or_none(player
.get('duration'))
465 programme_id
= player
.get('vpid')
468 programme_id
= self
._search
_regex
(
469 r
'"vpid"\s*:\s*"(%s)"' % self
._ID
_REGEX
, webpage
, 'vpid', fatal
=False, default
=None)
472 formats
, subtitles
= self
._download
_media
_selector
(programme_id
)
473 title
= self
._og
_search
_title
(webpage
)
474 description
= self
._search
_regex
(
475 r
'<p class="[^"]*medium-description[^"]*">([^<]+)</p>',
476 webpage
, 'description', fatal
=False)
478 programme_id
, title
, description
, duration
, formats
, subtitles
= self
._download
_playlist
(group_id
)
480 self
._sort
_formats
(formats
)
485 'description': description
,
486 'thumbnail': self
._og
_search
_thumbnail
(webpage
, default
=None),
487 'duration': duration
,
489 'subtitles': subtitles
,
493 class BBCIE(BBCCoUkIE
):
496 _VALID_URL
= r
'https?://(?:www\.)?bbc\.(?:com|co\.uk)/(?:[^/]+/)+(?P<id>[^/#?]+)'
498 _MEDIASELECTOR_URLS
= [
499 # Provides HQ HLS streams but fails with geolocation in some cases when it's
500 # even not geo restricted at all
501 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/iptv-all/vpid/%s',
502 # Provides more formats, namely direct mp4 links, but fails on some videos with
503 # notukerror for non UK (?) users (e.g.
504 # http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret)
505 'http://open.live.bbc.co.uk/mediaselector/4/mtis/stream/%s',
506 # Provides fewer formats, but works everywhere for everybody (hopefully)
507 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/journalism-pc/vpid/%s',
511 # article with multiple videos embedded with data-playable containing vpids
512 'url': 'http://www.bbc.com/news/world-europe-32668511',
514 'id': 'world-europe-32668511',
515 'title': 'Russia stages massive WW2 parade despite Western boycott',
516 'description': 'md5:00ff61976f6081841f759a08bf78cc9c',
520 # article with multiple videos embedded with data-playable (more videos)
521 'url': 'http://www.bbc.com/news/business-28299555',
523 'id': 'business-28299555',
524 'title': 'Farnborough Airshow: Video highlights',
525 'description': 'BBC reports and video highlights at the Farnborough Airshow.',
530 # article with multiple videos embedded with `new SMP()`
532 'url': 'http://www.bbc.co.uk/blogs/adamcurtis/entries/3662a707-0af9-3149-963f-47bea720b460',
534 'id': '3662a707-0af9-3149-963f-47bea720b460',
535 'title': 'BBC Blogs - Adam Curtis - BUGGER',
537 'playlist_count': 18,
539 # single video embedded with data-playable containing vpid
540 'url': 'http://www.bbc.com/news/world-europe-32041533',
544 'title': 'Aerial footage showed the site of the crash in the Alps - courtesy BFM TV',
545 'description': 'md5:2868290467291b37feda7863f7a83f54',
547 'timestamp': 1427219242,
548 'upload_date': '20150324',
552 'skip_download': True,
555 # article with single video embedded with data-playable containing XML playlist
556 # with direct video links as progressiveDownloadUrl (for now these are extracted)
557 # and playlist with f4m and m3u8 as streamingUrl
558 'url': 'http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu',
560 'id': '150615_telabyad_kentin_cogu',
562 'title': "YPG: Tel Abyad'ın tamamı kontrolümüzde",
563 'timestamp': 1434397334,
564 'upload_date': '20150615',
567 'skip_download': True,
570 # single video embedded with data-playable containing XML playlists (regional section)
571 'url': 'http://www.bbc.com/mundo/video_fotos/2015/06/150619_video_honduras_militares_hospitales_corrupcion_aw',
573 'id': '150619_video_honduras_militares_hospitales_corrupcion_aw',
575 'title': 'Honduras militariza sus hospitales por nuevo escándalo de corrupción',
576 'timestamp': 1434713142,
577 'upload_date': '20150619',
580 'skip_download': True,
583 # single video from video playlist embedded with vxp-playlist-data JSON
584 'url': 'http://www.bbc.com/news/video_and_audio/must_see/33376376',
588 'title': '''Judge Mindy Glazer: "I'm sorry to see you here... I always wondered what happened to you"''',
592 'skip_download': True,
595 # single video story with digitalData
596 'url': 'http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret',
600 'title': 'Sri Lanka’s spicy secret',
601 'description': 'As a new train line to Jaffna opens up the country’s north, travellers can experience a truly distinct slice of Tamil culture.',
602 'timestamp': 1437674293,
603 'upload_date': '20150723',
607 'skip_download': True,
610 # single video story without digitalData
611 'url': 'http://www.bbc.com/autos/story/20130513-hyundais-rock-star',
615 'title': 'Hyundai Santa Fe Sport: Rock star',
616 'description': 'md5:b042a26142c4154a6e472933cf20793d',
617 'timestamp': 1415867444,
618 'upload_date': '20141113',
622 'skip_download': True,
625 # single video with playlist.sxml URL in playlist param
626 'url': 'http://www.bbc.com/sport/0/football/33653409',
630 'title': 'Transfers: Cristiano Ronaldo to Man Utd, Arsenal to spend?',
631 'description': 'BBC Sport\'s David Ornstein has the latest transfer gossip, including rumours of a Manchester United return for Cristiano Ronaldo.',
636 'skip_download': True,
639 # article with multiple videos embedded with playlist.sxml in playlist param
640 'url': 'http://www.bbc.com/sport/0/football/34475836',
643 'title': 'What Liverpool can expect from Klopp',
647 # single video with playlist URL from weather section
648 'url': 'http://www.bbc.com/weather/features/33601775',
649 'only_matching': True,
651 # custom redirection to www.bbc.com
652 'url': 'http://www.bbc.co.uk/news/science-environment-33661876',
653 'only_matching': True,
657 def suitable(cls
, url
):
658 return False if BBCCoUkIE
.suitable(url
) or BBCCoUkArticleIE
.suitable(url
) else super(BBCIE
, cls
).suitable(url
)
660 def _extract_from_media_meta(self
, media_meta
, video_id
):
661 # Direct links to media in media metadata (e.g.
662 # http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu)
663 # TODO: there are also f4m and m3u8 streams incorporated in playlist.sxml
664 source_files
= media_meta
.get('sourceFiles')
668 'format_id': format_id
,
669 'ext': f
.get('encoding'),
670 'tbr': float_or_none(f
.get('bitrate'), 1000),
671 'filesize': int_or_none(f
.get('filesize')),
672 } for format_id
, f
in source_files
.items() if f
.get('url')], []
674 programme_id
= media_meta
.get('externalId')
676 return self
._download
_media
_selector
(programme_id
)
678 # Process playlist.sxml as legacy playlist
679 href
= media_meta
.get('href')
681 playlist
= self
._download
_legacy
_playlist
_url
(href
)
682 _
, _
, _
, _
, formats
, subtitles
= self
._extract
_from
_legacy
_playlist
(playlist
, video_id
)
683 return formats
, subtitles
687 def _extract_from_playlist_sxml(self
, url
, playlist_id
, timestamp
):
688 programme_id
, title
, description
, duration
, formats
, subtitles
= \
689 self
._process
_legacy
_playlist
_url
(url
, playlist_id
)
690 self
._sort
_formats
(formats
)
694 'description': description
,
695 'duration': duration
,
696 'timestamp': timestamp
,
698 'subtitles': subtitles
,
701 def _real_extract(self
, url
):
702 playlist_id
= self
._match
_id
(url
)
704 webpage
= self
._download
_webpage
(url
, playlist_id
)
707 playlist_title
= None
708 playlist_description
= None
710 ld
= self
._parse
_json
(
712 r
'(?s)<script type="application/ld\+json">(.+?)</script>',
713 webpage
, 'ld json', default
='{}'),
714 playlist_id
, fatal
=False)
716 timestamp
= parse_iso8601(ld
.get('datePublished'))
717 playlist_title
= ld
.get('headline')
718 playlist_description
= ld
.get('articleBody')
721 timestamp
= parse_iso8601(self
._search
_regex
(
722 [r
'<meta[^>]+property="article:published_time"[^>]+content="([^"]+)"',
723 r
'itemprop="datePublished"[^>]+datetime="([^"]+)"',
724 r
'"datePublished":\s*"([^"]+)'],
725 webpage
, 'date', default
=None))
729 # article with multiple videos embedded with playlist.sxml (e.g.
730 # http://www.bbc.com/sport/0/football/34475836)
731 playlists
= re
.findall(r
'<param[^>]+name="playlist"[^>]+value="([^"]+)"', webpage
)
734 self
._extract
_from
_playlist
_sxml
(playlist_url
, playlist_id
, timestamp
)
735 for playlist_url
in playlists
]
737 # news article with multiple videos embedded with data-playable
738 data_playables
= re
.findall(r
'data-playable=(["\'])({.+?}
)\
1', webpage)
740 for _, data_playable_json in data_playables:
741 data_playable = self._parse_json(
742 unescapeHTML(data_playable_json), playlist_id, fatal=False)
743 if not data_playable:
745 settings = data_playable.get('settings
', {})
747 # data-playable with video vpid in settings.playlistObject.items (e.g.
748 # http://www.bbc.com/news/world-us-canada-34473351)
749 playlist_object = settings.get('playlistObject
', {})
751 items = playlist_object.get('items
')
752 if items and isinstance(items, list):
753 title = playlist_object['title
']
754 description = playlist_object.get('summary
')
755 duration = int_or_none(items[0].get('duration
'))
756 programme_id = items[0].get('vpid
')
757 formats, subtitles = self._download_media_selector(programme_id)
758 self._sort_formats(formats)
762 'description
': description,
763 'timestamp
': timestamp,
764 'duration
': duration,
766 'subtitles
': subtitles,
769 # data-playable without vpid but with a playlist.sxml URLs
770 # in otherSettings.playlist (e.g.
771 # http://www.bbc.com/turkce/multimedya/2015/10/151010_vid_ankara_patlama_ani)
772 playlist = data_playable.get('otherSettings
', {}).get('playlist', {})
774 entries.append(self._extract_from_playlist_sxml(
775 playlist.get('progressiveDownloadUrl
'), playlist_id, timestamp))
778 playlist_title = playlist_title or remove_end(self._og_search_title(webpage), ' - BBC News
')
779 playlist_description = playlist_description or self._og_search_description(webpage, default=None)
780 return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)
782 # single video story (e.g. http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret)
783 programme_id = self._search_regex(
784 [r'data
-video
-player
-vpid
="(%s)"' % self._ID_REGEX,
785 r'<param
[^
>]+name
="externalIdentifier"[^
>]+value
="(%s)"' % self._ID_REGEX,
786 r'videoId\s
*:\s
*["\'](%s)["\']' % self._ID_REGEX],
787 webpage, 'vpid
', default=None)
790 formats, subtitles = self._download_media_selector(programme_id)
791 self._sort_formats(formats)
792 # digitalData may be missing (e.g. http://www.bbc.com/autos/story/20130513-hyundais-rock-star)
793 digital_data = self._parse_json(
795 r'var\s
+digitalData\s
*=\s
*({.+?}
);?
\n', webpage, 'digital data
', default='{}'),
796 programme_id, fatal=False)
797 page_info = digital_data.get('page
', {}).get('pageInfo', {})
798 title = page_info.get('pageName
') or self._og_search_title(webpage)
799 description = page_info.get('description
') or self._og_search_description(webpage)
800 timestamp = parse_iso8601(page_info.get('publicationDate
')) or timestamp
804 'description
': description,
805 'timestamp
': timestamp,
807 'subtitles
': subtitles,
810 playlist_title = self._html_search_regex(
811 r'<title
>(.*?
)(?
:\s
*-\s
*BBC
[^
]+)?
</title
>', webpage, 'playlist title
')
812 playlist_description = self._og_search_description(webpage, default=None)
814 def extract_all(pattern):
815 return list(filter(None, map(
816 lambda s: self._parse_json(s, playlist_id, fatal=False),
817 re.findall(pattern, webpage))))
819 # Multiple video article (e.g.
820 # http://www.bbc.co.uk/blogs/adamcurtis/entries/3662a707-0af9-3149-963f-47bea720b460)
821 EMBED_URL = r'https?
://(?
:www\
.)?bbc\
.co\
.uk
/(?
:[^
/]+/)+%s(?
:\b[^
"]+)?' % self._ID_REGEX
823 for match in extract_all(r'new\s+SMP\(({.+?})\)'):
824 embed_url = match.get('playerSettings', {}).get('externalEmbedUrl')
825 if embed_url and re.match(EMBED_URL, embed_url):
826 entries.append(embed_url)
827 entries.extend(re.findall(
828 r'setPlaylist\("(%s)"\)' % EMBED_URL, webpage))
830 return self.playlist_result(
831 [self.url_result(entry, 'BBCCoUk') for entry in entries],
832 playlist_id, playlist_title, playlist_description)
834 # Multiple video article (e.g. http://www.bbc.com/news/world-europe-32668511)
835 medias = extract_all(r"data
-media
-meta
='({[^']+})'")
838 # Single video article (e.g. http://www.bbc.com/news/video_and_audio/international)
839 media_asset = self._search_regex(
840 r'mediaAssetPage\.init\(\s*({.+?}), "/',
841 webpage, 'media asset
', default=None)
843 media_asset_page = self._parse_json(media_asset, playlist_id, fatal=False)
845 for video in media_asset_page.get('videos
', {}).values():
846 medias.extend(video.values())
849 # Multiple video playlist with single `now playing` entry (e.g.
850 # http://www.bbc.com/news/video_and_audio/must_see/33767813)
851 vxp_playlist = self._parse_json(
853 r'<script
[^
>]+class="vxp-playlist-data"[^
>]+type="application/json"[^
>]*>([^
<]+)</script
>',
854 webpage, 'playlist data
'),
857 for item in vxp_playlist:
858 media = item.get('media
')
861 playlist_medias.append(media)
862 # Download single video if found media with asset id matching the video id from URL
863 if item.get('advert
', {}).get('assetId
') == playlist_id:
866 # Fallback to the whole playlist
868 medias = playlist_medias
871 for num, media_meta in enumerate(medias, start=1):
872 formats, subtitles = self._extract_from_media_meta(media_meta, playlist_id)
875 self._sort_formats(formats)
877 video_id = media_meta.get('externalId
')
879 video_id = playlist_id if len(medias) == 1 else '%s-%s' % (playlist_id, num)
881 title = media_meta.get('caption
')
883 title = playlist_title if len(medias) == 1 else '%s - Video
%s' % (playlist_title, num)
885 duration = int_or_none(media_meta.get('durationInSeconds
')) or parse_duration(media_meta.get('duration
'))
888 for image in media_meta.get('images
', {}).values():
889 images.extend(image.values())
890 if 'image
' in media_meta:
891 images.append(media_meta['image
'])
894 'url
': image.get('href
'),
895 'width
': int_or_none(image.get('width
')),
896 'height
': int_or_none(image.get('height
')),
897 } for image in images]
902 'thumbnails
': thumbnails,
903 'duration
': duration,
904 'timestamp
': timestamp,
906 'subtitles
': subtitles,
909 return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)
912 class BBCCoUkArticleIE(InfoExtractor):
913 _VALID_URL = 'http
://www
.bbc
.co
.uk
/programmes
/articles
/(?P
<id>[a
-zA
-Z0
-9]+)'
914 IE_NAME = 'bbc
.co
.uk
:article
'
915 IE_DESC = 'BBC articles
'
918 'url
': 'http
://www
.bbc
.co
.uk
/programmes
/articles
/3jNQLTMrPlYGTBn0WV6M2MS
/not-your
-typical
-role
-model
-ada
-lovelace
-the
-19th
-century
-programmer
',
920 'id': '3jNQLTMrPlYGTBn0WV6M2MS
',
921 'title
': 'Calculating Ada
: The Countess of Computing
- Not your typical role model
: Ada Lovelace the
19th century programmer
- BBC Four
',
922 'description
': 'Hannah Fry reveals some of her surprising discoveries about Ada Lovelace during filming
.',
925 'add_ie
': ['BBCCoUk
'],
928 def _real_extract(self, url):
929 playlist_id = self._match_id(url)
931 webpage = self._download_webpage(url, playlist_id)
933 title = self._og_search_title(webpage)
934 description = self._og_search_description(webpage).strip()
936 entries = [self.url_result(programme_url) for programme_url in re.findall(
937 r'<div
[^
>]+typeof
="Clip"[^
>]+resource
="([^"]+)"', webpage)]
939 return self.playlist_result(entries, playlist_id, title, description)