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.

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