2 from __future__
import unicode_literals
9 from .common
import InfoExtractor
10 from ..compat
import (
15 compat_urllib_parse_urlparse
,
39 class BBCCoUkIE(InfoExtractor
):
41 IE_DESC
= 'BBC iPlayer'
42 _ID_REGEX
= r
'(?:[pbm][\da-z]{7}|w[\da-z]{7,14})'
45 (?:www\.)?bbc\.co\.uk/
47 programmes/(?!articles/)|
48 iplayer(?:/[^/]+)?/(?:episode/|playlist/)|
49 music/(?:clips|audiovideo/popular)[/#]|
52 events/[^/]+/play/[^/]+/
54 (?P<id>%s)(?!/(?:episodes|broadcasts|clips))
57 _LOGIN_URL
= 'https://account.bbc.com/signin'
58 _NETRC_MACHINE
= 'bbc'
60 _MEDIA_SELECTOR_URL_TEMPL
= 'https://open.live.bbc.co.uk/mediaselector/6/select/version/2.0/mediaset/%s/vpid/%s'
62 # Provides HQ HLS streams with even better quality that pc mediaset but fails
63 # with geolocation in some cases when it's even not geo restricted at all (e.g.
64 # http://www.bbc.co.uk/programmes/b06bp7lf). Also may fail with selectionunavailable.
69 _EMP_PLAYLIST_NS
= 'http://bbc.co.uk/2008/emp/playlist'
73 'url': 'http://www.bbc.co.uk/programmes/b039g8p7',
77 'title': 'Kaleidoscope, Leonard Cohen',
78 'description': 'The Canadian poet and songwriter reflects on his musical career.',
82 'skip_download': True,
86 'url': 'http://www.bbc.co.uk/iplayer/episode/b00yng5w/The_Man_in_Black_Series_3_The_Printed_Name/',
90 'title': 'The Man in Black: Series 3: The Printed Name',
91 'description': "Mark Gatiss introduces Nicholas Pierpan's chilling tale of a writer's devilish pact with a mysterious man. Stars Ewan Bailey.",
96 'skip_download': True,
98 'skip': 'Episode is no longer available on BBC iPlayer Radio',
101 'url': 'http://www.bbc.co.uk/iplayer/episode/b03vhd1f/The_Voice_UK_Series_3_Blind_Auditions_5/',
105 'title': 'The Voice UK: Series 3: Blind Auditions 5',
106 '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.',
111 'skip_download': True,
113 'skip': 'Currently BBC iPlayer TV programmes are available to play in the UK only',
116 'url': 'http://www.bbc.co.uk/iplayer/episode/p026c7jt/tomorrows-worlds-the-unearthly-history-of-science-fiction-2-invasion',
120 'title': "Tomorrow's Worlds: The Unearthly History of Science Fiction",
121 'description': '2. Invasion',
126 'skip_download': True,
128 'skip': 'Currently BBC iPlayer TV programmes are available to play in the UK only',
130 'url': 'http://www.bbc.co.uk/programmes/b04v20dw',
134 'title': 'Pete Tong, The Essential New Tune Special',
135 'description': "Pete has a very special mix - all of 2014's Essential New Tunes!",
140 'skip_download': True,
142 'skip': 'Episode is no longer available on BBC iPlayer Radio',
144 'url': 'http://www.bbc.co.uk/music/clips/p022h44b',
149 'title': 'BBC Proms Music Guides, Rachmaninov: Symphonic Dances',
150 'description': "In this Proms Music Guide, Andrew McGregor looks at Rachmaninov's Symphonic Dances.",
155 'skip_download': True,
158 'url': 'http://www.bbc.co.uk/music/clips/p025c0zz',
163 'title': 'Reading and Leeds Festival, 2014, Rae Morris - Closer (Live on BBC Three)',
164 'description': 'Rae Morris performs Closer for BBC Three at Reading 2014',
169 'skip_download': True,
172 'url': 'http://www.bbc.co.uk/iplayer/episode/b054fn09/ad/natural-world-20152016-2-super-powered-owls',
176 'title': 'Natural World, 2015-2016: 2. Super Powered Owls',
177 'description': 'md5:e4db5c937d0e95a7c6b5e654d429183d',
182 'skip_download': True,
184 'skip': 'geolocation',
186 'url': 'http://www.bbc.co.uk/iplayer/episode/b05zmgwn/royal-academy-summer-exhibition',
190 '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.',
191 'title': 'Royal Academy Summer Exhibition',
196 'skip_download': True,
198 'skip': 'geolocation',
200 # iptv-all mediaset fails with geolocation however there is no geo restriction
201 # for this programme at all
202 'url': 'http://www.bbc.co.uk/programmes/b06rkn85',
206 'title': "Best of the Mini-Mixes 2015: Part 3, Annie Mac's Friday Night - BBC Radio 1",
207 'description': "Annie has part three in the Best of the Mini-Mixes 2015, plus the year's Most Played!",
211 'skip_download': True,
213 'skip': 'Now it\'s really geo-restricted',
215 # compact player (https://github.com/ytdl-org/youtube-dl/issues/8147)
216 'url': 'http://www.bbc.co.uk/programmes/p028bfkf/player',
220 'title': 'Extract from BBC documentary Look Stranger - Giant Leeks and Magic Brews',
221 'description': 'Extract from BBC documentary Look Stranger - Giant Leeks and Magic Brews',
225 'skip_download': True,
228 'url': 'https://www.bbc.co.uk/sounds/play/m0007jzb',
233 'title': 'BBC Proms, 2019, Prom 34: West–Eastern Divan Orchestra',
234 'description': "Live BBC Proms. West–Eastern Divan Orchestra with Daniel Barenboim and Martha Argerich.",
239 'skip_download': True,
242 'url': 'http://www.bbc.co.uk/iplayer/playlist/p01dvks4',
243 'only_matching': True,
245 'url': 'http://www.bbc.co.uk/music/clips#p02frcc3',
246 'only_matching': True,
248 'url': 'http://www.bbc.co.uk/iplayer/cbeebies/episode/b0480276/bing-14-atchoo',
249 'only_matching': True,
251 'url': 'http://www.bbc.co.uk/radio/player/p03cchwf',
252 'only_matching': True,
254 'url': 'https://www.bbc.co.uk/music/audiovideo/popular#p055bc55',
255 'only_matching': True,
257 'url': 'http://www.bbc.co.uk/programmes/w3csv1y9',
258 'only_matching': True,
260 'url': 'https://www.bbc.co.uk/programmes/m00005xn',
261 'only_matching': True,
263 'url': 'https://www.bbc.co.uk/programmes/w172w4dww1jqt5s',
264 'only_matching': True,
268 username
, password
= self
._get
_login
_info
()
272 login_page
= self
._download
_webpage
(
273 self
._LOGIN
_URL
, None, 'Downloading signin page')
275 login_form
= self
._hidden
_inputs
(login_page
)
278 'username': username
,
279 'password': password
,
282 post_url
= urljoin(self
._LOGIN
_URL
, self
._search
_regex
(
283 r
'<form[^>]+action=(["\'])(?P
<url
>.+?
)\
1', login_page,
284 'post url
', default=self._LOGIN_URL, group='url
'))
286 response, urlh = self._download_webpage_handle(
287 post_url, None, 'Logging
in', data=urlencode_postdata(login_form),
288 headers={'Referer': self._LOGIN_URL})
290 if self._LOGIN_URL in urlh.geturl():
291 error = clean_html(get_element_by_class('form
-message
', response))
293 raise ExtractorError(
294 'Unable to login
: %s' % error, expected=True)
295 raise ExtractorError('Unable to log
in')
297 def _real_initialize(self):
300 class MediaSelectionError(Exception):
301 def __init__(self, id):
304 def _extract_asx_playlist(self, connection, programme_id):
305 asx = self._download_xml(connection.get('href
'), programme_id, 'Downloading ASX playlist
')
306 return [ref.get('href
') for ref in asx.findall('./Entry
/ref
')]
308 def _extract_items(self, playlist):
309 return playlist.findall('./{%s}item
' % self._EMP_PLAYLIST_NS)
311 def _extract_medias(self, media_selection):
312 error = media_selection.get('result
')
314 raise BBCCoUkIE.MediaSelectionError(error)
315 return media_selection.get('media
') or []
317 def _extract_connections(self, media):
318 return media.get('connection
') or []
320 def _get_subtitles(self, media, programme_id):
322 for connection in self._extract_connections(media):
323 cc_url = url_or_none(connection.get('href
'))
326 captions = self._download_xml(
327 cc_url, programme_id, 'Downloading captions
', fatal=False)
328 if not isinstance(captions, compat_etree_Element):
332 'url
': connection.get('href
'),
339 def _raise_extractor_error(self, media_selection_error):
340 raise ExtractorError(
341 '%s returned error
: %s' % (self.IE_NAME, media_selection_error.id),
344 def _download_media_selector(self, programme_id):
345 last_exception = None
346 for media_set in self._MEDIA_SETS:
348 return self._download_media_selector_url(
349 self._MEDIA_SELECTOR_URL_TEMPL % (media_set, programme_id), programme_id)
350 except BBCCoUkIE.MediaSelectionError as e:
351 if e.id in ('notukerror
', 'geolocation
', 'selectionunavailable
'):
354 self._raise_extractor_error(e)
355 self._raise_extractor_error(last_exception)
357 def _download_media_selector_url(self, url, programme_id=None):
358 media_selection = self._download_json(
359 url, programme_id, 'Downloading media selection JSON
',
360 expected_status=(403, 404))
361 return self._process_media_selector(media_selection, programme_id)
363 def _process_media_selector(self, media_selection, programme_id):
368 for media in self._extract_medias(media_selection):
369 kind = media.get('kind
')
370 if kind in ('video
', 'audio
'):
371 bitrate = int_or_none(media.get('bitrate
'))
372 encoding = media.get('encoding
')
373 width = int_or_none(media.get('width
'))
374 height = int_or_none(media.get('height
'))
375 file_size = int_or_none(media.get('media_file_size
'))
376 for connection in self._extract_connections(media):
377 href = connection.get('href
')
382 conn_kind = connection.get('kind
')
383 protocol = connection.get('protocol
')
384 supplier = connection.get('supplier
')
385 transfer_format = connection.get('transferFormat
')
386 format_id = supplier or conn_kind or protocol
388 if supplier == 'asx
':
389 for i, ref in enumerate(self._extract_asx_playlist(connection, programme_id)):
392 'format_id
': 'ref
%s_%s' % (i, format_id),
394 elif transfer_format == 'dash
':
395 formats.extend(self._extract_mpd_formats(
396 href, programme_id, mpd_id=format_id, fatal=False))
397 elif transfer_format == 'hls
':
398 formats.extend(self._extract_m3u8_formats(
399 href, programme_id, ext='mp4
', entry_protocol='m3u8_native
',
400 m3u8_id=format_id, fatal=False))
401 elif transfer_format == 'hds
':
402 formats.extend(self._extract_f4m_formats(
403 href, programme_id, f4m_id=format_id, fatal=False))
405 if not supplier and bitrate:
406 format_id += '-%d' % bitrate
408 'format_id
': format_id,
409 'filesize
': file_size,
424 if protocol in ('http
', 'https
'):
429 elif protocol == 'rtmp
':
430 application = connection.get('application
', 'ondemand
')
431 auth_string = connection.get('authString
')
432 identifier = connection.get('identifier
')
433 server = connection.get('server
')
435 'url
': '%s://%s/%s?
%s' % (protocol, server, application, auth_string),
436 'play_path
': identifier,
437 'app
': '%s?
%s' % (application, auth_string),
438 'page_url
': 'http
://www
.bbc
.co
.uk
',
439 'player_url
': 'http
://www
.bbc
.co
.uk
/emp
/releases
/iplayer
/revisions
/617463_618125_4/617463_618125_4_emp
.swf
',
446 elif kind == 'captions
':
447 subtitles = self.extract_subtitles(media, programme_id)
448 return formats, subtitles
450 def _download_playlist(self, playlist_id):
452 playlist = self._download_json(
453 'http
://www
.bbc
.co
.uk
/programmes
/%s/playlist
.json
' % playlist_id,
454 playlist_id, 'Downloading playlist JSON
')
456 version = playlist.get('defaultAvailableVersion
')
458 smp_config = version['smpConfig
']
459 title = smp_config['title
']
460 description = smp_config['summary
']
461 for item in smp_config['items
']:
463 if kind not in ('programme
', 'radioProgramme
'):
465 programme_id = item.get('vpid
')
466 duration = int_or_none(item.get('duration
'))
467 formats, subtitles = self._download_media_selector(programme_id)
468 return programme_id, title, description, duration, formats, subtitles
469 except ExtractorError as ee:
470 if not (isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 404):
473 # fallback to legacy playlist
474 return self._process_legacy_playlist(playlist_id)
476 def _process_legacy_playlist_url(self, url, display_id):
477 playlist = self._download_legacy_playlist_url(url, display_id)
478 return self._extract_from_legacy_playlist(playlist, display_id)
480 def _process_legacy_playlist(self, playlist_id):
481 return self._process_legacy_playlist_url(
482 'http
://www
.bbc
.co
.uk
/iplayer
/playlist
/%s' % playlist_id, playlist_id)
484 def _download_legacy_playlist_url(self, url, playlist_id=None):
485 return self._download_xml(
486 url, playlist_id, 'Downloading legacy playlist XML
')
488 def _extract_from_legacy_playlist(self, playlist, playlist_id):
489 no_items = playlist.find('./{%s}noItems
' % self._EMP_PLAYLIST_NS)
490 if no_items is not None:
491 reason = no_items.get('reason
')
492 if reason == 'preAvailability
':
493 msg = 'Episode
%s is not yet available
' % playlist_id
494 elif reason == 'postAvailability
':
495 msg = 'Episode
%s is no longer available
' % playlist_id
496 elif reason == 'noMedia
':
497 msg = 'Episode
%s is not currently available
' % playlist_id
499 msg = 'Episode
%s is not available
: %s' % (playlist_id, reason)
500 raise ExtractorError(msg, expected=True)
502 for item in self._extract_items(playlist):
503 kind = item.get('kind
')
504 if kind not in ('programme
', 'radioProgramme
'):
506 title = playlist.find('./{%s}title
' % self._EMP_PLAYLIST_NS).text
507 description_el = playlist.find('./{%s}summary
' % self._EMP_PLAYLIST_NS)
508 description = description_el.text if description_el is not None else None
510 def get_programme_id(item):
511 def get_from_attributes(item):
512 for p in ('identifier
', 'group
'):
514 if value and re.match(r'^
[pb
][\da
-z
]{7}$
', value):
516 get_from_attributes(item)
517 mediator = item.find('./{%s}mediator
' % self._EMP_PLAYLIST_NS)
518 if mediator is not None:
519 return get_from_attributes(mediator)
521 programme_id = get_programme_id(item)
522 duration = int_or_none(item.get('duration
'))
525 formats, subtitles = self._download_media_selector(programme_id)
527 formats, subtitles = self._process_media_selector(item, playlist_id)
528 programme_id = playlist_id
530 return programme_id, title, description, duration, formats, subtitles
532 def _real_extract(self, url):
533 group_id = self._match_id(url)
535 webpage = self._download_webpage(url, group_id, 'Downloading video page
')
537 error = self._search_regex(
538 r'<div
\b[^
>]+\bclass
=["\'](?:smp|playout)__message delta["\'][^
>]*>\s
*([^
<]+?
)\s
*<',
539 webpage, 'error
', default=None)
541 raise ExtractorError(error, expected=True)
546 tviplayer = self._search_regex(
547 r'mediator\
.bind\
(({.+?}
)\s
*,\s
*document\
.getElementById
',
548 webpage, 'player
', default=None)
551 player = self._parse_json(tviplayer, group_id).get('player
', {})
552 duration = int_or_none(player.get('duration
'))
553 programme_id = player.get('vpid
')
556 programme_id = self._search_regex(
557 r'"vpid"\s
*:\s
*"(%s)"' % self._ID_REGEX, webpage, 'vpid
', fatal=False, default=None)
560 formats, subtitles = self._download_media_selector(programme_id)
561 title = self._og_search_title(webpage, default=None) or self._html_search_regex(
562 (r'<h2
[^
>]+id="parent-title"[^
>]*>(.+?
)</h2
>',
563 r'<div
[^
>]+class="info"[^
>]*>\s
*<h1
>(.+?
)</h1
>'), webpage, 'title
')
564 description = self._search_regex(
565 (r'<p
class="[^"]*medium
-description
[^
"]*">([^
<]+)</p
>',
566 r'<div
[^
>]+class="info_+synopsis"[^
>]*>([^
<]+)</div
>'),
567 webpage, 'description
', default=None)
569 description = self._html_search_meta('description
', webpage)
571 programme_id, title, description, duration, formats, subtitles = self._download_playlist(group_id)
573 self._sort_formats(formats)
578 'description
': description,
579 'thumbnail
': self._og_search_thumbnail(webpage, default=None),
580 'duration
': duration,
582 'subtitles
': subtitles,
586 class BBCIE(BBCCoUkIE):
589 _VALID_URL = r'https?
://(?
:www\
.)?bbc\
.(?
:com|co\
.uk
)/(?
:[^
/]+/)+(?P
<id>[^
/#?]+)'
592 'mobile-tablet-main',
597 # article with multiple videos embedded with data-playable containing vpids
598 'url': 'http://www.bbc.com/news/world-europe-32668511',
600 'id': 'world-europe-32668511',
601 'title': 'Russia stages massive WW2 parade',
602 'description': 'md5:00ff61976f6081841f759a08bf78cc9c',
606 # article with multiple videos embedded with data-playable (more videos)
607 'url': 'http://www.bbc.com/news/business-28299555',
609 'id': 'business-28299555',
610 'title': 'Farnborough Airshow: Video highlights',
611 'description': 'BBC reports and video highlights at the Farnborough Airshow.',
616 # article with multiple videos embedded with `new SMP()`
618 'url': 'http://www.bbc.co.uk/blogs/adamcurtis/entries/3662a707-0af9-3149-963f-47bea720b460',
620 'id': '3662a707-0af9-3149-963f-47bea720b460',
623 'playlist_count': 18,
625 # single video embedded with data-playable containing vpid
626 'url': 'http://www.bbc.com/news/world-europe-32041533',
630 'title': 'Aerial footage showed the site of the crash in the Alps - courtesy BFM TV',
631 'description': 'md5:2868290467291b37feda7863f7a83f54',
633 'timestamp': 1427219242,
634 'upload_date': '20150324',
638 'skip_download': True,
641 # article with single video embedded with data-playable containing XML playlist
642 # with direct video links as progressiveDownloadUrl (for now these are extracted)
643 # and playlist with f4m and m3u8 as streamingUrl
644 'url': 'http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu',
646 'id': '150615_telabyad_kentin_cogu',
648 'title': "YPG: Tel Abyad'ın tamamı kontrolümüzde",
649 'description': 'md5:33a4805a855c9baf7115fcbde57e7025',
650 'timestamp': 1434397334,
651 'upload_date': '20150615',
654 'skip_download': True,
657 # single video embedded with data-playable containing XML playlists (regional section)
658 'url': 'http://www.bbc.com/mundo/video_fotos/2015/06/150619_video_honduras_militares_hospitales_corrupcion_aw',
660 'id': '150619_video_honduras_militares_hospitales_corrupcion_aw',
662 'title': 'Honduras militariza sus hospitales por nuevo escándalo de corrupción',
663 'description': 'md5:1525f17448c4ee262b64b8f0c9ce66c8',
664 'timestamp': 1434713142,
665 'upload_date': '20150619',
668 'skip_download': True,
671 # single video from video playlist embedded with vxp-playlist-data JSON
672 'url': 'http://www.bbc.com/news/video_and_audio/must_see/33376376',
676 'title': '''Judge Mindy Glazer: "I'm sorry to see you here... I always wondered what happened to you"''',
678 'description': '''Judge Mindy Glazer: "I'm sorry to see you here... I always wondered what happened to you"''',
681 'skip_download': True,
684 # single video story with digitalData
685 'url': 'http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret',
689 'title': 'Sri Lanka’s spicy secret',
690 'description': 'As a new train line to Jaffna opens up the country’s north, travellers can experience a truly distinct slice of Tamil culture.',
691 'timestamp': 1437674293,
692 'upload_date': '20150723',
696 'skip_download': True,
699 # single video story without digitalData
700 'url': 'http://www.bbc.com/autos/story/20130513-hyundais-rock-star',
704 'title': 'Hyundai Santa Fe Sport: Rock star',
705 'description': 'md5:b042a26142c4154a6e472933cf20793d',
706 'timestamp': 1415867444,
707 'upload_date': '20141113',
711 'skip_download': True,
714 # single video embedded with Morph
715 'url': 'http://www.bbc.co.uk/sport/live/olympics/36895975',
719 'title': "Nigeria v Japan - Men's First Round",
720 'description': 'Live coverage of the first round from Group B at the Amazonia Arena.',
722 'uploader': 'BBC Sport',
723 'uploader_id': 'bbc_sport',
727 'skip_download': True,
729 'skip': 'Georestricted to UK',
731 # single video with playlist.sxml URL in playlist param
732 'url': 'http://www.bbc.com/sport/0/football/33653409',
736 'title': 'Transfers: Cristiano Ronaldo to Man Utd, Arsenal to spend?',
737 'description': 'BBC Sport\'s David Ornstein has the latest transfer gossip, including rumours of a Manchester United return for Cristiano Ronaldo.',
742 'skip_download': True,
745 # article with multiple videos embedded with playlist.sxml in playlist param
746 'url': 'http://www.bbc.com/sport/0/football/34475836',
749 'title': 'Jurgen Klopp: Furious football from a witty and winning coach',
750 'description': 'Fast-paced football, wit, wisdom and a ready smile - why Liverpool fans should come to love new boss Jurgen Klopp.',
754 # school report article with single video
755 'url': 'http://www.bbc.co.uk/schoolreport/35744779',
758 'title': 'School which breaks down barriers in Jerusalem',
762 # single video with playlist URL from weather section
763 'url': 'http://www.bbc.com/weather/features/33601775',
764 'only_matching': True,
766 # custom redirection to www.bbc.com
767 # also, video with window.__INITIAL_DATA__
768 'url': 'http://www.bbc.co.uk/news/science-environment-33661876',
772 'title': "Pluto may have 'nitrogen glaciers'",
773 'description': 'md5:6a95b593f528d7a5f2605221bc56912f',
774 'thumbnail': r
're:https?://.+/.+\.jpg',
775 'timestamp': 1437785037,
776 'upload_date': '20150725',
779 # single video article embedded with data-media-vpid
780 'url': 'http://www.bbc.co.uk/sport/rowing/35908187',
781 'only_matching': True,
783 'url': 'https://www.bbc.co.uk/bbcthree/clip/73d0bbd0-abc3-4cea-b3c0-cdae21905eb1',
787 'title': 'Transfers: Cristiano Ronaldo to Man Utd, Arsenal to spend?',
788 'description': 'md5:4b7dfd063d5a789a1512e99662be3ddd',
791 'skip_download': True,
794 # window.__PRELOADED_STATE__
795 'url': 'https://www.bbc.co.uk/radio/play/b0b9z4yl',
799 'title': 'Prom 6: An American in Paris and Turangalila',
800 'description': 'md5:51cf7d6f5c8553f197e58203bc78dff8',
801 'uploader': 'Radio 3',
802 'uploader_id': 'bbc_radio_three',
805 'url': 'http://www.bbc.co.uk/learningenglish/chinese/features/lingohack/ep-181227',
809 'title': 'md5:2fabf12a726603193a2879a055f72514',
810 'description': 'Learn English words and phrases from this story',
812 'add_ie': [BBCCoUkIE
.ie_key()],
815 'url': 'https://www.bbc.com/reel/video/p07c6sb6/how-positive-thinking-is-harming-your-happiness',
819 'title': 'How positive thinking is harming your happiness',
820 'alt_title': 'The downsides of positive thinking',
821 'description': 'md5:fad74b31da60d83b8265954ee42d85b4',
823 'thumbnail': r
're:https?://.+/p07c9dsr.jpg',
824 'upload_date': '20190604',
825 'categories': ['Psychology'],
830 def suitable(cls
, url
):
831 EXCLUDE_IE
= (BBCCoUkIE
, BBCCoUkArticleIE
, BBCCoUkIPlayerEpisodesIE
, BBCCoUkIPlayerGroupIE
, BBCCoUkPlaylistIE
)
832 return (False if any(ie
.suitable(url
) for ie
in EXCLUDE_IE
)
833 else super(BBCIE
, cls
).suitable(url
))
835 def _extract_from_media_meta(self
, media_meta
, video_id
):
836 # Direct links to media in media metadata (e.g.
837 # http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu)
838 # TODO: there are also f4m and m3u8 streams incorporated in playlist.sxml
839 source_files
= media_meta
.get('sourceFiles')
843 'format_id': format_id
,
844 'ext': f
.get('encoding'),
845 'tbr': float_or_none(f
.get('bitrate'), 1000),
846 'filesize': int_or_none(f
.get('filesize')),
847 } for format_id
, f
in source_files
.items() if f
.get('url')], []
849 programme_id
= media_meta
.get('externalId')
851 return self
._download
_media
_selector
(programme_id
)
853 # Process playlist.sxml as legacy playlist
854 href
= media_meta
.get('href')
856 playlist
= self
._download
_legacy
_playlist
_url
(href
)
857 _
, _
, _
, _
, formats
, subtitles
= self
._extract
_from
_legacy
_playlist
(playlist
, video_id
)
858 return formats
, subtitles
862 def _extract_from_playlist_sxml(self
, url
, playlist_id
, timestamp
):
863 programme_id
, title
, description
, duration
, formats
, subtitles
= \
864 self
._process
_legacy
_playlist
_url
(url
, playlist_id
)
865 self
._sort
_formats
(formats
)
869 'description': description
,
870 'duration': duration
,
871 'timestamp': timestamp
,
873 'subtitles': subtitles
,
876 def _real_extract(self
, url
):
877 playlist_id
= self
._match
_id
(url
)
879 webpage
= self
._download
_webpage
(url
, playlist_id
)
881 json_ld_info
= self
._search
_json
_ld
(webpage
, playlist_id
, default
={})
882 timestamp
= json_ld_info
.get('timestamp')
884 playlist_title
= json_ld_info
.get('title')
885 if not playlist_title
:
886 playlist_title
= self
._og
_search
_title
(
887 webpage
, default
=None) or self
._html
_search
_regex
(
888 r
'<title>(.+?)</title>', webpage
, 'playlist title', default
=None)
890 playlist_title
= re
.sub(r
'(.+)\s*-\s*BBC.*?$', r
'\1', playlist_title
).strip()
892 playlist_description
= json_ld_info
.get(
893 'description') or self
._og
_search
_description
(webpage
, default
=None)
896 timestamp
= parse_iso8601(self
._search
_regex
(
897 [r
'<meta[^>]+property="article:published_time"[^>]+content="([^"]+)"',
898 r
'itemprop="datePublished"[^>]+datetime="([^"]+)"',
899 r
'"datePublished":\s*"([^"]+)'],
900 webpage
, 'date', default
=None))
904 # article with multiple videos embedded with playlist.sxml (e.g.
905 # http://www.bbc.com/sport/0/football/34475836)
906 playlists
= re
.findall(r
'<param[^>]+name="playlist"[^>]+value="([^"]+)"', webpage
)
907 playlists
.extend(re
.findall(r
'data-media-id="([^"]+/playlist\.sxml)"', webpage
))
910 self
._extract
_from
_playlist
_sxml
(playlist_url
, playlist_id
, timestamp
)
911 for playlist_url
in playlists
]
913 # news article with multiple videos embedded with data-playable
914 data_playables
= re
.findall(r
'data-playable=(["\'])({.+?}
)\
1', webpage)
916 for _, data_playable_json in data_playables:
917 data_playable = self._parse_json(
918 unescapeHTML(data_playable_json), playlist_id, fatal=False)
919 if not data_playable:
921 settings = data_playable.get('settings
', {})
923 # data-playable with video vpid in settings.playlistObject.items (e.g.
924 # http://www.bbc.com/news/world-us-canada-34473351)
925 playlist_object = settings.get('playlistObject
', {})
927 items = playlist_object.get('items
')
928 if items and isinstance(items, list):
929 title = playlist_object['title
']
930 description = playlist_object.get('summary
')
931 duration = int_or_none(items[0].get('duration
'))
932 programme_id = items[0].get('vpid
')
933 formats, subtitles = self._download_media_selector(programme_id)
934 self._sort_formats(formats)
938 'description
': description,
939 'timestamp
': timestamp,
940 'duration
': duration,
942 'subtitles
': subtitles,
945 # data-playable without vpid but with a playlist.sxml URLs
946 # in otherSettings.playlist (e.g.
947 # http://www.bbc.com/turkce/multimedya/2015/10/151010_vid_ankara_patlama_ani)
948 playlist = data_playable.get('otherSettings
', {}).get('playlist', {})
951 for key in ('streaming
', 'progressiveDownload
'):
952 playlist_url = playlist.get('%sUrl
' % key)
956 info = self._extract_from_playlist_sxml(
957 playlist_url, playlist_id, timestamp)
961 entry['title
'] = info['title
']
962 entry['formats
'].extend(info['formats
'])
963 except ExtractorError as e:
964 # Some playlist URL may fail with 500, at the same time
965 # the other one may work fine (e.g.
966 # http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu)
967 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 500:
971 self._sort_formats(entry['formats
'])
972 entries.append(entry)
975 return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)
977 # http://www.bbc.co.uk/learningenglish/chinese/features/lingohack/ep-181227
978 group_id = self._search_regex(
979 r'<div
[^
>]+\bclass
=["\']video["\'][^
>]+\bdata
-pid
=["\'](%s)' % self._ID_REGEX,
980 webpage, 'group id', default=None)
982 return self.url_result(
983 'https://www.bbc.co.uk/programmes/%s' % group_id,
984 ie=BBCCoUkIE.ie_key())
986 # single video story (e.g. http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret)
987 programme_id = self._search_regex(
988 [r'data-(?:video-player|media)-vpid="(%s)"' % self._ID_REGEX,
989 r'<param[^>]+name="externalIdentifier
"[^>]+value="(%s)"' % self._ID_REGEX,
990 r'videoId\s*:\s*["\'](%s)["\']' % self._ID_REGEX],
991 webpage, 'vpid', default=None)
994 formats, subtitles = self._download_media_selector(programme_id)
995 self._sort_formats(formats)
996 # digitalData may be missing (e.g. http://www.bbc.com/autos/story/20130513-hyundais-rock-star)
997 digital_data = self._parse_json(
999 r'var\s+digitalData\s*=\s*({.+?});?\n', webpage, 'digital data', default='{}'),
1000 programme_id, fatal=False)
1001 page_info = digital_data.get('page', {}).get('pageInfo', {})
1002 title = page_info.get('pageName') or self._og_search_title(webpage)
1003 description = page_info.get('description') or self._og_search_description(webpage)
1004 timestamp = parse_iso8601(page_info.get('publicationDate')) or timestamp
1008 'description': description,
1009 'timestamp': timestamp,
1011 'subtitles': subtitles,
1014 # bbc reel (e.g. https://www.bbc.com/reel/video/p07c6sb6/how-positive-thinking-is-harming-your-happiness)
1015 initial_data = self._parse_json(self._html_search_regex(
1016 r'<script[^>]+id=(["\'])initial
-data\
1[^
>]+data
-json
=(["\'])(?P<json>(?:(?!\2).)+)',
1017 webpage, 'initial data', default='{}', group='json'), playlist_id, fatal=False)
1019 init_data = try_get(
1020 initial_data, lambda x: x['initData']['items'][0], dict) or {}
1021 smp_data = init_data.get('smpData') or {}
1022 clip_data = try_get(smp_data, lambda x: x['items'][0], dict) or {}
1023 version_id = clip_data.get('versionID')
1025 title = smp_data['title']
1026 formats, subtitles = self._download_media_selector(version_id)
1027 self._sort_formats(formats)
1028 image_url = smp_data.get('holdingImageURL')
1029 display_date = init_data.get('displayDate')
1030 topic_title = init_data.get('topicTitle')
1036 'alt_title': init_data.get('shortTitle'),
1037 'thumbnail': image_url.replace('$recipe', 'raw') if image_url else None,
1038 'description': smp_data.get('summary') or init_data.get('shortSummary'),
1039 'upload_date': display_date.replace('-', '') if display_date else None,
1040 'subtitles': subtitles,
1041 'duration': int_or_none(clip_data.get('duration')),
1042 'categories': [topic_title] if topic_title else None,
1045 # Morph based embed (e.g. http://www.bbc.co.uk/sport/live/olympics/36895975)
1046 # There are several setPayload calls may be present but the video
1047 # seems to be always related to the first one
1048 morph_payload = self._parse_json(
1050 r'Morph\.setPayload\([^,]+,\s*({.+?})\);',
1051 webpage, 'morph payload', default='{}'),
1052 playlist_id, fatal=False)
1054 components = try_get(morph_payload, lambda x: x['body']['components'], list) or []
1055 for component in components:
1056 if not isinstance(component, dict):
1058 lead_media = try_get(component, lambda x: x['props']['leadMedia'], dict)
1061 identifiers = lead_media.get('identifiers')
1062 if not identifiers or not isinstance(identifiers, dict):
1064 programme_id = identifiers.get('vpid') or identifiers.get('playablePid')
1065 if not programme_id:
1067 title = lead_media.get('title') or self._og_search_title(webpage)
1068 formats, subtitles = self._download_media_selector(programme_id)
1069 self._sort_formats(formats)
1070 description = lead_media.get('summary')
1071 uploader = lead_media.get('masterBrand')
1072 uploader_id = lead_media.get('mid')
1074 duration_d = lead_media.get('duration')
1075 if isinstance(duration_d, dict):
1076 duration = parse_duration(dict_get(
1077 duration_d, ('rawDuration', 'formattedDuration', 'spokenDuration')))
1081 'description': description,
1082 'duration': duration,
1083 'uploader': uploader,
1084 'uploader_id': uploader_id,
1086 'subtitles': subtitles,
1089 preload_state = self._parse_json(self._search_regex(
1090 r'window\.__PRELOADED_STATE__\s*=\s*({.+?});', webpage,
1091 'preload state', default='{}'), playlist_id, fatal=False)
1093 current_programme = preload_state.get('programmes', {}).get('current') or {}
1094 programme_id = current_programme.get('id')
1095 if current_programme and programme_id and current_programme.get('type') == 'playable_item':
1096 title = current_programme.get('titles', {}).get('tertiary') or playlist_title
1097 formats, subtitles = self._download_media_selector(programme_id)
1098 self._sort_formats(formats)
1099 synopses = current_programme.get('synopses') or {}
1100 network = current_programme.get('network') or {}
1101 duration = int_or_none(
1102 current_programme.get('duration', {}).get('value'))
1104 image_url = current_programme.get('image_url')
1106 thumbnail = image_url.replace('{recipe}', 'raw')
1110 'description': dict_get(synopses, ('long', 'medium', 'short')),
1111 'thumbnail': thumbnail,
1112 'duration': duration,
1113 'uploader': network.get('short_title'),
1114 'uploader_id': network.get('id'),
1116 'subtitles': subtitles,
1119 bbc3_config = self._parse_json(
1121 r'(?s)bbcthreeConfig\s*=\s*({.+?})\s*;\s*<', webpage,
1122 'bbcthree config', default='{}'),
1123 playlist_id, transform_source=js_to_json, fatal=False) or {}
1124 payload = bbc3_config.get('payload') or {}
1126 clip = payload.get('currentClip') or {}
1127 clip_vpid = clip.get('vpid')
1128 clip_title = clip.get('title')
1129 if clip_vpid and clip_title:
1130 formats, subtitles = self._download_media_selector(clip_vpid)
1131 self._sort_formats(formats)
1134 'title': clip_title,
1135 'thumbnail': dict_get(clip, ('poster', 'imageUrl')),
1136 'description': clip.get('description'),
1137 'duration': parse_duration(clip.get('duration')),
1139 'subtitles': subtitles,
1141 bbc3_playlist = try_get(
1142 payload, lambda x: x['content']['bbcMedia']['playlist'],
1145 playlist_title = bbc3_playlist.get('title') or playlist_title
1146 thumbnail = bbc3_playlist.get('holdingImageURL')
1148 for bbc3_item in bbc3_playlist['items']:
1149 programme_id = bbc3_item.get('versionID')
1150 if not programme_id:
1152 formats, subtitles = self._download_media_selector(programme_id)
1153 self._sort_formats(formats)
1156 'title': playlist_title,
1157 'thumbnail': thumbnail,
1158 'timestamp': timestamp,
1160 'subtitles': subtitles,
1162 return self.playlist_result(
1163 entries, playlist_id, playlist_title, playlist_description)
1165 initial_data = self._parse_json(self._search_regex(
1166 r'window\.__INITIAL_DATA__\s*=\s*({.+?});', webpage,
1167 'preload state', default='{}'), playlist_id, fatal=False)
1169 def parse_media(media):
1172 for item in (try_get(media, lambda x: x['media']['items'], list) or []):
1173 item_id = item.get('id')
1174 item_title = item.get('title')
1175 if not (item_id and item_title):
1177 formats, subtitles = self._download_media_selector(item_id)
1178 self._sort_formats(formats)
1180 blocks = try_get(media, lambda x: x['summary']['blocks'], list)
1183 for block in blocks:
1184 text = try_get(block, lambda x: x['model']['text'], compat_str)
1186 summary.append(text)
1188 item_desc = '\n\n'.join(summary)
1190 for meta in try_get(media, lambda x: x['metadata']['items'], list) or []:
1191 if try_get(meta, lambda x: x['label']) == 'Published':
1192 item_time = unified_timestamp(meta.get('timestamp'))
1196 'title': item_title,
1197 'thumbnail': item.get('holdingImageUrl'),
1199 'subtitles': subtitles,
1200 'timestamp': item_time,
1201 'description': strip_or_none(item_desc),
1203 for resp in (initial_data.get('data') or {}).values():
1204 name = resp.get('name')
1205 if name == 'media-experience':
1206 parse_media(try_get(resp, lambda x: x['data']['initialItem']['mediaItem'], dict))
1207 elif name == 'article':
1208 for block in (try_get(resp, lambda x: x['data']['blocks'], list) or []):
1209 if block.get('type') != 'media':
1211 parse_media(block.get('model'))
1212 return self.playlist_result(
1213 entries, playlist_id, playlist_title, playlist_description)
1215 def extract_all(pattern):
1216 return list(filter(None, map(
1217 lambda s: self._parse_json(s, playlist_id, fatal=False),
1218 re.findall(pattern, webpage))))
1220 # Multiple video article (e.g.
1221 # http://www.bbc.co.uk/blogs/adamcurtis/entries/3662a707-0af9-3149-963f-47bea720b460)
1222 EMBED_URL = r'https?://(?:www\.)?bbc\.co\.uk/(?:[^/]+/)+%s(?:\b[^"]+)?
' % self._ID_REGEX
1224 for match in extract_all(r'new\s
+SMP\
(({.+?}
)\
)'):
1225 embed_url = match.get('playerSettings
', {}).get('externalEmbedUrl
')
1226 if embed_url and re.match(EMBED_URL, embed_url):
1227 entries.append(embed_url)
1228 entries.extend(re.findall(
1229 r'setPlaylist\
("(%s)"\
)' % EMBED_URL, webpage))
1231 return self.playlist_result(
1232 [self.url_result(entry_, 'BBCCoUk
') for entry_ in entries],
1233 playlist_id, playlist_title, playlist_description)
1235 # Multiple video article (e.g. http://www.bbc.com/news/world-europe-32668511)
1236 medias = extract_all(r"data-media-meta='({[^']+}
)'")
1239 # Single video article (e.g. http://www.bbc.com/news/video_and_audio/international)
1240 media_asset = self._search_regex(
1241 r'mediaAssetPage\
.init\
(\s
*({.+?}
), "/',
1242 webpage, 'media asset', default=None)
1244 media_asset_page = self._parse_json(media_asset, playlist_id, fatal=False)
1246 for video in media_asset_page.get('videos', {}).values():
1247 medias.extend(video.values())
1250 # Multiple video playlist with single `now playing` entry (e.g.
1251 # http://www.bbc.com/news/video_and_audio/must_see/33767813)
1252 vxp_playlist = self._parse_json(
1254 r'<script[^>]+class="vxp
-playlist
-data
"[^>]+type="application
/json
"[^>]*>([^<]+)</script>',
1255 webpage, 'playlist data'),
1257 playlist_medias = []
1258 for item in vxp_playlist:
1259 media = item.get('media')
1262 playlist_medias.append(media)
1263 # Download single video if found media with asset id matching the video id from URL
1264 if item.get('advert', {}).get('assetId') == playlist_id:
1267 # Fallback to the whole playlist
1269 medias = playlist_medias
1272 for num, media_meta in enumerate(medias, start=1):
1273 formats, subtitles = self._extract_from_media_meta(media_meta, playlist_id)
1274 if not formats and not self.get_param('ignore_no_formats'):
1276 self._sort_formats(formats)
1278 video_id = media_meta.get('externalId')
1280 video_id = playlist_id if len(medias) == 1 else '%s-%s' % (playlist_id, num)
1282 title = media_meta.get('caption')
1284 title = playlist_title if len(medias) == 1 else '%s - Video %s' % (playlist_title, num)
1286 duration = int_or_none(media_meta.get('durationInSeconds')) or parse_duration(media_meta.get('duration'))
1289 for image in media_meta.get('images', {}).values():
1290 images.extend(image.values())
1291 if 'image' in media_meta:
1292 images.append(media_meta['image'])
1295 'url': image.get('href'),
1296 'width': int_or_none(image.get('width')),
1297 'height': int_or_none(image.get('height')),
1298 } for image in images]
1303 'thumbnails': thumbnails,
1304 'duration': duration,
1305 'timestamp': timestamp,
1307 'subtitles': subtitles,
1310 return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)
1313 class BBCCoUkArticleIE(InfoExtractor):
1314 _VALID_URL = r'https?://(?:www\.)?bbc\.co\.uk/programmes/articles/(?P<id>[a-zA-Z0-9]+)'
1315 IE_NAME = 'bbc.co.uk:article'
1316 IE_DESC = 'BBC articles'
1319 'url': 'http://www.bbc.co.uk/programmes/articles/3jNQLTMrPlYGTBn0WV6M2MS/not-your-typical-role-model-ada-lovelace-the-19th-century-programmer',
1321 'id': '3jNQLTMrPlYGTBn0WV6M2MS',
1322 'title': 'Calculating Ada: The Countess of Computing - Not your typical role model: Ada Lovelace the 19th century programmer - BBC Four',
1323 'description': 'Hannah Fry reveals some of her surprising discoveries about Ada Lovelace during filming.',
1325 'playlist_count': 4,
1326 'add_ie': ['BBCCoUk'],
1329 def _real_extract(self, url):
1330 playlist_id = self._match_id(url)
1332 webpage = self._download_webpage(url, playlist_id)
1334 title = self._og_search_title(webpage)
1335 description = self._og_search_description(webpage).strip()
1337 entries = [self.url_result(programme_url) for programme_url in re.findall(
1338 r'<div[^>]+typeof="Clip
"[^>]+resource="([^
"]+)"', webpage)]
1340 return self.playlist_result(entries, playlist_id, title, description)
1343 class BBCCoUkPlaylistBaseIE(InfoExtractor):
1344 def _entries(self, webpage, url, playlist_id):
1345 single_page = 'page
' in compat_urlparse.parse_qs(
1346 compat_urlparse.urlparse(url).query)
1347 for page_num in itertools.count(2):
1348 for video_id in re.findall(
1349 self._VIDEO_ID_TEMPLATE % BBCCoUkIE._ID_REGEX, webpage):
1350 yield self.url_result(
1351 self._URL_TEMPLATE % video_id, BBCCoUkIE.ie_key())
1354 next_page = self._search_regex(
1355 r'<li
[^
>]+class=(["\'])pagination_+next\1[^>]*><a[^>]+href=(["\'])(?P
<url
>(?
:(?
!\
2).)+)\
2',
1356 webpage, 'next page url
', default=None, group='url
')
1359 webpage = self._download_webpage(
1360 compat_urlparse.urljoin(url, next_page), playlist_id,
1361 'Downloading page
%d' % page_num, page_num)
1363 def _real_extract(self, url):
1364 playlist_id = self._match_id(url)
1366 webpage = self._download_webpage(url, playlist_id)
1368 title, description = self._extract_title_and_description(webpage)
1370 return self.playlist_result(
1371 self._entries(webpage, url, playlist_id),
1372 playlist_id, title, description)
1375 class BBCCoUkIPlayerPlaylistBaseIE(InfoExtractor):
1376 _VALID_URL_TMPL = r'https?
://(?
:www\
.)?bbc\
.co\
.uk
/iplayer
/%%s/(?P
<id>%s)' % BBCCoUkIE._ID_REGEX
1379 def _get_default(episode, key, default_key='default
'):
1380 return try_get(episode, lambda x: x[key][default_key])
1382 def _get_description(self, data):
1383 synopsis = data.get(self._DESCRIPTION_KEY) or {}
1384 return dict_get(synopsis, ('large
', 'medium
', 'small
'))
1386 def _fetch_page(self, programme_id, per_page, series_id, page):
1387 elements = self._get_elements(self._call_api(
1388 programme_id, per_page, page + 1, series_id))
1389 for element in elements:
1390 episode = self._get_episode(element)
1391 episode_id = episode.get('id')
1395 image = self._get_episode_image(episode)
1397 thumbnail = image.replace('{recipe}
', 'raw
')
1398 category = self._get_default(episode, 'labels
', 'category
')
1402 'title
': self._get_episode_field(episode, 'subtitle
'),
1403 'url
': 'https
://www
.bbc
.co
.uk
/iplayer
/episode
/' + episode_id,
1404 'thumbnail
': thumbnail,
1405 'description
': self._get_description(episode),
1406 'categories
': [category] if category else None,
1407 'series
': self._get_episode_field(episode, 'title
'),
1408 'ie_key
': BBCCoUkIE.ie_key(),
1411 def _real_extract(self, url):
1412 pid = self._match_id(url)
1413 qs = compat_parse_qs(compat_urllib_parse_urlparse(url).query)
1414 series_id = qs.get('seriesId
', [None])[0]
1415 page = qs.get('page
', [None])[0]
1416 per_page = 36 if page else self._PAGE_SIZE
1417 fetch_page = functools.partial(self._fetch_page, pid, per_page, series_id)
1418 entries = fetch_page(int(page) - 1) if page else OnDemandPagedList(fetch_page, self._PAGE_SIZE)
1419 playlist_data = self._get_playlist_data(self._call_api(pid, 1))
1420 return self.playlist_result(
1421 entries, pid, self._get_playlist_title(playlist_data),
1422 self._get_description(playlist_data))
1425 class BBCCoUkIPlayerEpisodesIE(BBCCoUkIPlayerPlaylistBaseIE):
1426 IE_NAME = 'bbc
.co
.uk
:iplayer
:episodes
'
1427 _VALID_URL = BBCCoUkIPlayerPlaylistBaseIE._VALID_URL_TMPL % 'episodes
'
1429 'url
': 'http
://www
.bbc
.co
.uk
/iplayer
/episodes
/b05rcz9v
',
1432 'title
': 'The Disappearance
',
1433 'description
': 'md5
:58eb101aee3116bad4da05f91179c0cb
',
1435 'playlist_mincount
': 8,
1438 'url
': 'https
://www
.bbc
.co
.uk
/iplayer
/episodes
/b094m5t9
/doctor
-foster
',
1441 'title
': 'Doctor Foster
',
1442 'description
': 'md5
:5aa9195fad900e8e14b52acd765a9fd6
',
1444 'playlist_mincount
': 10,
1447 'url
': 'https
://www
.bbc
.co
.uk
/iplayer
/episodes
/b094m5t9
/doctor
-foster?seriesId
=b094m6nv
',
1450 'title
': 'Doctor Foster
',
1451 'description
': 'md5
:5aa9195fad900e8e14b52acd765a9fd6
',
1453 'playlist_mincount
': 5,
1456 'url
': 'https
://www
.bbc
.co
.uk
/iplayer
/episodes
/m0004c4v
/beechgrove
',
1459 'title
': 'Beechgrove
',
1460 'description
': 'Gardening show that celebrates Scottish horticulture
and growing conditions
.',
1462 'playlist_mincount
': 37,
1465 'url
': 'https
://www
.bbc
.co
.uk
/iplayer
/episodes
/m0004c4v
/beechgrove?page
=2',
1468 'title
': 'Beechgrove
',
1469 'description
': 'Gardening show that celebrates Scottish horticulture
and growing conditions
.',
1471 'playlist_mincount
': 1,
1474 _DESCRIPTION_KEY = 'synopsis
'
1476 def _get_episode_image(self, episode):
1477 return self._get_default(episode, 'image
')
1479 def _get_episode_field(self, episode, field):
1480 return self._get_default(episode, field)
1483 def _get_elements(data):
1484 return data['entities
']['results
']
1487 def _get_episode(element):
1488 return element.get('episode
') or {}
1490 def _call_api(self, pid, per_page, page=1, series_id=None):
1494 'perPage
': per_page,
1497 variables['sliceId
'] = series_id
1498 return self._download_json(
1499 'https
://graph
.ibl
.api
.bbc
.co
.uk
/', pid, headers={
1500 'Content
-Type
': 'application
/json
'
1501 }, data=json.dumps({
1502 'id': '5692d93d5aac8d796a0305e895e61551
',
1503 'variables
': variables,
1504 }).encode('utf
-8'))['data
']['programme
']
1507 def _get_playlist_data(data):
1510 def _get_playlist_title(self, data):
1511 return self._get_default(data, 'title
')
1514 class BBCCoUkIPlayerGroupIE(BBCCoUkIPlayerPlaylistBaseIE):
1515 IE_NAME = 'bbc
.co
.uk
:iplayer
:group
'
1516 _VALID_URL = BBCCoUkIPlayerPlaylistBaseIE._VALID_URL_TMPL % 'group
'
1518 # Available for over a year unlike 30 days for most other programmes
1519 'url
': 'http
://www
.bbc
.co
.uk
/iplayer
/group
/p02tcc32
',
1522 'title
': 'Bohemian Icons
',
1523 'description
': 'md5
:683e901041b2fe9ba596f2ab04c4dbe7
',
1525 'playlist_mincount
': 10,
1528 'url
': 'https
://www
.bbc
.co
.uk
/iplayer
/group
/p081d7j7
',
1531 'title
': 'Music
in Scotland
',
1532 'description
': 'Perfomances
in Scotland
and programmes featuring Scottish acts
.',
1534 'playlist_mincount
': 47,
1537 'url
': 'https
://www
.bbc
.co
.uk
/iplayer
/group
/p081d7j7?page
=2',
1540 'title
': 'Music
in Scotland
',
1541 'description
': 'Perfomances
in Scotland
and programmes featuring Scottish acts
.',
1543 'playlist_mincount
': 11,
1546 _DESCRIPTION_KEY = 'synopses
'
1548 def _get_episode_image(self, episode):
1549 return self._get_default(episode, 'images
', 'standard
')
1551 def _get_episode_field(self, episode, field):
1552 return episode.get(field)
1555 def _get_elements(data):
1556 return data['elements
']
1559 def _get_episode(element):
1562 def _call_api(self, pid, per_page, page=1, series_id=None):
1563 return self._download_json(
1564 'http
://ibl
.api
.bbc
.co
.uk
/ibl
/v1
/groups
/%s/episodes
' % pid,
1567 'per_page
': per_page,
1568 })['group_episodes
']
1571 def _get_playlist_data(data):
1572 return data['group
']
1574 def _get_playlist_title(self, data):
1575 return data.get('title
')
1578 class BBCCoUkPlaylistIE(BBCCoUkPlaylistBaseIE):
1579 IE_NAME = 'bbc
.co
.uk
:playlist
'
1580 _VALID_URL = r'https?
://(?
:www\
.)?bbc\
.co\
.uk
/programmes
/(?P
<id>%s)/(?
:episodes|broadcasts|clips
)' % BBCCoUkIE._ID_REGEX
1581 _URL_TEMPLATE = 'http
://www
.bbc
.co
.uk
/programmes
/%s'
1582 _VIDEO_ID_TEMPLATE = r'data
-pid
=["\'](%s)'
1584 'url': 'http://www.bbc.co.uk/programmes/b05rcz9v/clips',
1587 'title': 'The Disappearance - Clips - BBC Four',
1588 'description': 'French thriller serial about a missing teenager.',
1590 'playlist_mincount': 7,
1592 # multipage playlist, explicit page
1593 'url': 'http://www.bbc.co.uk/programmes/b00mfl7n/clips?page=1',
1596 'title': 'Frozen Planet - Clips - BBC One',
1597 'description': 'md5:65dcbf591ae628dafe32aa6c4a4a0d8c',
1599 'playlist_mincount': 24,
1601 # multipage playlist, all pages
1602 'url': 'http://www.bbc.co.uk/programmes/b00mfl7n/clips',
1605 'title': 'Frozen Planet - Clips - BBC One',
1606 'description': 'md5:65dcbf591ae628dafe32aa6c4a4a0d8c',
1608 'playlist_mincount': 142,
1610 'url': 'http://www.bbc.co.uk/programmes/b05rcz9v/broadcasts/2016/06',
1611 'only_matching': True,
1613 'url': 'http://www.bbc.co.uk/programmes/b05rcz9v/clips',
1614 'only_matching': True,
1616 'url': 'http://www.bbc.co.uk/programmes/b055jkys/episodes/player',
1617 'only_matching': True,
1620 def _extract_title_and_description(self, webpage):
1621 title = self._og_search_title(webpage, fatal=False)
1622 description = self._og_search_description(webpage)
1623 return title, description