You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1231 lines
53 KiB

8 years ago
10 years ago
8 years ago
9 years ago
8 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import itertools
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. clean_html,
  8. dict_get,
  9. ExtractorError,
  10. float_or_none,
  11. get_element_by_class,
  12. int_or_none,
  13. parse_duration,
  14. parse_iso8601,
  15. try_get,
  16. unescapeHTML,
  17. urlencode_postdata,
  18. urljoin,
  19. )
  20. from ..compat import (
  21. compat_etree_fromstring,
  22. compat_HTTPError,
  23. compat_urlparse,
  24. )
  25. class BBCCoUkIE(InfoExtractor):
  26. IE_NAME = 'bbc.co.uk'
  27. IE_DESC = 'BBC iPlayer'
  28. _ID_REGEX = r'[pb][\da-z]{7}'
  29. _VALID_URL = r'''(?x)
  30. https?://
  31. (?:www\.)?bbc\.co\.uk/
  32. (?:
  33. programmes/(?!articles/)|
  34. iplayer(?:/[^/]+)?/(?:episode/|playlist/)|
  35. music/(?:clips|audiovideo/popular)[/#]|
  36. radio/player/
  37. )
  38. (?P<id>%s)(?!/(?:episodes|broadcasts|clips))
  39. ''' % _ID_REGEX
  40. _LOGIN_URL = 'https://account.bbc.com/signin'
  41. _NETRC_MACHINE = 'bbc'
  42. _MEDIASELECTOR_URLS = [
  43. # Provides HQ HLS streams with even better quality that pc mediaset but fails
  44. # with geolocation in some cases when it's even not geo restricted at all (e.g.
  45. # http://www.bbc.co.uk/programmes/b06bp7lf). Also may fail with selectionunavailable.
  46. 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/iptv-all/vpid/%s',
  47. 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/pc/vpid/%s',
  48. ]
  49. _MEDIASELECTION_NS = 'http://bbc.co.uk/2008/mp/mediaselection'
  50. _EMP_PLAYLIST_NS = 'http://bbc.co.uk/2008/emp/playlist'
  51. _NAMESPACES = (
  52. _MEDIASELECTION_NS,
  53. _EMP_PLAYLIST_NS,
  54. )
  55. _TESTS = [
  56. {
  57. 'url': 'http://www.bbc.co.uk/programmes/b039g8p7',
  58. 'info_dict': {
  59. 'id': 'b039d07m',
  60. 'ext': 'flv',
  61. 'title': 'Leonard Cohen, Kaleidoscope - BBC Radio 4',
  62. 'description': 'The Canadian poet and songwriter reflects on his musical career.',
  63. },
  64. 'params': {
  65. # rtmp download
  66. 'skip_download': True,
  67. }
  68. },
  69. {
  70. 'url': 'http://www.bbc.co.uk/iplayer/episode/b00yng5w/The_Man_in_Black_Series_3_The_Printed_Name/',
  71. 'info_dict': {
  72. 'id': 'b00yng1d',
  73. 'ext': 'flv',
  74. 'title': 'The Man in Black: Series 3: The Printed Name',
  75. 'description': "Mark Gatiss introduces Nicholas Pierpan's chilling tale of a writer's devilish pact with a mysterious man. Stars Ewan Bailey.",
  76. 'duration': 1800,
  77. },
  78. 'params': {
  79. # rtmp download
  80. 'skip_download': True,
  81. },
  82. 'skip': 'Episode is no longer available on BBC iPlayer Radio',
  83. },
  84. {
  85. 'url': 'http://www.bbc.co.uk/iplayer/episode/b03vhd1f/The_Voice_UK_Series_3_Blind_Auditions_5/',
  86. 'info_dict': {
  87. 'id': 'b00yng1d',
  88. 'ext': 'flv',
  89. 'title': 'The Voice UK: Series 3: Blind Auditions 5',
  90. '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.',
  91. 'duration': 5100,
  92. },
  93. 'params': {
  94. # rtmp download
  95. 'skip_download': True,
  96. },
  97. 'skip': 'Currently BBC iPlayer TV programmes are available to play in the UK only',
  98. },
  99. {
  100. 'url': 'http://www.bbc.co.uk/iplayer/episode/p026c7jt/tomorrows-worlds-the-unearthly-history-of-science-fiction-2-invasion',
  101. 'info_dict': {
  102. 'id': 'b03k3pb7',
  103. 'ext': 'flv',
  104. 'title': "Tomorrow's Worlds: The Unearthly History of Science Fiction",
  105. 'description': '2. Invasion',
  106. 'duration': 3600,
  107. },
  108. 'params': {
  109. # rtmp download
  110. 'skip_download': True,
  111. },
  112. 'skip': 'Currently BBC iPlayer TV programmes are available to play in the UK only',
  113. }, {
  114. 'url': 'http://www.bbc.co.uk/programmes/b04v20dw',
  115. 'info_dict': {
  116. 'id': 'b04v209v',
  117. 'ext': 'flv',
  118. 'title': 'Pete Tong, The Essential New Tune Special',
  119. 'description': "Pete has a very special mix - all of 2014's Essential New Tunes!",
  120. 'duration': 10800,
  121. },
  122. 'params': {
  123. # rtmp download
  124. 'skip_download': True,
  125. },
  126. 'skip': 'Episode is no longer available on BBC iPlayer Radio',
  127. }, {
  128. 'url': 'http://www.bbc.co.uk/music/clips/p022h44b',
  129. 'note': 'Audio',
  130. 'info_dict': {
  131. 'id': 'p022h44j',
  132. 'ext': 'flv',
  133. 'title': 'BBC Proms Music Guides, Rachmaninov: Symphonic Dances',
  134. 'description': "In this Proms Music Guide, Andrew McGregor looks at Rachmaninov's Symphonic Dances.",
  135. 'duration': 227,
  136. },
  137. 'params': {
  138. # rtmp download
  139. 'skip_download': True,
  140. }
  141. }, {
  142. 'url': 'http://www.bbc.co.uk/music/clips/p025c0zz',
  143. 'note': 'Video',
  144. 'info_dict': {
  145. 'id': 'p025c103',
  146. 'ext': 'flv',
  147. 'title': 'Reading and Leeds Festival, 2014, Rae Morris - Closer (Live on BBC Three)',
  148. 'description': 'Rae Morris performs Closer for BBC Three at Reading 2014',
  149. 'duration': 226,
  150. },
  151. 'params': {
  152. # rtmp download
  153. 'skip_download': True,
  154. }
  155. }, {
  156. 'url': 'http://www.bbc.co.uk/iplayer/episode/b054fn09/ad/natural-world-20152016-2-super-powered-owls',
  157. 'info_dict': {
  158. 'id': 'p02n76xf',
  159. 'ext': 'flv',
  160. 'title': 'Natural World, 2015-2016: 2. Super Powered Owls',
  161. 'description': 'md5:e4db5c937d0e95a7c6b5e654d429183d',
  162. 'duration': 3540,
  163. },
  164. 'params': {
  165. # rtmp download
  166. 'skip_download': True,
  167. },
  168. 'skip': 'geolocation',
  169. }, {
  170. 'url': 'http://www.bbc.co.uk/iplayer/episode/b05zmgwn/royal-academy-summer-exhibition',
  171. 'info_dict': {
  172. 'id': 'b05zmgw1',
  173. 'ext': 'flv',
  174. '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.',
  175. 'title': 'Royal Academy Summer Exhibition',
  176. 'duration': 3540,
  177. },
  178. 'params': {
  179. # rtmp download
  180. 'skip_download': True,
  181. },
  182. 'skip': 'geolocation',
  183. }, {
  184. # iptv-all mediaset fails with geolocation however there is no geo restriction
  185. # for this programme at all
  186. 'url': 'http://www.bbc.co.uk/programmes/b06rkn85',
  187. 'info_dict': {
  188. 'id': 'b06rkms3',
  189. 'ext': 'flv',
  190. 'title': "Best of the Mini-Mixes 2015: Part 3, Annie Mac's Friday Night - BBC Radio 1",
  191. 'description': "Annie has part three in the Best of the Mini-Mixes 2015, plus the year's Most Played!",
  192. },
  193. 'params': {
  194. # rtmp download
  195. 'skip_download': True,
  196. },
  197. 'skip': 'Now it\'s really geo-restricted',
  198. }, {
  199. # compact player (https://github.com/rg3/youtube-dl/issues/8147)
  200. 'url': 'http://www.bbc.co.uk/programmes/p028bfkf/player',
  201. 'info_dict': {
  202. 'id': 'p028bfkj',
  203. 'ext': 'flv',
  204. 'title': 'Extract from BBC documentary Look Stranger - Giant Leeks and Magic Brews',
  205. 'description': 'Extract from BBC documentary Look Stranger - Giant Leeks and Magic Brews',
  206. },
  207. 'params': {
  208. # rtmp download
  209. 'skip_download': True,
  210. },
  211. }, {
  212. 'url': 'http://www.bbc.co.uk/iplayer/playlist/p01dvks4',
  213. 'only_matching': True,
  214. }, {
  215. 'url': 'http://www.bbc.co.uk/music/clips#p02frcc3',
  216. 'only_matching': True,
  217. }, {
  218. 'url': 'http://www.bbc.co.uk/iplayer/cbeebies/episode/b0480276/bing-14-atchoo',
  219. 'only_matching': True,
  220. }, {
  221. 'url': 'http://www.bbc.co.uk/radio/player/p03cchwf',
  222. 'only_matching': True,
  223. }, {
  224. 'url': 'https://www.bbc.co.uk/music/audiovideo/popular#p055bc55',
  225. 'only_matching': True,
  226. }]
  227. _USP_RE = r'/([^/]+?)\.ism(?:\.hlsv2\.ism)?/[^/]+\.m3u8'
  228. def _login(self):
  229. username, password = self._get_login_info()
  230. if username is None:
  231. return
  232. login_page = self._download_webpage(
  233. self._LOGIN_URL, None, 'Downloading signin page')
  234. login_form = self._hidden_inputs(login_page)
  235. login_form.update({
  236. 'username': username,
  237. 'password': password,
  238. })
  239. post_url = urljoin(self._LOGIN_URL, self._search_regex(
  240. r'<form[^>]+action=(["\'])(?P<url>.+?)\1', login_page,
  241. 'post url', default=self._LOGIN_URL, group='url'))
  242. response, urlh = self._download_webpage_handle(
  243. post_url, None, 'Logging in', data=urlencode_postdata(login_form),
  244. headers={'Referer': self._LOGIN_URL})
  245. if self._LOGIN_URL in urlh.geturl():
  246. error = clean_html(get_element_by_class('form-message', response))
  247. if error:
  248. raise ExtractorError(
  249. 'Unable to login: %s' % error, expected=True)
  250. raise ExtractorError('Unable to log in')
  251. def _real_initialize(self):
  252. self._login()
  253. class MediaSelectionError(Exception):
  254. def __init__(self, id):
  255. self.id = id
  256. def _extract_asx_playlist(self, connection, programme_id):
  257. asx = self._download_xml(connection.get('href'), programme_id, 'Downloading ASX playlist')
  258. return [ref.get('href') for ref in asx.findall('./Entry/ref')]
  259. def _extract_items(self, playlist):
  260. return playlist.findall('./{%s}item' % self._EMP_PLAYLIST_NS)
  261. def _findall_ns(self, element, xpath):
  262. elements = []
  263. for ns in self._NAMESPACES:
  264. elements.extend(element.findall(xpath % ns))
  265. return elements
  266. def _extract_medias(self, media_selection):
  267. error = media_selection.find('./{%s}error' % self._MEDIASELECTION_NS)
  268. if error is None:
  269. media_selection.find('./{%s}error' % self._EMP_PLAYLIST_NS)
  270. if error is not None:
  271. raise BBCCoUkIE.MediaSelectionError(error.get('id'))
  272. return self._findall_ns(media_selection, './{%s}media')
  273. def _extract_connections(self, media):
  274. return self._findall_ns(media, './{%s}connection')
  275. def _get_subtitles(self, media, programme_id):
  276. subtitles = {}
  277. for connection in self._extract_connections(media):
  278. captions = self._download_xml(connection.get('href'), programme_id, 'Downloading captions')
  279. lang = captions.get('{http://www.w3.org/XML/1998/namespace}lang', 'en')
  280. subtitles[lang] = [
  281. {
  282. 'url': connection.get('href'),
  283. 'ext': 'ttml',
  284. },
  285. ]
  286. return subtitles
  287. def _raise_extractor_error(self, media_selection_error):
  288. raise ExtractorError(
  289. '%s returned error: %s' % (self.IE_NAME, media_selection_error.id),
  290. expected=True)
  291. def _download_media_selector(self, programme_id):
  292. last_exception = None
  293. for mediaselector_url in self._MEDIASELECTOR_URLS:
  294. try:
  295. return self._download_media_selector_url(
  296. mediaselector_url % programme_id, programme_id)
  297. except BBCCoUkIE.MediaSelectionError as e:
  298. if e.id in ('notukerror', 'geolocation', 'selectionunavailable'):
  299. last_exception = e
  300. continue
  301. self._raise_extractor_error(e)
  302. self._raise_extractor_error(last_exception)
  303. def _download_media_selector_url(self, url, programme_id=None):
  304. try:
  305. media_selection = self._download_xml(
  306. url, programme_id, 'Downloading media selection XML')
  307. except ExtractorError as ee:
  308. if isinstance(ee.cause, compat_HTTPError) and ee.cause.code in (403, 404):
  309. media_selection = compat_etree_fromstring(ee.cause.read().decode('utf-8'))
  310. else:
  311. raise
  312. return self._process_media_selector(media_selection, programme_id)
  313. def _process_media_selector(self, media_selection, programme_id):
  314. formats = []
  315. subtitles = None
  316. urls = []
  317. for media in self._extract_medias(media_selection):
  318. kind = media.get('kind')
  319. if kind in ('video', 'audio'):
  320. bitrate = int_or_none(media.get('bitrate'))
  321. encoding = media.get('encoding')
  322. service = media.get('service')
  323. width = int_or_none(media.get('width'))
  324. height = int_or_none(media.get('height'))
  325. file_size = int_or_none(media.get('media_file_size'))
  326. for connection in self._extract_connections(media):
  327. href = connection.get('href')
  328. if href in urls:
  329. continue
  330. if href:
  331. urls.append(href)
  332. conn_kind = connection.get('kind')
  333. protocol = connection.get('protocol')
  334. supplier = connection.get('supplier')
  335. transfer_format = connection.get('transferFormat')
  336. format_id = supplier or conn_kind or protocol
  337. if service:
  338. format_id = '%s_%s' % (service, format_id)
  339. # ASX playlist
  340. if supplier == 'asx':
  341. for i, ref in enumerate(self._extract_asx_playlist(connection, programme_id)):
  342. formats.append({
  343. 'url': ref,
  344. 'format_id': 'ref%s_%s' % (i, format_id),
  345. })
  346. elif transfer_format == 'dash':
  347. formats.extend(self._extract_mpd_formats(
  348. href, programme_id, mpd_id=format_id, fatal=False))
  349. elif transfer_format == 'hls':
  350. formats.extend(self._extract_m3u8_formats(
  351. href, programme_id, ext='mp4', entry_protocol='m3u8_native',
  352. m3u8_id=format_id, fatal=False))
  353. if re.search(self._USP_RE, href):
  354. usp_formats = self._extract_m3u8_formats(
  355. re.sub(self._USP_RE, r'/\1.ism/\1.m3u8', href),
  356. programme_id, ext='mp4', entry_protocol='m3u8_native',
  357. m3u8_id=format_id, fatal=False)
  358. for f in usp_formats:
  359. if f.get('height') and f['height'] > 720:
  360. continue
  361. formats.append(f)
  362. elif transfer_format == 'hds':
  363. formats.extend(self._extract_f4m_formats(
  364. href, programme_id, f4m_id=format_id, fatal=False))
  365. else:
  366. if not service and not supplier and bitrate:
  367. format_id += '-%d' % bitrate
  368. fmt = {
  369. 'format_id': format_id,
  370. 'filesize': file_size,
  371. }
  372. if kind == 'video':
  373. fmt.update({
  374. 'width': width,
  375. 'height': height,
  376. 'tbr': bitrate,
  377. 'vcodec': encoding,
  378. })
  379. else:
  380. fmt.update({
  381. 'abr': bitrate,
  382. 'acodec': encoding,
  383. 'vcodec': 'none',
  384. })
  385. if protocol in ('http', 'https'):
  386. # Direct link
  387. fmt.update({
  388. 'url': href,
  389. })
  390. elif protocol == 'rtmp':
  391. application = connection.get('application', 'ondemand')
  392. auth_string = connection.get('authString')
  393. identifier = connection.get('identifier')
  394. server = connection.get('server')
  395. fmt.update({
  396. 'url': '%s://%s/%s?%s' % (protocol, server, application, auth_string),
  397. 'play_path': identifier,
  398. 'app': '%s?%s' % (application, auth_string),
  399. 'page_url': 'http://www.bbc.co.uk',
  400. 'player_url': 'http://www.bbc.co.uk/emp/releases/iplayer/revisions/617463_618125_4/617463_618125_4_emp.swf',
  401. 'rtmp_live': False,
  402. 'ext': 'flv',
  403. })
  404. else:
  405. continue
  406. formats.append(fmt)
  407. elif kind == 'captions':
  408. subtitles = self.extract_subtitles(media, programme_id)
  409. return formats, subtitles
  410. def _download_playlist(self, playlist_id):
  411. try:
  412. playlist = self._download_json(
  413. 'http://www.bbc.co.uk/programmes/%s/playlist.json' % playlist_id,
  414. playlist_id, 'Downloading playlist JSON')
  415. version = playlist.get('defaultAvailableVersion')
  416. if version:
  417. smp_config = version['smpConfig']
  418. title = smp_config['title']
  419. description = smp_config['summary']
  420. for item in smp_config['items']:
  421. kind = item['kind']
  422. if kind not in ('programme', 'radioProgramme'):
  423. continue
  424. programme_id = item.get('vpid')
  425. duration = int_or_none(item.get('duration'))
  426. formats, subtitles = self._download_media_selector(programme_id)
  427. return programme_id, title, description, duration, formats, subtitles
  428. except ExtractorError as ee:
  429. if not (isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 404):
  430. raise
  431. # fallback to legacy playlist
  432. return self._process_legacy_playlist(playlist_id)
  433. def _process_legacy_playlist_url(self, url, display_id):
  434. playlist = self._download_legacy_playlist_url(url, display_id)
  435. return self._extract_from_legacy_playlist(playlist, display_id)
  436. def _process_legacy_playlist(self, playlist_id):
  437. return self._process_legacy_playlist_url(
  438. 'http://www.bbc.co.uk/iplayer/playlist/%s' % playlist_id, playlist_id)
  439. def _download_legacy_playlist_url(self, url, playlist_id=None):
  440. return self._download_xml(
  441. url, playlist_id, 'Downloading legacy playlist XML')
  442. def _extract_from_legacy_playlist(self, playlist, playlist_id):
  443. no_items = playlist.find('./{%s}noItems' % self._EMP_PLAYLIST_NS)
  444. if no_items is not None:
  445. reason = no_items.get('reason')
  446. if reason == 'preAvailability':
  447. msg = 'Episode %s is not yet available' % playlist_id
  448. elif reason == 'postAvailability':
  449. msg = 'Episode %s is no longer available' % playlist_id
  450. elif reason == 'noMedia':
  451. msg = 'Episode %s is not currently available' % playlist_id
  452. else:
  453. msg = 'Episode %s is not available: %s' % (playlist_id, reason)
  454. raise ExtractorError(msg, expected=True)
  455. for item in self._extract_items(playlist):
  456. kind = item.get('kind')
  457. if kind not in ('programme', 'radioProgramme'):
  458. continue
  459. title = playlist.find('./{%s}title' % self._EMP_PLAYLIST_NS).text
  460. description_el = playlist.find('./{%s}summary' % self._EMP_PLAYLIST_NS)
  461. description = description_el.text if description_el is not None else None
  462. def get_programme_id(item):
  463. def get_from_attributes(item):
  464. for p in('identifier', 'group'):
  465. value = item.get(p)
  466. if value and re.match(r'^[pb][\da-z]{7}$', value):
  467. return value
  468. get_from_attributes(item)
  469. mediator = item.find('./{%s}mediator' % self._EMP_PLAYLIST_NS)
  470. if mediator is not None:
  471. return get_from_attributes(mediator)
  472. programme_id = get_programme_id(item)
  473. duration = int_or_none(item.get('duration'))
  474. if programme_id:
  475. formats, subtitles = self._download_media_selector(programme_id)
  476. else:
  477. formats, subtitles = self._process_media_selector(item, playlist_id)
  478. programme_id = playlist_id
  479. return programme_id, title, description, duration, formats, subtitles
  480. def _real_extract(self, url):
  481. group_id = self._match_id(url)
  482. webpage = self._download_webpage(url, group_id, 'Downloading video page')
  483. error = self._search_regex(
  484. r'<div\b[^>]+\bclass=["\']smp__message delta["\'][^>]*>([^<]+)<',
  485. webpage, 'error', default=None)
  486. if error:
  487. raise ExtractorError(error, expected=True)
  488. programme_id = None
  489. duration = None
  490. tviplayer = self._search_regex(
  491. r'mediator\.bind\(({.+?})\s*,\s*document\.getElementById',
  492. webpage, 'player', default=None)
  493. if tviplayer:
  494. player = self._parse_json(tviplayer, group_id).get('player', {})
  495. duration = int_or_none(player.get('duration'))
  496. programme_id = player.get('vpid')
  497. if not programme_id:
  498. programme_id = self._search_regex(
  499. r'"vpid"\s*:\s*"(%s)"' % self._ID_REGEX, webpage, 'vpid', fatal=False, default=None)
  500. if programme_id:
  501. formats, subtitles = self._download_media_selector(programme_id)
  502. title = self._og_search_title(webpage, default=None) or self._html_search_regex(
  503. (r'<h2[^>]+id="parent-title"[^>]*>(.+?)</h2>',
  504. r'<div[^>]+class="info"[^>]*>\s*<h1>(.+?)</h1>'), webpage, 'title')
  505. description = self._search_regex(
  506. (r'<p class="[^"]*medium-description[^"]*">([^<]+)</p>',
  507. r'<div[^>]+class="info_+synopsis"[^>]*>([^<]+)</div>'),
  508. webpage, 'description', default=None)
  509. if not description:
  510. description = self._html_search_meta('description', webpage)
  511. else:
  512. programme_id, title, description, duration, formats, subtitles = self._download_playlist(group_id)
  513. self._sort_formats(formats)
  514. return {
  515. 'id': programme_id,
  516. 'title': title,
  517. 'description': description,
  518. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  519. 'duration': duration,
  520. 'formats': formats,
  521. 'subtitles': subtitles,
  522. }
  523. class BBCIE(BBCCoUkIE):
  524. IE_NAME = 'bbc'
  525. IE_DESC = 'BBC'
  526. _VALID_URL = r'https?://(?:www\.)?bbc\.(?:com|co\.uk)/(?:[^/]+/)+(?P<id>[^/#?]+)'
  527. _MEDIASELECTOR_URLS = [
  528. # Provides HQ HLS streams but fails with geolocation in some cases when it's
  529. # even not geo restricted at all
  530. 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/iptv-all/vpid/%s',
  531. # Provides more formats, namely direct mp4 links, but fails on some videos with
  532. # notukerror for non UK (?) users (e.g.
  533. # http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret)
  534. 'http://open.live.bbc.co.uk/mediaselector/4/mtis/stream/%s',
  535. # Provides fewer formats, but works everywhere for everybody (hopefully)
  536. 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/journalism-pc/vpid/%s',
  537. ]
  538. _TESTS = [{
  539. # article with multiple videos embedded with data-playable containing vpids
  540. 'url': 'http://www.bbc.com/news/world-europe-32668511',
  541. 'info_dict': {
  542. 'id': 'world-europe-32668511',
  543. 'title': 'Russia stages massive WW2 parade despite Western boycott',
  544. 'description': 'md5:00ff61976f6081841f759a08bf78cc9c',
  545. },
  546. 'playlist_count': 2,
  547. }, {
  548. # article with multiple videos embedded with data-playable (more videos)
  549. 'url': 'http://www.bbc.com/news/business-28299555',
  550. 'info_dict': {
  551. 'id': 'business-28299555',
  552. 'title': 'Farnborough Airshow: Video highlights',
  553. 'description': 'BBC reports and video highlights at the Farnborough Airshow.',
  554. },
  555. 'playlist_count': 9,
  556. 'skip': 'Save time',
  557. }, {
  558. # article with multiple videos embedded with `new SMP()`
  559. # broken
  560. 'url': 'http://www.bbc.co.uk/blogs/adamcurtis/entries/3662a707-0af9-3149-963f-47bea720b460',
  561. 'info_dict': {
  562. 'id': '3662a707-0af9-3149-963f-47bea720b460',
  563. 'title': 'BUGGER',
  564. },
  565. 'playlist_count': 18,
  566. }, {
  567. # single video embedded with data-playable containing vpid
  568. 'url': 'http://www.bbc.com/news/world-europe-32041533',
  569. 'info_dict': {
  570. 'id': 'p02mprgb',
  571. 'ext': 'mp4',
  572. 'title': 'Aerial footage showed the site of the crash in the Alps - courtesy BFM TV',
  573. 'description': 'md5:2868290467291b37feda7863f7a83f54',
  574. 'duration': 47,
  575. 'timestamp': 1427219242,
  576. 'upload_date': '20150324',
  577. },
  578. 'params': {
  579. # rtmp download
  580. 'skip_download': True,
  581. }
  582. }, {
  583. # article with single video embedded with data-playable containing XML playlist
  584. # with direct video links as progressiveDownloadUrl (for now these are extracted)
  585. # and playlist with f4m and m3u8 as streamingUrl
  586. 'url': 'http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu',
  587. 'info_dict': {
  588. 'id': '150615_telabyad_kentin_cogu',
  589. 'ext': 'mp4',
  590. 'title': "YPG: Tel Abyad'ın tamamı kontrolümüzde",
  591. 'description': 'md5:33a4805a855c9baf7115fcbde57e7025',
  592. 'timestamp': 1434397334,
  593. 'upload_date': '20150615',
  594. },
  595. 'params': {
  596. 'skip_download': True,
  597. }
  598. }, {
  599. # single video embedded with data-playable containing XML playlists (regional section)
  600. 'url': 'http://www.bbc.com/mundo/video_fotos/2015/06/150619_video_honduras_militares_hospitales_corrupcion_aw',
  601. 'info_dict': {
  602. 'id': '150619_video_honduras_militares_hospitales_corrupcion_aw',
  603. 'ext': 'mp4',
  604. 'title': 'Honduras militariza sus hospitales por nuevo escándalo de corrupción',
  605. 'description': 'md5:1525f17448c4ee262b64b8f0c9ce66c8',
  606. 'timestamp': 1434713142,
  607. 'upload_date': '20150619',
  608. },
  609. 'params': {
  610. 'skip_download': True,
  611. }
  612. }, {
  613. # single video from video playlist embedded with vxp-playlist-data JSON
  614. 'url': 'http://www.bbc.com/news/video_and_audio/must_see/33376376',
  615. 'info_dict': {
  616. 'id': 'p02w6qjc',
  617. 'ext': 'mp4',
  618. 'title': '''Judge Mindy Glazer: "I'm sorry to see you here... I always wondered what happened to you"''',
  619. 'duration': 56,
  620. 'description': '''Judge Mindy Glazer: "I'm sorry to see you here... I always wondered what happened to you"''',
  621. },
  622. 'params': {
  623. 'skip_download': True,
  624. }
  625. }, {
  626. # single video story with digitalData
  627. 'url': 'http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret',
  628. 'info_dict': {
  629. 'id': 'p02q6gc4',
  630. 'ext': 'flv',
  631. 'title': 'Sri Lanka’s spicy secret',
  632. 'description': 'As a new train line to Jaffna opens up the country’s north, travellers can experience a truly distinct slice of Tamil culture.',
  633. 'timestamp': 1437674293,
  634. 'upload_date': '20150723',
  635. },
  636. 'params': {
  637. # rtmp download
  638. 'skip_download': True,
  639. }
  640. }, {
  641. # single video story without digitalData
  642. 'url': 'http://www.bbc.com/autos/story/20130513-hyundais-rock-star',
  643. 'info_dict': {
  644. 'id': 'p018zqqg',
  645. 'ext': 'mp4',
  646. 'title': 'Hyundai Santa Fe Sport: Rock star',
  647. 'description': 'md5:b042a26142c4154a6e472933cf20793d',
  648. 'timestamp': 1415867444,
  649. 'upload_date': '20141113',
  650. },
  651. 'params': {
  652. # rtmp download
  653. 'skip_download': True,
  654. }
  655. }, {
  656. # single video embedded with Morph
  657. 'url': 'http://www.bbc.co.uk/sport/live/olympics/36895975',
  658. 'info_dict': {
  659. 'id': 'p041vhd0',
  660. 'ext': 'mp4',
  661. 'title': "Nigeria v Japan - Men's First Round",
  662. 'description': 'Live coverage of the first round from Group B at the Amazonia Arena.',
  663. 'duration': 7980,
  664. 'uploader': 'BBC Sport',
  665. 'uploader_id': 'bbc_sport',
  666. },
  667. 'params': {
  668. # m3u8 download
  669. 'skip_download': True,
  670. },
  671. 'skip': 'Georestricted to UK',
  672. }, {
  673. # single video with playlist.sxml URL in playlist param
  674. 'url': 'http://www.bbc.com/sport/0/football/33653409',
  675. 'info_dict': {
  676. 'id': 'p02xycnp',
  677. 'ext': 'mp4',
  678. 'title': 'Transfers: Cristiano Ronaldo to Man Utd, Arsenal to spend?',
  679. 'description': 'BBC Sport\'s David Ornstein has the latest transfer gossip, including rumours of a Manchester United return for Cristiano Ronaldo.',
  680. 'duration': 140,
  681. },
  682. 'params': {
  683. # rtmp download
  684. 'skip_download': True,
  685. }
  686. }, {
  687. # article with multiple videos embedded with playlist.sxml in playlist param
  688. 'url': 'http://www.bbc.com/sport/0/football/34475836',
  689. 'info_dict': {
  690. 'id': '34475836',
  691. 'title': 'Jurgen Klopp: Furious football from a witty and winning coach',
  692. 'description': 'Fast-paced football, wit, wisdom and a ready smile - why Liverpool fans should come to love new boss Jurgen Klopp.',
  693. },
  694. 'playlist_count': 3,
  695. }, {
  696. # school report article with single video
  697. 'url': 'http://www.bbc.co.uk/schoolreport/35744779',
  698. 'info_dict': {
  699. 'id': '35744779',
  700. 'title': 'School which breaks down barriers in Jerusalem',
  701. },
  702. 'playlist_count': 1,
  703. }, {
  704. # single video with playlist URL from weather section
  705. 'url': 'http://www.bbc.com/weather/features/33601775',
  706. 'only_matching': True,
  707. }, {
  708. # custom redirection to www.bbc.com
  709. 'url': 'http://www.bbc.co.uk/news/science-environment-33661876',
  710. 'only_matching': True,
  711. }, {
  712. # single video article embedded with data-media-vpid
  713. 'url': 'http://www.bbc.co.uk/sport/rowing/35908187',
  714. 'only_matching': True,
  715. }]
  716. @classmethod
  717. def suitable(cls, url):
  718. EXCLUDE_IE = (BBCCoUkIE, BBCCoUkArticleIE, BBCCoUkIPlayerPlaylistIE, BBCCoUkPlaylistIE)
  719. return (False if any(ie.suitable(url) for ie in EXCLUDE_IE)
  720. else super(BBCIE, cls).suitable(url))
  721. def _extract_from_media_meta(self, media_meta, video_id):
  722. # Direct links to media in media metadata (e.g.
  723. # http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu)
  724. # TODO: there are also f4m and m3u8 streams incorporated in playlist.sxml
  725. source_files = media_meta.get('sourceFiles')
  726. if source_files:
  727. return [{
  728. 'url': f['url'],
  729. 'format_id': format_id,
  730. 'ext': f.get('encoding'),
  731. 'tbr': float_or_none(f.get('bitrate'), 1000),
  732. 'filesize': int_or_none(f.get('filesize')),
  733. } for format_id, f in source_files.items() if f.get('url')], []
  734. programme_id = media_meta.get('externalId')
  735. if programme_id:
  736. return self._download_media_selector(programme_id)
  737. # Process playlist.sxml as legacy playlist
  738. href = media_meta.get('href')
  739. if href:
  740. playlist = self._download_legacy_playlist_url(href)
  741. _, _, _, _, formats, subtitles = self._extract_from_legacy_playlist(playlist, video_id)
  742. return formats, subtitles
  743. return [], []
  744. def _extract_from_playlist_sxml(self, url, playlist_id, timestamp):
  745. programme_id, title, description, duration, formats, subtitles = \
  746. self._process_legacy_playlist_url(url, playlist_id)
  747. self._sort_formats(formats)
  748. return {
  749. 'id': programme_id,
  750. 'title': title,
  751. 'description': description,
  752. 'duration': duration,
  753. 'timestamp': timestamp,
  754. 'formats': formats,
  755. 'subtitles': subtitles,
  756. }
  757. def _real_extract(self, url):
  758. playlist_id = self._match_id(url)
  759. webpage = self._download_webpage(url, playlist_id)
  760. json_ld_info = self._search_json_ld(webpage, playlist_id, default={})
  761. timestamp = json_ld_info.get('timestamp')
  762. playlist_title = json_ld_info.get('title')
  763. if not playlist_title:
  764. playlist_title = self._og_search_title(
  765. webpage, default=None) or self._html_search_regex(
  766. r'<title>(.+?)</title>', webpage, 'playlist title', default=None)
  767. if playlist_title:
  768. playlist_title = re.sub(r'(.+)\s*-\s*BBC.*?$', r'\1', playlist_title).strip()
  769. playlist_description = json_ld_info.get(
  770. 'description') or self._og_search_description(webpage, default=None)
  771. if not timestamp:
  772. timestamp = parse_iso8601(self._search_regex(
  773. [r'<meta[^>]+property="article:published_time"[^>]+content="([^"]+)"',
  774. r'itemprop="datePublished"[^>]+datetime="([^"]+)"',
  775. r'"datePublished":\s*"([^"]+)'],
  776. webpage, 'date', default=None))
  777. entries = []
  778. # article with multiple videos embedded with playlist.sxml (e.g.
  779. # http://www.bbc.com/sport/0/football/34475836)
  780. playlists = re.findall(r'<param[^>]+name="playlist"[^>]+value="([^"]+)"', webpage)
  781. playlists.extend(re.findall(r'data-media-id="([^"]+/playlist\.sxml)"', webpage))
  782. if playlists:
  783. entries = [
  784. self._extract_from_playlist_sxml(playlist_url, playlist_id, timestamp)
  785. for playlist_url in playlists]
  786. # news article with multiple videos embedded with data-playable
  787. data_playables = re.findall(r'data-playable=(["\'])({.+?})\1', webpage)
  788. if data_playables:
  789. for _, data_playable_json in data_playables:
  790. data_playable = self._parse_json(
  791. unescapeHTML(data_playable_json), playlist_id, fatal=False)
  792. if not data_playable:
  793. continue
  794. settings = data_playable.get('settings', {})
  795. if settings:
  796. # data-playable with video vpid in settings.playlistObject.items (e.g.
  797. # http://www.bbc.com/news/world-us-canada-34473351)
  798. playlist_object = settings.get('playlistObject', {})
  799. if playlist_object:
  800. items = playlist_object.get('items')
  801. if items and isinstance(items, list):
  802. title = playlist_object['title']
  803. description = playlist_object.get('summary')
  804. duration = int_or_none(items[0].get('duration'))
  805. programme_id = items[0].get('vpid')
  806. formats, subtitles = self._download_media_selector(programme_id)
  807. self._sort_formats(formats)
  808. entries.append({
  809. 'id': programme_id,
  810. 'title': title,
  811. 'description': description,
  812. 'timestamp': timestamp,
  813. 'duration': duration,
  814. 'formats': formats,
  815. 'subtitles': subtitles,
  816. })
  817. else:
  818. # data-playable without vpid but with a playlist.sxml URLs
  819. # in otherSettings.playlist (e.g.
  820. # http://www.bbc.com/turkce/multimedya/2015/10/151010_vid_ankara_patlama_ani)
  821. playlist = data_playable.get('otherSettings', {}).get('playlist', {})
  822. if playlist:
  823. entry = None
  824. for key in ('streaming', 'progressiveDownload'):
  825. playlist_url = playlist.get('%sUrl' % key)
  826. if not playlist_url:
  827. continue
  828. try:
  829. info = self._extract_from_playlist_sxml(
  830. playlist_url, playlist_id, timestamp)
  831. if not entry:
  832. entry = info
  833. else:
  834. entry['title'] = info['title']
  835. entry['formats'].extend(info['formats'])
  836. except Exception as e:
  837. # Some playlist URL may fail with 500, at the same time
  838. # the other one may work fine (e.g.
  839. # http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu)
  840. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 500:
  841. continue
  842. raise
  843. if entry:
  844. self._sort_formats(entry['formats'])
  845. entries.append(entry)
  846. if entries:
  847. return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)
  848. # single video story (e.g. http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret)
  849. programme_id = self._search_regex(
  850. [r'data-(?:video-player|media)-vpid="(%s)"' % self._ID_REGEX,
  851. r'<param[^>]+name="externalIdentifier"[^>]+value="(%s)"' % self._ID_REGEX,
  852. r'videoId\s*:\s*["\'](%s)["\']' % self._ID_REGEX],
  853. webpage, 'vpid', default=None)
  854. if programme_id:
  855. formats, subtitles = self._download_media_selector(programme_id)
  856. self._sort_formats(formats)
  857. # digitalData may be missing (e.g. http://www.bbc.com/autos/story/20130513-hyundais-rock-star)
  858. digital_data = self._parse_json(
  859. self._search_regex(
  860. r'var\s+digitalData\s*=\s*({.+?});?\n', webpage, 'digital data', default='{}'),
  861. programme_id, fatal=False)
  862. page_info = digital_data.get('page', {}).get('pageInfo', {})
  863. title = page_info.get('pageName') or self._og_search_title(webpage)
  864. description = page_info.get('description') or self._og_search_description(webpage)
  865. timestamp = parse_iso8601(page_info.get('publicationDate')) or timestamp
  866. return {
  867. 'id': programme_id,
  868. 'title': title,
  869. 'description': description,
  870. 'timestamp': timestamp,
  871. 'formats': formats,
  872. 'subtitles': subtitles,
  873. }
  874. # Morph based embed (e.g. http://www.bbc.co.uk/sport/live/olympics/36895975)
  875. # There are several setPayload calls may be present but the video
  876. # seems to be always related to the first one
  877. morph_payload = self._parse_json(
  878. self._search_regex(
  879. r'Morph\.setPayload\([^,]+,\s*({.+?})\);',
  880. webpage, 'morph payload', default='{}'),
  881. playlist_id, fatal=False)
  882. if morph_payload:
  883. components = try_get(morph_payload, lambda x: x['body']['components'], list) or []
  884. for component in components:
  885. if not isinstance(component, dict):
  886. continue
  887. lead_media = try_get(component, lambda x: x['props']['leadMedia'], dict)
  888. if not lead_media:
  889. continue
  890. identifiers = lead_media.get('identifiers')
  891. if not identifiers or not isinstance(identifiers, dict):
  892. continue
  893. programme_id = identifiers.get('vpid') or identifiers.get('playablePid')
  894. if not programme_id:
  895. continue
  896. title = lead_media.get('title') or self._og_search_title(webpage)
  897. formats, subtitles = self._download_media_selector(programme_id)
  898. self._sort_formats(formats)
  899. description = lead_media.get('summary')
  900. uploader = lead_media.get('masterBrand')
  901. uploader_id = lead_media.get('mid')
  902. duration = None
  903. duration_d = lead_media.get('duration')
  904. if isinstance(duration_d, dict):
  905. duration = parse_duration(dict_get(
  906. duration_d, ('rawDuration', 'formattedDuration', 'spokenDuration')))
  907. return {
  908. 'id': programme_id,
  909. 'title': title,
  910. 'description': description,
  911. 'duration': duration,
  912. 'uploader': uploader,
  913. 'uploader_id': uploader_id,
  914. 'formats': formats,
  915. 'subtitles': subtitles,
  916. }
  917. def extract_all(pattern):
  918. return list(filter(None, map(
  919. lambda s: self._parse_json(s, playlist_id, fatal=False),
  920. re.findall(pattern, webpage))))
  921. # Multiple video article (e.g.
  922. # http://www.bbc.co.uk/blogs/adamcurtis/entries/3662a707-0af9-3149-963f-47bea720b460)
  923. EMBED_URL = r'https?://(?:www\.)?bbc\.co\.uk/(?:[^/]+/)+%s(?:\b[^"]+)?' % self._ID_REGEX
  924. entries = []
  925. for match in extract_all(r'new\s+SMP\(({.+?})\)'):
  926. embed_url = match.get('playerSettings', {}).get('externalEmbedUrl')
  927. if embed_url and re.match(EMBED_URL, embed_url):
  928. entries.append(embed_url)
  929. entries.extend(re.findall(
  930. r'setPlaylist\("(%s)"\)' % EMBED_URL, webpage))
  931. if entries:
  932. return self.playlist_result(
  933. [self.url_result(entry_, 'BBCCoUk') for entry_ in entries],
  934. playlist_id, playlist_title, playlist_description)
  935. # Multiple video article (e.g. http://www.bbc.com/news/world-europe-32668511)
  936. medias = extract_all(r"data-media-meta='({[^']+})'")
  937. if not medias:
  938. # Single video article (e.g. http://www.bbc.com/news/video_and_audio/international)
  939. media_asset = self._search_regex(
  940. r'mediaAssetPage\.init\(\s*({.+?}), "/',
  941. webpage, 'media asset', default=None)
  942. if media_asset:
  943. media_asset_page = self._parse_json(media_asset, playlist_id, fatal=False)
  944. medias = []
  945. for video in media_asset_page.get('videos', {}).values():
  946. medias.extend(video.values())
  947. if not medias:
  948. # Multiple video playlist with single `now playing` entry (e.g.
  949. # http://www.bbc.com/news/video_and_audio/must_see/33767813)
  950. vxp_playlist = self._parse_json(
  951. self._search_regex(
  952. r'<script[^>]+class="vxp-playlist-data"[^>]+type="application/json"[^>]*>([^<]+)</script>',
  953. webpage, 'playlist data'),
  954. playlist_id)
  955. playlist_medias = []
  956. for item in vxp_playlist:
  957. media = item.get('media')
  958. if not media:
  959. continue
  960. playlist_medias.append(media)
  961. # Download single video if found media with asset id matching the video id from URL
  962. if item.get('advert', {}).get('assetId') == playlist_id:
  963. medias = [media]
  964. break
  965. # Fallback to the whole playlist
  966. if not medias:
  967. medias = playlist_medias
  968. entries = []
  969. for num, media_meta in enumerate(medias, start=1):
  970. formats, subtitles = self._extract_from_media_meta(media_meta, playlist_id)
  971. if not formats:
  972. continue
  973. self._sort_formats(formats)
  974. video_id = media_meta.get('externalId')
  975. if not video_id:
  976. video_id = playlist_id if len(medias) == 1 else '%s-%s' % (playlist_id, num)
  977. title = media_meta.get('caption')
  978. if not title:
  979. title = playlist_title if len(medias) == 1 else '%s - Video %s' % (playlist_title, num)
  980. duration = int_or_none(media_meta.get('durationInSeconds')) or parse_duration(media_meta.get('duration'))
  981. images = []
  982. for image in media_meta.get('images', {}).values():
  983. images.extend(image.values())
  984. if 'image' in media_meta:
  985. images.append(media_meta['image'])
  986. thumbnails = [{
  987. 'url': image.get('href'),
  988. 'width': int_or_none(image.get('width')),
  989. 'height': int_or_none(image.get('height')),
  990. } for image in images]
  991. entries.append({
  992. 'id': video_id,
  993. 'title': title,
  994. 'thumbnails': thumbnails,
  995. 'duration': duration,
  996. 'timestamp': timestamp,
  997. 'formats': formats,
  998. 'subtitles': subtitles,
  999. })
  1000. return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)
  1001. class BBCCoUkArticleIE(InfoExtractor):
  1002. _VALID_URL = r'https?://(?:www\.)?bbc\.co\.uk/programmes/articles/(?P<id>[a-zA-Z0-9]+)'
  1003. IE_NAME = 'bbc.co.uk:article'
  1004. IE_DESC = 'BBC articles'
  1005. _TEST = {
  1006. 'url': 'http://www.bbc.co.uk/programmes/articles/3jNQLTMrPlYGTBn0WV6M2MS/not-your-typical-role-model-ada-lovelace-the-19th-century-programmer',
  1007. 'info_dict': {
  1008. 'id': '3jNQLTMrPlYGTBn0WV6M2MS',
  1009. 'title': 'Calculating Ada: The Countess of Computing - Not your typical role model: Ada Lovelace the 19th century programmer - BBC Four',
  1010. 'description': 'Hannah Fry reveals some of her surprising discoveries about Ada Lovelace during filming.',
  1011. },
  1012. 'playlist_count': 4,
  1013. 'add_ie': ['BBCCoUk'],
  1014. }
  1015. def _real_extract(self, url):
  1016. playlist_id = self._match_id(url)
  1017. webpage = self._download_webpage(url, playlist_id)
  1018. title = self._og_search_title(webpage)
  1019. description = self._og_search_description(webpage).strip()
  1020. entries = [self.url_result(programme_url) for programme_url in re.findall(
  1021. r'<div[^>]+typeof="Clip"[^>]+resource="([^"]+)"', webpage)]
  1022. return self.playlist_result(entries, playlist_id, title, description)
  1023. class BBCCoUkPlaylistBaseIE(InfoExtractor):
  1024. def _entries(self, webpage, url, playlist_id):
  1025. single_page = 'page' in compat_urlparse.parse_qs(
  1026. compat_urlparse.urlparse(url).query)
  1027. for page_num in itertools.count(2):
  1028. for video_id in re.findall(
  1029. self._VIDEO_ID_TEMPLATE % BBCCoUkIE._ID_REGEX, webpage):
  1030. yield self.url_result(
  1031. self._URL_TEMPLATE % video_id, BBCCoUkIE.ie_key())
  1032. if single_page:
  1033. return
  1034. next_page = self._search_regex(
  1035. r'<li[^>]+class=(["\'])pagination_+next\1[^>]*><a[^>]+href=(["\'])(?P<url>(?:(?!\2).)+)\2',
  1036. webpage, 'next page url', default=None, group='url')
  1037. if not next_page:
  1038. break
  1039. webpage = self._download_webpage(
  1040. compat_urlparse.urljoin(url, next_page), playlist_id,
  1041. 'Downloading page %d' % page_num, page_num)
  1042. def _real_extract(self, url):
  1043. playlist_id = self._match_id(url)
  1044. webpage = self._download_webpage(url, playlist_id)
  1045. title, description = self._extract_title_and_description(webpage)
  1046. return self.playlist_result(
  1047. self._entries(webpage, url, playlist_id),
  1048. playlist_id, title, description)
  1049. class BBCCoUkIPlayerPlaylistIE(BBCCoUkPlaylistBaseIE):
  1050. IE_NAME = 'bbc.co.uk:iplayer:playlist'
  1051. _VALID_URL = r'https?://(?:www\.)?bbc\.co\.uk/iplayer/(?:episodes|group)/(?P<id>%s)' % BBCCoUkIE._ID_REGEX
  1052. _URL_TEMPLATE = 'http://www.bbc.co.uk/iplayer/episode/%s'
  1053. _VIDEO_ID_TEMPLATE = r'data-ip-id=["\'](%s)'
  1054. _TESTS = [{
  1055. 'url': 'http://www.bbc.co.uk/iplayer/episodes/b05rcz9v',
  1056. 'info_dict': {
  1057. 'id': 'b05rcz9v',
  1058. 'title': 'The Disappearance',
  1059. 'description': 'French thriller serial about a missing teenager.',
  1060. },
  1061. 'playlist_mincount': 6,
  1062. 'skip': 'This programme is not currently available on BBC iPlayer',
  1063. }, {
  1064. # Available for over a year unlike 30 days for most other programmes
  1065. 'url': 'http://www.bbc.co.uk/iplayer/group/p02tcc32',
  1066. 'info_dict': {
  1067. 'id': 'p02tcc32',
  1068. 'title': 'Bohemian Icons',
  1069. 'description': 'md5:683e901041b2fe9ba596f2ab04c4dbe7',
  1070. },
  1071. 'playlist_mincount': 10,
  1072. }]
  1073. def _extract_title_and_description(self, webpage):
  1074. title = self._search_regex(r'<h1>([^<]+)</h1>', webpage, 'title', fatal=False)
  1075. description = self._search_regex(
  1076. r'<p[^>]+class=(["\'])subtitle\1[^>]*>(?P<value>[^<]+)</p>',
  1077. webpage, 'description', fatal=False, group='value')
  1078. return title, description
  1079. class BBCCoUkPlaylistIE(BBCCoUkPlaylistBaseIE):
  1080. IE_NAME = 'bbc.co.uk:playlist'
  1081. _VALID_URL = r'https?://(?:www\.)?bbc\.co\.uk/programmes/(?P<id>%s)/(?:episodes|broadcasts|clips)' % BBCCoUkIE._ID_REGEX
  1082. _URL_TEMPLATE = 'http://www.bbc.co.uk/programmes/%s'
  1083. _VIDEO_ID_TEMPLATE = r'data-pid=["\'](%s)'
  1084. _TESTS = [{
  1085. 'url': 'http://www.bbc.co.uk/programmes/b05rcz9v/clips',
  1086. 'info_dict': {
  1087. 'id': 'b05rcz9v',
  1088. 'title': 'The Disappearance - Clips - BBC Four',
  1089. 'description': 'French thriller serial about a missing teenager.',
  1090. },
  1091. 'playlist_mincount': 7,
  1092. }, {
  1093. # multipage playlist, explicit page
  1094. 'url': 'http://www.bbc.co.uk/programmes/b00mfl7n/clips?page=1',
  1095. 'info_dict': {
  1096. 'id': 'b00mfl7n',
  1097. 'title': 'Frozen Planet - Clips - BBC One',
  1098. 'description': 'md5:65dcbf591ae628dafe32aa6c4a4a0d8c',
  1099. },
  1100. 'playlist_mincount': 24,
  1101. }, {
  1102. # multipage playlist, all pages
  1103. 'url': 'http://www.bbc.co.uk/programmes/b00mfl7n/clips',
  1104. 'info_dict': {
  1105. 'id': 'b00mfl7n',
  1106. 'title': 'Frozen Planet - Clips - BBC One',
  1107. 'description': 'md5:65dcbf591ae628dafe32aa6c4a4a0d8c',
  1108. },
  1109. 'playlist_mincount': 142,
  1110. }, {
  1111. 'url': 'http://www.bbc.co.uk/programmes/b05rcz9v/broadcasts/2016/06',
  1112. 'only_matching': True,
  1113. }, {
  1114. 'url': 'http://www.bbc.co.uk/programmes/b05rcz9v/clips',
  1115. 'only_matching': True,
  1116. }, {
  1117. 'url': 'http://www.bbc.co.uk/programmes/b055jkys/episodes/player',
  1118. 'only_matching': True,
  1119. }]
  1120. def _extract_title_and_description(self, webpage):
  1121. title = self._og_search_title(webpage, fatal=False)
  1122. description = self._og_search_description(webpage)
  1123. return title, description