[bbc] Improve playlist extraction, refactor, expand support and document
[youtube-dl] / youtube_dl / extractor / bbc.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 import xml.etree.ElementTree
6
7 from .common import InfoExtractor
8 from ..utils import (
9     ExtractorError,
10     float_or_none,
11     int_or_none,
12     parse_duration,
13     parse_iso8601,
14 )
15 from ..compat import compat_HTTPError
16
17
18 class BBCCoUkIE(InfoExtractor):
19     IE_NAME = 'bbc.co.uk'
20     IE_DESC = 'BBC iPlayer'
21     _VALID_URL = r'https?://(?:www\.)?bbc\.co\.uk/(?:(?:(?:programmes|iplayer(?:/[^/]+)?/(?:episode|playlist))/)|music/clips[/#])(?P<id>[\da-z]{8})'
22
23     _MEDIASELECTOR_URL = 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/pc/vpid/%s'
24
25     _TESTS = [
26         {
27             'url': 'http://www.bbc.co.uk/programmes/b039g8p7',
28             'info_dict': {
29                 'id': 'b039d07m',
30                 'ext': 'flv',
31                 'title': 'Kaleidoscope, Leonard Cohen',
32                 'description': 'The Canadian poet and songwriter reflects on his musical career.',
33                 'duration': 1740,
34             },
35             'params': {
36                 # rtmp download
37                 'skip_download': True,
38             }
39         },
40         {
41             'url': 'http://www.bbc.co.uk/iplayer/episode/b00yng5w/The_Man_in_Black_Series_3_The_Printed_Name/',
42             'info_dict': {
43                 'id': 'b00yng1d',
44                 'ext': 'flv',
45                 'title': 'The Man in Black: Series 3: The Printed Name',
46                 'description': "Mark Gatiss introduces Nicholas Pierpan's chilling tale of a writer's devilish pact with a mysterious man. Stars Ewan Bailey.",
47                 'duration': 1800,
48             },
49             'params': {
50                 # rtmp download
51                 'skip_download': True,
52             },
53             'skip': 'Episode is no longer available on BBC iPlayer Radio',
54         },
55         {
56             'url': 'http://www.bbc.co.uk/iplayer/episode/b03vhd1f/The_Voice_UK_Series_3_Blind_Auditions_5/',
57             'info_dict': {
58                 'id': 'b00yng1d',
59                 'ext': 'flv',
60                 'title': 'The Voice UK: Series 3: Blind Auditions 5',
61                 '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.",
62                 'duration': 5100,
63             },
64             'params': {
65                 # rtmp download
66                 'skip_download': True,
67             },
68             'skip': 'Currently BBC iPlayer TV programmes are available to play in the UK only',
69         },
70         {
71             'url': 'http://www.bbc.co.uk/iplayer/episode/p026c7jt/tomorrows-worlds-the-unearthly-history-of-science-fiction-2-invasion',
72             'info_dict': {
73                 'id': 'b03k3pb7',
74                 'ext': 'flv',
75                 'title': "Tomorrow's Worlds: The Unearthly History of Science Fiction",
76                 'description': '2. Invasion',
77                 'duration': 3600,
78             },
79             'params': {
80                 # rtmp download
81                 'skip_download': True,
82             },
83             'skip': 'Currently BBC iPlayer TV programmes are available to play in the UK only',
84         }, {
85             'url': 'http://www.bbc.co.uk/programmes/b04v20dw',
86             'info_dict': {
87                 'id': 'b04v209v',
88                 'ext': 'flv',
89                 'title': 'Pete Tong, The Essential New Tune Special',
90                 'description': "Pete has a very special mix - all of 2014's Essential New Tunes!",
91                 'duration': 10800,
92             },
93             'params': {
94                 # rtmp download
95                 'skip_download': True,
96             }
97         }, {
98             'url': 'http://www.bbc.co.uk/music/clips/p02frcc3',
99             'note': 'Audio',
100             'info_dict': {
101                 'id': 'p02frcch',
102                 'ext': 'flv',
103                 'title': 'Pete Tong, Past, Present and Future Special, Madeon - After Hours mix',
104                 'description': 'French house superstar Madeon takes us out of the club and onto the after party.',
105                 'duration': 3507,
106             },
107             'params': {
108                 # rtmp download
109                 'skip_download': True,
110             }
111         }, {
112             'url': 'http://www.bbc.co.uk/music/clips/p025c0zz',
113             'note': 'Video',
114             'info_dict': {
115                 'id': 'p025c103',
116                 'ext': 'flv',
117                 'title': 'Reading and Leeds Festival, 2014, Rae Morris - Closer (Live on BBC Three)',
118                 'description': 'Rae Morris performs Closer for BBC Three at Reading 2014',
119                 'duration': 226,
120             },
121             'params': {
122                 # rtmp download
123                 'skip_download': True,
124             }
125         }, {
126             'url': 'http://www.bbc.co.uk/iplayer/episode/b054fn09/ad/natural-world-20152016-2-super-powered-owls',
127             'info_dict': {
128                 'id': 'p02n76xf',
129                 'ext': 'flv',
130                 'title': 'Natural World, 2015-2016: 2. Super Powered Owls',
131                 'description': 'md5:e4db5c937d0e95a7c6b5e654d429183d',
132                 'duration': 3540,
133             },
134             'params': {
135                 # rtmp download
136                 'skip_download': True,
137             },
138             'skip': 'geolocation',
139         }, {
140             'url': 'http://www.bbc.co.uk/iplayer/episode/b05zmgwn/royal-academy-summer-exhibition',
141             'info_dict': {
142                 'id': 'b05zmgw1',
143                 'ext': 'flv',
144                 '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.',
145                 'title': 'Royal Academy Summer Exhibition',
146                 'duration': 3540,
147             },
148             'params': {
149                 # rtmp download
150                 'skip_download': True,
151             },
152             'skip': 'geolocation',
153         }, {
154             'url': 'http://www.bbc.co.uk/iplayer/playlist/p01dvks4',
155             'only_matching': True,
156         }, {
157             'url': 'http://www.bbc.co.uk/music/clips#p02frcc3',
158             'only_matching': True,
159         }, {
160             'url': 'http://www.bbc.co.uk/iplayer/cbeebies/episode/b0480276/bing-14-atchoo',
161             'only_matching': True,
162         }
163     ]
164
165     def _extract_asx_playlist(self, connection, programme_id):
166         asx = self._download_xml(connection.get('href'), programme_id, 'Downloading ASX playlist')
167         return [ref.get('href') for ref in asx.findall('./Entry/ref')]
168
169     def _extract_connection(self, connection, programme_id):
170         formats = []
171         protocol = connection.get('protocol')
172         supplier = connection.get('supplier')
173         if protocol == 'http':
174             href = connection.get('href')
175             # ASX playlist
176             if supplier == 'asx':
177                 for i, ref in enumerate(self._extract_asx_playlist(connection, programme_id)):
178                     formats.append({
179                         'url': ref,
180                         'format_id': 'ref%s_%s' % (i, supplier),
181                     })
182             # Direct link
183             else:
184                 formats.append({
185                     'url': href,
186                     'format_id': supplier,
187                 })
188         elif protocol == 'rtmp':
189             application = connection.get('application', 'ondemand')
190             auth_string = connection.get('authString')
191             identifier = connection.get('identifier')
192             server = connection.get('server')
193             formats.append({
194                 'url': '%s://%s/%s?%s' % (protocol, server, application, auth_string),
195                 'play_path': identifier,
196                 'app': '%s?%s' % (application, auth_string),
197                 'page_url': 'http://www.bbc.co.uk',
198                 'player_url': 'http://www.bbc.co.uk/emp/releases/iplayer/revisions/617463_618125_4/617463_618125_4_emp.swf',
199                 'rtmp_live': False,
200                 'ext': 'flv',
201                 'format_id': supplier,
202             })
203         return formats
204
205     def _extract_items(self, playlist):
206         return playlist.findall('./{http://bbc.co.uk/2008/emp/playlist}item')
207
208     def _extract_medias(self, media_selection):
209         error = media_selection.find('./{http://bbc.co.uk/2008/mp/mediaselection}error')
210         if error is not None:
211             raise ExtractorError(
212                 '%s returned error: %s' % (self.IE_NAME, error.get('id')), expected=True)
213         return media_selection.findall('./{http://bbc.co.uk/2008/mp/mediaselection}media')
214
215     def _extract_connections(self, media):
216         return media.findall('./{http://bbc.co.uk/2008/mp/mediaselection}connection')
217
218     def _extract_video(self, media, programme_id):
219         formats = []
220         vbr = int_or_none(media.get('bitrate'))
221         vcodec = media.get('encoding')
222         service = media.get('service')
223         width = int_or_none(media.get('width'))
224         height = int_or_none(media.get('height'))
225         file_size = int_or_none(media.get('media_file_size'))
226         for connection in self._extract_connections(media):
227             conn_formats = self._extract_connection(connection, programme_id)
228             for format in conn_formats:
229                 format.update({
230                     'format_id': '%s_%s' % (service, format['format_id']),
231                     'width': width,
232                     'height': height,
233                     'vbr': vbr,
234                     'vcodec': vcodec,
235                     'filesize': file_size,
236                 })
237             formats.extend(conn_formats)
238         return formats
239
240     def _extract_audio(self, media, programme_id):
241         formats = []
242         abr = int_or_none(media.get('bitrate'))
243         acodec = media.get('encoding')
244         service = media.get('service')
245         for connection in self._extract_connections(media):
246             conn_formats = self._extract_connection(connection, programme_id)
247             for format in conn_formats:
248                 format.update({
249                     'format_id': '%s_%s' % (service, format['format_id']),
250                     'abr': abr,
251                     'acodec': acodec,
252                 })
253             formats.extend(conn_formats)
254         return formats
255
256     def _get_subtitles(self, media, programme_id):
257         subtitles = {}
258         for connection in self._extract_connections(media):
259             captions = self._download_xml(connection.get('href'), programme_id, 'Downloading captions')
260             lang = captions.get('{http://www.w3.org/XML/1998/namespace}lang', 'en')
261             subtitles[lang] = [
262                 {
263                     'url': connection.get('href'),
264                     'ext': 'ttml',
265                 },
266             ]
267         return subtitles
268
269     def _download_media_selector(self, programme_id):
270         return self._download_media_selector_url(
271             self._MEDIASELECTOR_URL % programme_id, programme_id)
272
273     def _download_media_selector_url(self, url, programme_id=None):
274         try:
275             media_selection = self._download_xml(
276                 url, programme_id, 'Downloading media selection XML')
277         except ExtractorError as ee:
278             if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
279                 media_selection = xml.etree.ElementTree.fromstring(ee.cause.read().decode('utf-8'))
280             else:
281                 raise
282         return self._process_media_selector(media_selection, programme_id)
283
284     def _process_media_selector(self, media_selection, programme_id):
285         formats = []
286         subtitles = None
287
288         for media in self._extract_medias(media_selection):
289             kind = media.get('kind')
290             if kind == 'audio':
291                 formats.extend(self._extract_audio(media, programme_id))
292             elif kind == 'video':
293                 formats.extend(self._extract_video(media, programme_id))
294             elif kind == 'captions':
295                 subtitles = self.extract_subtitles(media, programme_id)
296
297         return formats, subtitles
298
299     def _download_playlist(self, playlist_id):
300         try:
301             playlist = self._download_json(
302                 'http://www.bbc.co.uk/programmes/%s/playlist.json' % playlist_id,
303                 playlist_id, 'Downloading playlist JSON')
304
305             version = playlist.get('defaultAvailableVersion')
306             if version:
307                 smp_config = version['smpConfig']
308                 title = smp_config['title']
309                 description = smp_config['summary']
310                 for item in smp_config['items']:
311                     kind = item['kind']
312                     if kind != 'programme' and kind != 'radioProgramme':
313                         continue
314                     programme_id = item.get('vpid')
315                     duration = int_or_none(item.get('duration'))
316                     formats, subtitles = self._download_media_selector(programme_id)
317                 return programme_id, title, description, duration, formats, subtitles
318         except ExtractorError as ee:
319             if not (isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 404):
320                 raise
321
322         # fallback to legacy playlist
323         return self._process_legacy_playlist(playlist_id)
324
325     def _process_legacy_playlist_url(self, url, display_id):
326         playlist = self._download_legacy_playlist_url(url, display_id)
327         return self._extract_from_legacy_playlist(playlist, display_id)
328
329     def _process_legacy_playlist(self, playlist_id):
330         return self._process_legacy_playlist_url(
331             'http://www.bbc.co.uk/iplayer/playlist/%s' % playlist_id, playlist_id)
332
333     def _download_legacy_playlist_url(self, url, playlist_id=None):
334         return self._download_xml(
335             url, playlist_id, 'Downloading legacy playlist XML')
336
337     def _extract_from_legacy_playlist(self, playlist, playlist_id):
338         no_items = playlist.find('./{http://bbc.co.uk/2008/emp/playlist}noItems')
339         if no_items is not None:
340             reason = no_items.get('reason')
341             if reason == 'preAvailability':
342                 msg = 'Episode %s is not yet available' % playlist_id
343             elif reason == 'postAvailability':
344                 msg = 'Episode %s is no longer available' % playlist_id
345             elif reason == 'noMedia':
346                 msg = 'Episode %s is not currently available' % playlist_id
347             else:
348                 msg = 'Episode %s is not available: %s' % (playlist_id, reason)
349             raise ExtractorError(msg, expected=True)
350
351         for item in self._extract_items(playlist):
352             kind = item.get('kind')
353             if kind != 'programme' and kind != 'radioProgramme':
354                 continue
355             title = playlist.find('./{http://bbc.co.uk/2008/emp/playlist}title').text
356             description = playlist.find('./{http://bbc.co.uk/2008/emp/playlist}summary').text
357
358             def get_programme_id(item):
359                 def get_from_attributes(item):
360                     for p in('identifier', 'group'):
361                         value = item.get(p)
362                         if value and re.match(r'^[pb][\da-z]{7}$', value):
363                             return value
364                 get_from_attributes(item)
365                 mediator = item.find('./{http://bbc.co.uk/2008/emp/playlist}mediator')
366                 if mediator is not None:
367                     return get_from_attributes(mediator)
368
369             programme_id = get_programme_id(item)
370             duration = int_or_none(item.get('duration'))
371             # TODO: programme_id can be None and media items can be incorporated right inside
372             # playlist's item (e.g. http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu)
373             # as f4m and m3u8
374             formats, subtitles = self._download_media_selector(programme_id)
375
376         return programme_id, title, description, duration, formats, subtitles
377
378     def _real_extract(self, url):
379         group_id = self._match_id(url)
380
381         webpage = self._download_webpage(url, group_id, 'Downloading video page')
382
383         programme_id = None
384
385         tviplayer = self._search_regex(
386             r'mediator\.bind\(({.+?})\s*,\s*document\.getElementById',
387             webpage, 'player', default=None)
388
389         if tviplayer:
390             player = self._parse_json(tviplayer, group_id).get('player', {})
391             duration = int_or_none(player.get('duration'))
392             programme_id = player.get('vpid')
393
394         if not programme_id:
395             programme_id = self._search_regex(
396                 r'"vpid"\s*:\s*"([\da-z]{8})"', webpage, 'vpid', fatal=False, default=None)
397
398         if programme_id:
399             formats, subtitles = self._download_media_selector(programme_id)
400             title = self._og_search_title(webpage)
401             description = self._search_regex(
402                 r'<p class="[^"]*medium-description[^"]*">([^<]+)</p>',
403                 webpage, 'description', fatal=False)
404         else:
405             programme_id, title, description, duration, formats, subtitles = self._download_playlist(group_id)
406
407         self._sort_formats(formats)
408
409         return {
410             'id': programme_id,
411             'title': title,
412             'description': description,
413             'thumbnail': self._og_search_thumbnail(webpage, default=None),
414             'duration': duration,
415             'formats': formats,
416             'subtitles': subtitles,
417         }
418
419
420 class BBCIE(BBCCoUkIE):
421     IE_NAME = 'bbc'
422     IE_DESC = 'BBC'
423     _VALID_URL = r'https?://(?:www\.)?bbc\.(?:com|co\.uk)/(?:[^/]+/)+(?P<id>[^/#?]+)'
424
425     # fails with notukerror for some videos
426     #_MEDIASELECTOR_URL = 'http://open.live.bbc.co.uk/mediaselector/4/mtis/stream/%s'
427     _MEDIASELECTOR_URL = 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/journalism-pc/vpid/%s'
428
429     _TESTS = [{
430         # article with multiple videos embedded with data-media-meta containing
431         # playlist.sxml, externalId and no direct video links
432         'url': 'http://www.bbc.com/news/world-europe-32668511',
433         'info_dict': {
434             'id': 'world-europe-32668511',
435             'title': 'Russia stages massive WW2 parade despite Western boycott',
436             'description': 'md5:00ff61976f6081841f759a08bf78cc9c',
437         },
438         'playlist_count': 2,
439     }, {
440         # article with multiple videos embedded with data-media-meta (more videos)
441         'url': 'http://www.bbc.com/news/business-28299555',
442         'info_dict': {
443             'id': 'business-28299555',
444             'title': 'Farnborough Airshow: Video highlights',
445             'description': 'BBC reports and video highlights at the Farnborough Airshow.',
446         },
447         'playlist_count': 9,
448         'skip': 'Save time',
449     }, {
450         # single video embedded with mediaAssetPage.init()
451         'url': 'http://www.bbc.com/news/world-europe-32041533',
452         'info_dict': {
453             'id': 'p02mprgb',
454             'ext': 'flv',
455             'title': 'Aerial footage showed the site of the crash in the Alps - courtesy BFM TV',
456             'duration': 47,
457             'timestamp': 1427219242,
458             'upload_date': '20150324',
459         },
460         'params': {
461             # rtmp download
462             'skip_download': True,
463         }
464     }, {
465         # article with single video embedded with data-media-meta containing
466         # direct video links (for now these are extracted) and playlist.xml (with
467         # media items as f4m and m3u8 - currently unsupported)
468         'url': 'http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu',
469         'info_dict': {
470             'id': '150615_telabyad_kentin_cogu',
471             'ext': 'mp4',
472             'title': "YPG: Tel Abyad'ın tamamı kontrolümüzde",
473             'duration': 47,
474             'timestamp': 1434397334,
475             'upload_date': '20150615',
476         },
477         'params': {
478             'skip_download': True,
479         }
480     }, {
481         # single video embedded with mediaAssetPage.init() (regional section)
482         'url': 'http://www.bbc.com/mundo/video_fotos/2015/06/150619_video_honduras_militares_hospitales_corrupcion_aw',
483         'info_dict': {
484             'id': '150619_video_honduras_militares_hospitales_corrupcion_aw',
485             'ext': 'mp4',
486             'title': 'Honduras militariza sus hospitales por nuevo escándalo de corrupción',
487             'duration': 87,
488             'timestamp': 1434713142,
489             'upload_date': '20150619',
490         },
491         'params': {
492             'skip_download': True,
493         }
494     }, {
495         # single video story with digitalData
496         'url': 'http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret',
497         'info_dict': {
498             'id': 'p02q6gc4',
499             'ext': 'flv',
500             'title': 'Sri Lanka’s spicy secret',
501             'description': 'As a new train line to Jaffna opens up the country’s north, travellers can experience a truly distinct slice of Tamil culture.',
502             'timestamp': 1437674293,
503             'upload_date': '20150723',
504         },
505         'params': {
506             # rtmp download
507             'skip_download': True,
508         }
509     }, {
510         # single video story without digitalData
511         'url': 'http://www.bbc.com/autos/story/20130513-hyundais-rock-star',
512         'info_dict': {
513             'id': 'p018zqqg',
514             'ext': 'flv',
515             'title': 'Hyundai Santa Fe Sport: Rock star',
516             'description': 'md5:b042a26142c4154a6e472933cf20793d',
517             'timestamp': 1368473503,
518             'upload_date': '20130513',
519         },
520         'params': {
521             # rtmp download
522             'skip_download': True,
523         }
524     }, {
525         # single video with playlist.sxml URL
526         'url': 'http://www.bbc.com/sport/0/football/33653409',
527         'info_dict': {
528             'id': 'p02xycnp',
529             'ext': 'flv',
530             'title': 'Transfers: Cristiano Ronaldo to Man Utd, Arsenal to spend?',
531             'description': 'md5:398fca0e2e701c609d726e034fa1fc89',
532             'duration': 140,
533         },
534         'params': {
535             # rtmp download
536             'skip_download': True,
537         }
538     }, {
539         # single video with playlist URL from weather section
540         'url': 'http://www.bbc.com/weather/features/33601775',
541         'only_matching': True,
542     }, {
543         # custom redirection to www.bbc.com
544         'url': 'http://www.bbc.co.uk/news/science-environment-33661876',
545         'only_matching': True,
546     }]
547
548     @classmethod
549     def suitable(cls, url):
550         return False if BBCCoUkIE.suitable(url) else super(BBCIE, cls).suitable(url)
551
552     def _extract_from_media_meta(self, media_meta, video_id):
553         # Direct links to media in media metadata (e.g.
554         # http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu)
555         # TODO: there are also f4m and m3u8 streams incorporated in playlist.sxml
556         source_files = media_meta.get('sourceFiles')
557         if source_files:
558             return [{
559                 'url': f['url'],
560                 'format_id': format_id,
561                 'ext': f.get('encoding'),
562                 'tbr': float_or_none(f.get('bitrate'), 1000),
563                 'filesize': int_or_none(f.get('filesize')),
564             } for format_id, f in source_files.items() if f.get('url')], []
565
566         programme_id = media_meta.get('externalId')
567         if programme_id:
568             return self._download_media_selector(programme_id)
569
570         # Process playlist.sxml as legacy playlist
571         href = media_meta.get('href')
572         if href:
573             playlist = self._download_legacy_playlist_url(href)
574             _, _, _, _, formats, subtitles = self._extract_from_legacy_playlist(playlist, video_id)
575             return formats, subtitles
576
577         return [], []
578
579     def _real_extract(self, url):
580         playlist_id = self._match_id(url)
581
582         webpage = self._download_webpage(url, playlist_id)
583
584         timestamp = parse_iso8601(self._search_regex(
585             [r'"datePublished":\s*"([^"]+)',
586              r'<meta[^>]+property="article:published_time"[^>]+content="([^"]+)"',
587              r'itemprop="datePublished"[^>]+datetime="([^"]+)"'],
588             webpage, 'date', default=None))
589
590         # single video with playlist.sxml URL (e.g. http://www.bbc.com/sport/0/football/3365340ng)
591         playlist = self._search_regex(
592             r'<param[^>]+name="playlist"[^>]+value="([^"]+)"',
593             webpage, 'playlist', default=None)
594         if playlist:
595             programme_id, title, description, duration, formats, subtitles = \
596                 self._process_legacy_playlist_url(playlist, playlist_id)
597             self._sort_formats(formats)
598             return {
599                 'id': programme_id,
600                 'title': title,
601                 'description': description,
602                 'duration': duration,
603                 'timestamp': timestamp,
604                 'formats': formats,
605                 'subtitles': subtitles,
606             }
607
608         # single video story (e.g. http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret)
609         programme_id = self._search_regex(
610             [r'data-video-player-vpid="([\da-z]{8})"',
611              r'<param[^>]+name="externalIdentifier"[^>]+value="([\da-z]{8})"'],
612             webpage, 'vpid', default=None)
613         if programme_id:
614             formats, subtitles = self._download_media_selector(programme_id)
615             self._sort_formats(formats)
616             # digitalData may be missing (e.g. http://www.bbc.com/autos/story/20130513-hyundais-rock-star)
617             digital_data = self._parse_json(
618                 self._search_regex(
619                     r'var\s+digitalData\s*=\s*({.+?});?\n', webpage, 'digital data', default='{}'),
620                 programme_id, fatal=False)
621             page_info = digital_data.get('page', {}).get('pageInfo', {})
622             title = page_info.get('pageName') or self._og_search_title(webpage)
623             description = page_info.get('description') or self._og_search_description(webpage)
624             timestamp = parse_iso8601(page_info.get('publicationDate')) or timestamp
625             return {
626                 'id': programme_id,
627                 'title': title,
628                 'description': description,
629                 'timestamp': timestamp,
630                 'formats': formats,
631                 'subtitles': subtitles,
632             }
633
634         playlist_title = self._html_search_regex(
635             r'<title>(.*?)(?:\s*-\s*BBC [^ ]+)?</title>', webpage, 'playlist title')
636         playlist_description = self._og_search_description(webpage)
637
638         # Multiple video article (e.g. http://www.bbc.com/news/world-europe-32668511)
639         medias = list(filter(None, map(
640             lambda s: self._parse_json(s, playlist_id, fatal=False),
641             re.findall(r"data-media-meta='({[^']+})'", webpage))))
642
643         if not medias:
644             # Single video article (e.g. http://www.bbc.com/news/video_and_audio/international)
645             media_asset_page = self._parse_json(
646                 self._search_regex(
647                     r'mediaAssetPage\.init\(\s*({.+?}), "/', webpage, 'media asset'),
648                 playlist_id)
649             medias = []
650             for video in media_asset_page.get('videos', {}).values():
651                 medias.extend(video.values())
652
653         entries = []
654         for num, media_meta in enumerate(medias, start=1):
655             formats, subtitles = self._extract_from_media_meta(media_meta, playlist_id)
656             if not formats:
657                 continue
658             self._sort_formats(formats)
659
660             video_id = media_meta.get('externalId')
661             if not video_id:
662                 video_id = playlist_id if len(medias) == 1 else '%s-%s' % (playlist_id, num)
663
664             title = media_meta.get('caption')
665             if not title:
666                 title = playlist_title if len(medias) == 1 else '%s - Video %s' % (playlist_title, num)
667
668             duration = int_or_none(media_meta.get('durationInSeconds')) or parse_duration(media_meta.get('duration'))
669
670             images = []
671             for image in media_meta.get('images', {}).values():
672                 images.extend(image.values())
673             if 'image' in media_meta:
674                 images.append(media_meta['image'])
675
676             thumbnails = [{
677                 'url': image.get('href'),
678                 'width': int_or_none(image.get('width')),
679                 'height': int_or_none(image.get('height')),
680             } for image in images]
681
682             entries.append({
683                 'id': video_id,
684                 'title': title,
685                 'thumbnails': thumbnails,
686                 'duration': duration,
687                 'timestamp': timestamp,
688                 'formats': formats,
689                 'subtitles': subtitles,
690             })
691
692         return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)