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.

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