bbc.py 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  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. 'tbr': bitrate,
  344. 'vcodec': encoding,
  345. })
  346. else:
  347. fmt.update({
  348. 'abr': bitrate,
  349. 'acodec': encoding,
  350. 'vcodec': 'none',
  351. })
  352. if protocol in ('http', 'https'):
  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. else:
  372. continue
  373. formats.append(fmt)
  374. elif kind == 'captions':
  375. subtitles = self.extract_subtitles(media, programme_id)
  376. return formats, subtitles
  377. def _download_playlist(self, playlist_id):
  378. try:
  379. playlist = self._download_json(
  380. 'http://www.bbc.co.uk/programmes/%s/playlist.json' % playlist_id,
  381. playlist_id, 'Downloading playlist JSON')
  382. version = playlist.get('defaultAvailableVersion')
  383. if version:
  384. smp_config = version['smpConfig']
  385. title = smp_config['title']
  386. description = smp_config['summary']
  387. for item in smp_config['items']:
  388. kind = item['kind']
  389. if kind not in ('programme', 'radioProgramme'):
  390. continue
  391. programme_id = item.get('vpid')
  392. duration = int_or_none(item.get('duration'))
  393. formats, subtitles = self._download_media_selector(programme_id)
  394. return programme_id, title, description, duration, formats, subtitles
  395. except ExtractorError as ee:
  396. if not (isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 404):
  397. raise
  398. # fallback to legacy playlist
  399. return self._process_legacy_playlist(playlist_id)
  400. def _process_legacy_playlist_url(self, url, display_id):
  401. playlist = self._download_legacy_playlist_url(url, display_id)
  402. return self._extract_from_legacy_playlist(playlist, display_id)
  403. def _process_legacy_playlist(self, playlist_id):
  404. return self._process_legacy_playlist_url(
  405. 'http://www.bbc.co.uk/iplayer/playlist/%s' % playlist_id, playlist_id)
  406. def _download_legacy_playlist_url(self, url, playlist_id=None):
  407. return self._download_xml(
  408. url, playlist_id, 'Downloading legacy playlist XML')
  409. def _extract_from_legacy_playlist(self, playlist, playlist_id):
  410. no_items = playlist.find('./{%s}noItems' % self._EMP_PLAYLIST_NS)
  411. if no_items is not None:
  412. reason = no_items.get('reason')
  413. if reason == 'preAvailability':
  414. msg = 'Episode %s is not yet available' % playlist_id
  415. elif reason == 'postAvailability':
  416. msg = 'Episode %s is no longer available' % playlist_id
  417. elif reason == 'noMedia':
  418. msg = 'Episode %s is not currently available' % playlist_id
  419. else:
  420. msg = 'Episode %s is not available: %s' % (playlist_id, reason)
  421. raise ExtractorError(msg, expected=True)
  422. for item in self._extract_items(playlist):
  423. kind = item.get('kind')
  424. if kind not in ('programme', 'radioProgramme'):
  425. continue
  426. title = playlist.find('./{%s}title' % self._EMP_PLAYLIST_NS).text
  427. description_el = playlist.find('./{%s}summary' % self._EMP_PLAYLIST_NS)
  428. description = description_el.text if description_el is not None else None
  429. def get_programme_id(item):
  430. def get_from_attributes(item):
  431. for p in('identifier', 'group'):
  432. value = item.get(p)
  433. if value and re.match(r'^[pb][\da-z]{7}$', value):
  434. return value
  435. get_from_attributes(item)
  436. mediator = item.find('./{%s}mediator' % self._EMP_PLAYLIST_NS)
  437. if mediator is not None:
  438. return get_from_attributes(mediator)
  439. programme_id = get_programme_id(item)
  440. duration = int_or_none(item.get('duration'))
  441. if programme_id:
  442. formats, subtitles = self._download_media_selector(programme_id)
  443. else:
  444. formats, subtitles = self._process_media_selector(item, playlist_id)
  445. programme_id = playlist_id
  446. return programme_id, title, description, duration, formats, subtitles
  447. def _real_extract(self, url):
  448. group_id = self._match_id(url)
  449. webpage = self._download_webpage(url, group_id, 'Downloading video page')
  450. programme_id = None
  451. duration = None
  452. tviplayer = self._search_regex(
  453. r'mediator\.bind\(({.+?})\s*,\s*document\.getElementById',
  454. webpage, 'player', default=None)
  455. if tviplayer:
  456. player = self._parse_json(tviplayer, group_id).get('player', {})
  457. duration = int_or_none(player.get('duration'))
  458. programme_id = player.get('vpid')
  459. if not programme_id:
  460. programme_id = self._search_regex(
  461. r'"vpid"\s*:\s*"(%s)"' % self._ID_REGEX, webpage, 'vpid', fatal=False, default=None)
  462. if programme_id:
  463. formats, subtitles = self._download_media_selector(programme_id)
  464. title = self._og_search_title(webpage, default=None) or self._html_search_regex(
  465. (r'<h2[^>]+id="parent-title"[^>]*>(.+?)</h2>',
  466. r'<div[^>]+class="info"[^>]*>\s*<h1>(.+?)</h1>'), webpage, 'title')
  467. description = self._search_regex(
  468. (r'<p class="[^"]*medium-description[^"]*">([^<]+)</p>',
  469. r'<div[^>]+class="info_+synopsis"[^>]*>([^<]+)</div>'),
  470. webpage, 'description', default=None)
  471. if not description:
  472. description = self._html_search_meta('description', webpage)
  473. else:
  474. programme_id, title, description, duration, formats, subtitles = self._download_playlist(group_id)
  475. self._sort_formats(formats)
  476. return {
  477. 'id': programme_id,
  478. 'title': title,
  479. 'description': description,
  480. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  481. 'duration': duration,
  482. 'formats': formats,
  483. 'subtitles': subtitles,
  484. }
  485. class BBCIE(BBCCoUkIE):
  486. IE_NAME = 'bbc'
  487. IE_DESC = 'BBC'
  488. _VALID_URL = r'https?://(?:www\.)?bbc\.(?:com|co\.uk)/(?:[^/]+/)+(?P<id>[^/#?]+)'
  489. _MEDIASELECTOR_URLS = [
  490. # Provides HQ HLS streams but fails with geolocation in some cases when it's
  491. # even not geo restricted at all
  492. 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/iptv-all/vpid/%s',
  493. # Provides more formats, namely direct mp4 links, but fails on some videos with
  494. # notukerror for non UK (?) users (e.g.
  495. # http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret)
  496. 'http://open.live.bbc.co.uk/mediaselector/4/mtis/stream/%s',
  497. # Provides fewer formats, but works everywhere for everybody (hopefully)
  498. 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/journalism-pc/vpid/%s',
  499. ]
  500. _TESTS = [{
  501. # article with multiple videos embedded with data-playable containing vpids
  502. 'url': 'http://www.bbc.com/news/world-europe-32668511',
  503. 'info_dict': {
  504. 'id': 'world-europe-32668511',
  505. 'title': 'Russia stages massive WW2 parade despite Western boycott',
  506. 'description': 'md5:00ff61976f6081841f759a08bf78cc9c',
  507. },
  508. 'playlist_count': 2,
  509. }, {
  510. # article with multiple videos embedded with data-playable (more videos)
  511. 'url': 'http://www.bbc.com/news/business-28299555',
  512. 'info_dict': {
  513. 'id': 'business-28299555',
  514. 'title': 'Farnborough Airshow: Video highlights',
  515. 'description': 'BBC reports and video highlights at the Farnborough Airshow.',
  516. },
  517. 'playlist_count': 9,
  518. 'skip': 'Save time',
  519. }, {
  520. # article with multiple videos embedded with `new SMP()`
  521. # broken
  522. 'url': 'http://www.bbc.co.uk/blogs/adamcurtis/entries/3662a707-0af9-3149-963f-47bea720b460',
  523. 'info_dict': {
  524. 'id': '3662a707-0af9-3149-963f-47bea720b460',
  525. 'title': 'BUGGER',
  526. },
  527. 'playlist_count': 18,
  528. }, {
  529. # single video embedded with data-playable containing vpid
  530. 'url': 'http://www.bbc.com/news/world-europe-32041533',
  531. 'info_dict': {
  532. 'id': 'p02mprgb',
  533. 'ext': 'mp4',
  534. 'title': 'Aerial footage showed the site of the crash in the Alps - courtesy BFM TV',
  535. 'description': 'md5:2868290467291b37feda7863f7a83f54',
  536. 'duration': 47,
  537. 'timestamp': 1427219242,
  538. 'upload_date': '20150324',
  539. },
  540. 'params': {
  541. # rtmp download
  542. 'skip_download': True,
  543. }
  544. }, {
  545. # article with single video embedded with data-playable containing XML playlist
  546. # with direct video links as progressiveDownloadUrl (for now these are extracted)
  547. # and playlist with f4m and m3u8 as streamingUrl
  548. 'url': 'http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu',
  549. 'info_dict': {
  550. 'id': '150615_telabyad_kentin_cogu',
  551. 'ext': 'mp4',
  552. 'title': "YPG: Tel Abyad'ın tamamı kontrolümüzde",
  553. 'description': 'md5:33a4805a855c9baf7115fcbde57e7025',
  554. 'timestamp': 1434397334,
  555. 'upload_date': '20150615',
  556. },
  557. 'params': {
  558. 'skip_download': True,
  559. }
  560. }, {
  561. # single video embedded with data-playable containing XML playlists (regional section)
  562. 'url': 'http://www.bbc.com/mundo/video_fotos/2015/06/150619_video_honduras_militares_hospitales_corrupcion_aw',
  563. 'info_dict': {
  564. 'id': '150619_video_honduras_militares_hospitales_corrupcion_aw',
  565. 'ext': 'mp4',
  566. 'title': 'Honduras militariza sus hospitales por nuevo escándalo de corrupción',
  567. 'description': 'md5:1525f17448c4ee262b64b8f0c9ce66c8',
  568. 'timestamp': 1434713142,
  569. 'upload_date': '20150619',
  570. },
  571. 'params': {
  572. 'skip_download': True,
  573. }
  574. }, {
  575. # single video from video playlist embedded with vxp-playlist-data JSON
  576. 'url': 'http://www.bbc.com/news/video_and_audio/must_see/33376376',
  577. 'info_dict': {
  578. 'id': 'p02w6qjc',
  579. 'ext': 'mp4',
  580. 'title': '''Judge Mindy Glazer: "I'm sorry to see you here... I always wondered what happened to you"''',
  581. 'duration': 56,
  582. 'description': '''Judge Mindy Glazer: "I'm sorry to see you here... I always wondered what happened to you"''',
  583. },
  584. 'params': {
  585. 'skip_download': True,
  586. }
  587. }, {
  588. # single video story with digitalData
  589. 'url': 'http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret',
  590. 'info_dict': {
  591. 'id': 'p02q6gc4',
  592. 'ext': 'flv',
  593. 'title': 'Sri Lanka’s spicy secret',
  594. 'description': 'As a new train line to Jaffna opens up the country’s north, travellers can experience a truly distinct slice of Tamil culture.',
  595. 'timestamp': 1437674293,
  596. 'upload_date': '20150723',
  597. },
  598. 'params': {
  599. # rtmp download
  600. 'skip_download': True,
  601. }
  602. }, {
  603. # single video story without digitalData
  604. 'url': 'http://www.bbc.com/autos/story/20130513-hyundais-rock-star',
  605. 'info_dict': {
  606. 'id': 'p018zqqg',
  607. 'ext': 'mp4',
  608. 'title': 'Hyundai Santa Fe Sport: Rock star',
  609. 'description': 'md5:b042a26142c4154a6e472933cf20793d',
  610. 'timestamp': 1415867444,
  611. 'upload_date': '20141113',
  612. },
  613. 'params': {
  614. # rtmp download
  615. 'skip_download': True,
  616. }
  617. }, {
  618. # single video embedded with Morph
  619. 'url': 'http://www.bbc.co.uk/sport/live/olympics/36895975',
  620. 'info_dict': {
  621. 'id': 'p041vhd0',
  622. 'ext': 'mp4',
  623. 'title': "Nigeria v Japan - Men's First Round",
  624. 'description': 'Live coverage of the first round from Group B at the Amazonia Arena.',
  625. 'duration': 7980,
  626. 'uploader': 'BBC Sport',
  627. 'uploader_id': 'bbc_sport',
  628. },
  629. 'params': {
  630. # m3u8 download
  631. 'skip_download': True,
  632. },
  633. 'skip': 'Georestricted to UK',
  634. }, {
  635. # single video with playlist.sxml URL in playlist param
  636. 'url': 'http://www.bbc.com/sport/0/football/33653409',
  637. 'info_dict': {
  638. 'id': 'p02xycnp',
  639. 'ext': 'mp4',
  640. 'title': 'Transfers: Cristiano Ronaldo to Man Utd, Arsenal to spend?',
  641. 'description': 'BBC Sport\'s David Ornstein has the latest transfer gossip, including rumours of a Manchester United return for Cristiano Ronaldo.',
  642. 'duration': 140,
  643. },
  644. 'params': {
  645. # rtmp download
  646. 'skip_download': True,
  647. }
  648. }, {
  649. # article with multiple videos embedded with playlist.sxml in playlist param
  650. 'url': 'http://www.bbc.com/sport/0/football/34475836',
  651. 'info_dict': {
  652. 'id': '34475836',
  653. 'title': 'Jurgen Klopp: Furious football from a witty and winning coach',
  654. 'description': 'Fast-paced football, wit, wisdom and a ready smile - why Liverpool fans should come to love new boss Jurgen Klopp.',
  655. },
  656. 'playlist_count': 3,
  657. }, {
  658. # school report article with single video
  659. 'url': 'http://www.bbc.co.uk/schoolreport/35744779',
  660. 'info_dict': {
  661. 'id': '35744779',
  662. 'title': 'School which breaks down barriers in Jerusalem',
  663. },
  664. 'playlist_count': 1,
  665. }, {
  666. # single video with playlist URL from weather section
  667. 'url': 'http://www.bbc.com/weather/features/33601775',
  668. 'only_matching': True,
  669. }, {
  670. # custom redirection to www.bbc.com
  671. 'url': 'http://www.bbc.co.uk/news/science-environment-33661876',
  672. 'only_matching': True,
  673. }, {
  674. # single video article embedded with data-media-vpid
  675. 'url': 'http://www.bbc.co.uk/sport/rowing/35908187',
  676. 'only_matching': True,
  677. }]
  678. @classmethod
  679. def suitable(cls, url):
  680. EXCLUDE_IE = (BBCCoUkIE, BBCCoUkArticleIE, BBCCoUkIPlayerPlaylistIE, BBCCoUkPlaylistIE)
  681. return (False if any(ie.suitable(url) for ie in EXCLUDE_IE)
  682. else super(BBCIE, cls).suitable(url))
  683. def _extract_from_media_meta(self, media_meta, video_id):
  684. # Direct links to media in media metadata (e.g.
  685. # http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu)
  686. # TODO: there are also f4m and m3u8 streams incorporated in playlist.sxml
  687. source_files = media_meta.get('sourceFiles')
  688. if source_files:
  689. return [{
  690. 'url': f['url'],
  691. 'format_id': format_id,
  692. 'ext': f.get('encoding'),
  693. 'tbr': float_or_none(f.get('bitrate'), 1000),
  694. 'filesize': int_or_none(f.get('filesize')),
  695. } for format_id, f in source_files.items() if f.get('url')], []
  696. programme_id = media_meta.get('externalId')
  697. if programme_id:
  698. return self._download_media_selector(programme_id)
  699. # Process playlist.sxml as legacy playlist
  700. href = media_meta.get('href')
  701. if href:
  702. playlist = self._download_legacy_playlist_url(href)
  703. _, _, _, _, formats, subtitles = self._extract_from_legacy_playlist(playlist, video_id)
  704. return formats, subtitles
  705. return [], []
  706. def _extract_from_playlist_sxml(self, url, playlist_id, timestamp):
  707. programme_id, title, description, duration, formats, subtitles = \
  708. self._process_legacy_playlist_url(url, playlist_id)
  709. self._sort_formats(formats)
  710. return {
  711. 'id': programme_id,
  712. 'title': title,
  713. 'description': description,
  714. 'duration': duration,
  715. 'timestamp': timestamp,
  716. 'formats': formats,
  717. 'subtitles': subtitles,
  718. }
  719. def _real_extract(self, url):
  720. playlist_id = self._match_id(url)
  721. webpage = self._download_webpage(url, playlist_id)
  722. json_ld_info = self._search_json_ld(webpage, playlist_id, default={})
  723. timestamp = json_ld_info.get('timestamp')
  724. playlist_title = json_ld_info.get('title')
  725. if not playlist_title:
  726. playlist_title = self._og_search_title(
  727. webpage, default=None) or self._html_search_regex(
  728. r'<title>(.+?)</title>', webpage, 'playlist title', default=None)
  729. if playlist_title:
  730. playlist_title = re.sub(r'(.+)\s*-\s*BBC.*?$', r'\1', playlist_title).strip()
  731. playlist_description = json_ld_info.get(
  732. 'description') or self._og_search_description(webpage, default=None)
  733. if not timestamp:
  734. timestamp = parse_iso8601(self._search_regex(
  735. [r'<meta[^>]+property="article:published_time"[^>]+content="([^"]+)"',
  736. r'itemprop="datePublished"[^>]+datetime="([^"]+)"',
  737. r'"datePublished":\s*"([^"]+)'],
  738. webpage, 'date', default=None))
  739. entries = []
  740. # article with multiple videos embedded with playlist.sxml (e.g.
  741. # http://www.bbc.com/sport/0/football/34475836)
  742. playlists = re.findall(r'<param[^>]+name="playlist"[^>]+value="([^"]+)"', webpage)
  743. playlists.extend(re.findall(r'data-media-id="([^"]+/playlist\.sxml)"', webpage))
  744. if playlists:
  745. entries = [
  746. self._extract_from_playlist_sxml(playlist_url, playlist_id, timestamp)
  747. for playlist_url in playlists]
  748. # news article with multiple videos embedded with data-playable
  749. data_playables = re.findall(r'data-playable=(["\'])({.+?})\1', webpage)
  750. if data_playables:
  751. for _, data_playable_json in data_playables:
  752. data_playable = self._parse_json(
  753. unescapeHTML(data_playable_json), playlist_id, fatal=False)
  754. if not data_playable:
  755. continue
  756. settings = data_playable.get('settings', {})
  757. if settings:
  758. # data-playable with video vpid in settings.playlistObject.items (e.g.
  759. # http://www.bbc.com/news/world-us-canada-34473351)
  760. playlist_object = settings.get('playlistObject', {})
  761. if playlist_object:
  762. items = playlist_object.get('items')
  763. if items and isinstance(items, list):
  764. title = playlist_object['title']
  765. description = playlist_object.get('summary')
  766. duration = int_or_none(items[0].get('duration'))
  767. programme_id = items[0].get('vpid')
  768. formats, subtitles = self._download_media_selector(programme_id)
  769. self._sort_formats(formats)
  770. entries.append({
  771. 'id': programme_id,
  772. 'title': title,
  773. 'description': description,
  774. 'timestamp': timestamp,
  775. 'duration': duration,
  776. 'formats': formats,
  777. 'subtitles': subtitles,
  778. })
  779. else:
  780. # data-playable without vpid but with a playlist.sxml URLs
  781. # in otherSettings.playlist (e.g.
  782. # http://www.bbc.com/turkce/multimedya/2015/10/151010_vid_ankara_patlama_ani)
  783. playlist = data_playable.get('otherSettings', {}).get('playlist', {})
  784. if playlist:
  785. entry = None
  786. for key in ('streaming', 'progressiveDownload'):
  787. playlist_url = playlist.get('%sUrl' % key)
  788. if not playlist_url:
  789. continue
  790. try:
  791. info = self._extract_from_playlist_sxml(
  792. playlist_url, playlist_id, timestamp)
  793. if not entry:
  794. entry = info
  795. else:
  796. entry['title'] = info['title']
  797. entry['formats'].extend(info['formats'])
  798. except Exception as e:
  799. # Some playlist URL may fail with 500, at the same time
  800. # the other one may work fine (e.g.
  801. # http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu)
  802. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 500:
  803. continue
  804. raise
  805. if entry:
  806. self._sort_formats(entry['formats'])
  807. entries.append(entry)
  808. if entries:
  809. return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)
  810. # single video story (e.g. http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret)
  811. programme_id = self._search_regex(
  812. [r'data-(?:video-player|media)-vpid="(%s)"' % self._ID_REGEX,
  813. r'<param[^>]+name="externalIdentifier"[^>]+value="(%s)"' % self._ID_REGEX,
  814. r'videoId\s*:\s*["\'](%s)["\']' % self._ID_REGEX],
  815. webpage, 'vpid', default=None)
  816. if programme_id:
  817. formats, subtitles = self._download_media_selector(programme_id)
  818. self._sort_formats(formats)
  819. # digitalData may be missing (e.g. http://www.bbc.com/autos/story/20130513-hyundais-rock-star)
  820. digital_data = self._parse_json(
  821. self._search_regex(
  822. r'var\s+digitalData\s*=\s*({.+?});?\n', webpage, 'digital data', default='{}'),
  823. programme_id, fatal=False)
  824. page_info = digital_data.get('page', {}).get('pageInfo', {})
  825. title = page_info.get('pageName') or self._og_search_title(webpage)
  826. description = page_info.get('description') or self._og_search_description(webpage)
  827. timestamp = parse_iso8601(page_info.get('publicationDate')) or timestamp
  828. return {
  829. 'id': programme_id,
  830. 'title': title,
  831. 'description': description,
  832. 'timestamp': timestamp,
  833. 'formats': formats,
  834. 'subtitles': subtitles,
  835. }
  836. # Morph based embed (e.g. http://www.bbc.co.uk/sport/live/olympics/36895975)
  837. # There are several setPayload calls may be present but the video
  838. # seems to be always related to the first one
  839. morph_payload = self._parse_json(
  840. self._search_regex(
  841. r'Morph\.setPayload\([^,]+,\s*({.+?})\);',
  842. webpage, 'morph payload', default='{}'),
  843. playlist_id, fatal=False)
  844. if morph_payload:
  845. components = try_get(morph_payload, lambda x: x['body']['components'], list) or []
  846. for component in components:
  847. if not isinstance(component, dict):
  848. continue
  849. lead_media = try_get(component, lambda x: x['props']['leadMedia'], dict)
  850. if not lead_media:
  851. continue
  852. identifiers = lead_media.get('identifiers')
  853. if not identifiers or not isinstance(identifiers, dict):
  854. continue
  855. programme_id = identifiers.get('vpid') or identifiers.get('playablePid')
  856. if not programme_id:
  857. continue
  858. title = lead_media.get('title') or self._og_search_title(webpage)
  859. formats, subtitles = self._download_media_selector(programme_id)
  860. self._sort_formats(formats)
  861. description = lead_media.get('summary')
  862. uploader = lead_media.get('masterBrand')
  863. uploader_id = lead_media.get('mid')
  864. duration = None
  865. duration_d = lead_media.get('duration')
  866. if isinstance(duration_d, dict):
  867. duration = parse_duration(dict_get(
  868. duration_d, ('rawDuration', 'formattedDuration', 'spokenDuration')))
  869. return {
  870. 'id': programme_id,
  871. 'title': title,
  872. 'description': description,
  873. 'duration': duration,
  874. 'uploader': uploader,
  875. 'uploader_id': uploader_id,
  876. 'formats': formats,
  877. 'subtitles': subtitles,
  878. }
  879. def extract_all(pattern):
  880. return list(filter(None, map(
  881. lambda s: self._parse_json(s, playlist_id, fatal=False),
  882. re.findall(pattern, webpage))))
  883. # Multiple video article (e.g.
  884. # http://www.bbc.co.uk/blogs/adamcurtis/entries/3662a707-0af9-3149-963f-47bea720b460)
  885. EMBED_URL = r'https?://(?:www\.)?bbc\.co\.uk/(?:[^/]+/)+%s(?:\b[^"]+)?' % self._ID_REGEX
  886. entries = []
  887. for match in extract_all(r'new\s+SMP\(({.+?})\)'):
  888. embed_url = match.get('playerSettings', {}).get('externalEmbedUrl')
  889. if embed_url and re.match(EMBED_URL, embed_url):
  890. entries.append(embed_url)
  891. entries.extend(re.findall(
  892. r'setPlaylist\("(%s)"\)' % EMBED_URL, webpage))
  893. if entries:
  894. return self.playlist_result(
  895. [self.url_result(entry_, 'BBCCoUk') for entry_ in entries],
  896. playlist_id, playlist_title, playlist_description)
  897. # Multiple video article (e.g. http://www.bbc.com/news/world-europe-32668511)
  898. medias = extract_all(r"data-media-meta='({[^']+})'")
  899. if not medias:
  900. # Single video article (e.g. http://www.bbc.com/news/video_and_audio/international)
  901. media_asset = self._search_regex(
  902. r'mediaAssetPage\.init\(\s*({.+?}), "/',
  903. webpage, 'media asset', default=None)
  904. if media_asset:
  905. media_asset_page = self._parse_json(media_asset, playlist_id, fatal=False)
  906. medias = []
  907. for video in media_asset_page.get('videos', {}).values():
  908. medias.extend(video.values())
  909. if not medias:
  910. # Multiple video playlist with single `now playing` entry (e.g.
  911. # http://www.bbc.com/news/video_and_audio/must_see/33767813)
  912. vxp_playlist = self._parse_json(
  913. self._search_regex(
  914. r'<script[^>]+class="vxp-playlist-data"[^>]+type="application/json"[^>]*>([^<]+)</script>',
  915. webpage, 'playlist data'),
  916. playlist_id)
  917. playlist_medias = []
  918. for item in vxp_playlist:
  919. media = item.get('media')
  920. if not media:
  921. continue
  922. playlist_medias.append(media)
  923. # Download single video if found media with asset id matching the video id from URL
  924. if item.get('advert', {}).get('assetId') == playlist_id:
  925. medias = [media]
  926. break
  927. # Fallback to the whole playlist
  928. if not medias:
  929. medias = playlist_medias
  930. entries = []
  931. for num, media_meta in enumerate(medias, start=1):
  932. formats, subtitles = self._extract_from_media_meta(media_meta, playlist_id)
  933. if not formats:
  934. continue
  935. self._sort_formats(formats)
  936. video_id = media_meta.get('externalId')
  937. if not video_id:
  938. video_id = playlist_id if len(medias) == 1 else '%s-%s' % (playlist_id, num)
  939. title = media_meta.get('caption')
  940. if not title:
  941. title = playlist_title if len(medias) == 1 else '%s - Video %s' % (playlist_title, num)
  942. duration = int_or_none(media_meta.get('durationInSeconds')) or parse_duration(media_meta.get('duration'))
  943. images = []
  944. for image in media_meta.get('images', {}).values():
  945. images.extend(image.values())
  946. if 'image' in media_meta:
  947. images.append(media_meta['image'])
  948. thumbnails = [{
  949. 'url': image.get('href'),
  950. 'width': int_or_none(image.get('width')),
  951. 'height': int_or_none(image.get('height')),
  952. } for image in images]
  953. entries.append({
  954. 'id': video_id,
  955. 'title': title,
  956. 'thumbnails': thumbnails,
  957. 'duration': duration,
  958. 'timestamp': timestamp,
  959. 'formats': formats,
  960. 'subtitles': subtitles,
  961. })
  962. return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)
  963. class BBCCoUkArticleIE(InfoExtractor):
  964. _VALID_URL = r'https?://(?:www\.)?bbc\.co\.uk/programmes/articles/(?P<id>[a-zA-Z0-9]+)'
  965. IE_NAME = 'bbc.co.uk:article'
  966. IE_DESC = 'BBC articles'
  967. _TEST = {
  968. 'url': 'http://www.bbc.co.uk/programmes/articles/3jNQLTMrPlYGTBn0WV6M2MS/not-your-typical-role-model-ada-lovelace-the-19th-century-programmer',
  969. 'info_dict': {
  970. 'id': '3jNQLTMrPlYGTBn0WV6M2MS',
  971. 'title': 'Calculating Ada: The Countess of Computing - Not your typical role model: Ada Lovelace the 19th century programmer - BBC Four',
  972. 'description': 'Hannah Fry reveals some of her surprising discoveries about Ada Lovelace during filming.',
  973. },
  974. 'playlist_count': 4,
  975. 'add_ie': ['BBCCoUk'],
  976. }
  977. def _real_extract(self, url):
  978. playlist_id = self._match_id(url)
  979. webpage = self._download_webpage(url, playlist_id)
  980. title = self._og_search_title(webpage)
  981. description = self._og_search_description(webpage).strip()
  982. entries = [self.url_result(programme_url) for programme_url in re.findall(
  983. r'<div[^>]+typeof="Clip"[^>]+resource="([^"]+)"', webpage)]
  984. return self.playlist_result(entries, playlist_id, title, description)
  985. class BBCCoUkPlaylistBaseIE(InfoExtractor):
  986. def _entries(self, webpage, url, playlist_id):
  987. single_page = 'page' in compat_urlparse.parse_qs(
  988. compat_urlparse.urlparse(url).query)
  989. for page_num in itertools.count(2):
  990. for video_id in re.findall(
  991. self._VIDEO_ID_TEMPLATE % BBCCoUkIE._ID_REGEX, webpage):
  992. yield self.url_result(
  993. self._URL_TEMPLATE % video_id, BBCCoUkIE.ie_key())
  994. if single_page:
  995. return
  996. next_page = self._search_regex(
  997. r'<li[^>]+class=(["\'])pagination_+next\1[^>]*><a[^>]+href=(["\'])(?P<url>(?:(?!\2).)+)\2',
  998. webpage, 'next page url', default=None, group='url')
  999. if not next_page:
  1000. break
  1001. webpage = self._download_webpage(
  1002. compat_urlparse.urljoin(url, next_page), playlist_id,
  1003. 'Downloading page %d' % page_num, page_num)
  1004. def _real_extract(self, url):
  1005. playlist_id = self._match_id(url)
  1006. webpage = self._download_webpage(url, playlist_id)
  1007. title, description = self._extract_title_and_description(webpage)
  1008. return self.playlist_result(
  1009. self._entries(webpage, url, playlist_id),
  1010. playlist_id, title, description)
  1011. class BBCCoUkIPlayerPlaylistIE(BBCCoUkPlaylistBaseIE):
  1012. IE_NAME = 'bbc.co.uk:iplayer:playlist'
  1013. _VALID_URL = r'https?://(?:www\.)?bbc\.co\.uk/iplayer/(?:episodes|group)/(?P<id>%s)' % BBCCoUkIE._ID_REGEX
  1014. _URL_TEMPLATE = 'http://www.bbc.co.uk/iplayer/episode/%s'
  1015. _VIDEO_ID_TEMPLATE = r'data-ip-id=["\'](%s)'
  1016. _TESTS = [{
  1017. 'url': 'http://www.bbc.co.uk/iplayer/episodes/b05rcz9v',
  1018. 'info_dict': {
  1019. 'id': 'b05rcz9v',
  1020. 'title': 'The Disappearance',
  1021. 'description': 'French thriller serial about a missing teenager.',
  1022. },
  1023. 'playlist_mincount': 6,
  1024. 'skip': 'This programme is not currently available on BBC iPlayer',
  1025. }, {
  1026. # Available for over a year unlike 30 days for most other programmes
  1027. 'url': 'http://www.bbc.co.uk/iplayer/group/p02tcc32',
  1028. 'info_dict': {
  1029. 'id': 'p02tcc32',
  1030. 'title': 'Bohemian Icons',
  1031. 'description': 'md5:683e901041b2fe9ba596f2ab04c4dbe7',
  1032. },
  1033. 'playlist_mincount': 10,
  1034. }]
  1035. def _extract_title_and_description(self, webpage):
  1036. title = self._search_regex(r'<h1>([^<]+)</h1>', webpage, 'title', fatal=False)
  1037. description = self._search_regex(
  1038. r'<p[^>]+class=(["\'])subtitle\1[^>]*>(?P<value>[^<]+)</p>',
  1039. webpage, 'description', fatal=False, group='value')
  1040. return title, description
  1041. class BBCCoUkPlaylistIE(BBCCoUkPlaylistBaseIE):
  1042. IE_NAME = 'bbc.co.uk:playlist'
  1043. _VALID_URL = r'https?://(?:www\.)?bbc\.co\.uk/programmes/(?P<id>%s)/(?:episodes|broadcasts|clips)' % BBCCoUkIE._ID_REGEX
  1044. _URL_TEMPLATE = 'http://www.bbc.co.uk/programmes/%s'
  1045. _VIDEO_ID_TEMPLATE = r'data-pid=["\'](%s)'
  1046. _TESTS = [{
  1047. 'url': 'http://www.bbc.co.uk/programmes/b05rcz9v/clips',
  1048. 'info_dict': {
  1049. 'id': 'b05rcz9v',
  1050. 'title': 'The Disappearance - Clips - BBC Four',
  1051. 'description': 'French thriller serial about a missing teenager.',
  1052. },
  1053. 'playlist_mincount': 7,
  1054. }, {
  1055. # multipage playlist, explicit page
  1056. 'url': 'http://www.bbc.co.uk/programmes/b00mfl7n/clips?page=1',
  1057. 'info_dict': {
  1058. 'id': 'b00mfl7n',
  1059. 'title': 'Frozen Planet - Clips - BBC One',
  1060. 'description': 'md5:65dcbf591ae628dafe32aa6c4a4a0d8c',
  1061. },
  1062. 'playlist_mincount': 24,
  1063. }, {
  1064. # multipage playlist, all pages
  1065. 'url': 'http://www.bbc.co.uk/programmes/b00mfl7n/clips',
  1066. 'info_dict': {
  1067. 'id': 'b00mfl7n',
  1068. 'title': 'Frozen Planet - Clips - BBC One',
  1069. 'description': 'md5:65dcbf591ae628dafe32aa6c4a4a0d8c',
  1070. },
  1071. 'playlist_mincount': 142,
  1072. }, {
  1073. 'url': 'http://www.bbc.co.uk/programmes/b05rcz9v/broadcasts/2016/06',
  1074. 'only_matching': True,
  1075. }, {
  1076. 'url': 'http://www.bbc.co.uk/programmes/b05rcz9v/clips',
  1077. 'only_matching': True,
  1078. }, {
  1079. 'url': 'http://www.bbc.co.uk/programmes/b055jkys/episodes/player',
  1080. 'only_matching': True,
  1081. }]
  1082. def _extract_title_and_description(self, webpage):
  1083. title = self._og_search_title(webpage, fatal=False)
  1084. description = self._og_search_description(webpage)
  1085. return title, description