npo.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_HTTPError,
  6. compat_str,
  7. )
  8. from ..utils import (
  9. determine_ext,
  10. ExtractorError,
  11. fix_xml_ampersands,
  12. int_or_none,
  13. merge_dicts,
  14. orderedSet,
  15. parse_duration,
  16. qualities,
  17. str_or_none,
  18. strip_jsonp,
  19. unified_strdate,
  20. unified_timestamp,
  21. url_or_none,
  22. urlencode_postdata,
  23. )
  24. class NPOBaseIE(InfoExtractor):
  25. def _get_token(self, video_id):
  26. return self._download_json(
  27. 'http://ida.omroep.nl/app.php/auth', video_id,
  28. note='Downloading token')['token']
  29. class NPOIE(NPOBaseIE):
  30. IE_NAME = 'npo'
  31. IE_DESC = 'npo.nl, ntr.nl, omroepwnl.nl, zapp.nl and npo3.nl'
  32. _VALID_URL = r'''(?x)
  33. (?:
  34. npo:|
  35. https?://
  36. (?:www\.)?
  37. (?:
  38. npo\.nl/(?:[^/]+/)*|
  39. (?:ntr|npostart)\.nl/(?:[^/]+/){2,}|
  40. omroepwnl\.nl/video/fragment/[^/]+__|
  41. (?:zapp|npo3)\.nl/(?:[^/]+/){2,}
  42. )
  43. )
  44. (?P<id>[^/?#]+)
  45. '''
  46. _TESTS = [{
  47. 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
  48. 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
  49. 'info_dict': {
  50. 'id': 'VPWON_1220719',
  51. 'ext': 'm4v',
  52. 'title': 'Nieuwsuur',
  53. 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
  54. 'upload_date': '20140622',
  55. },
  56. }, {
  57. 'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800',
  58. 'md5': 'da50a5787dbfc1603c4ad80f31c5120b',
  59. 'info_dict': {
  60. 'id': 'VARA_101191800',
  61. 'ext': 'm4v',
  62. 'title': 'De Mega Mike & Mega Thomas show: The best of.',
  63. 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4',
  64. 'upload_date': '20090227',
  65. 'duration': 2400,
  66. },
  67. }, {
  68. 'url': 'http://www.npo.nl/tegenlicht/25-02-2013/VPWON_1169289',
  69. 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
  70. 'info_dict': {
  71. 'id': 'VPWON_1169289',
  72. 'ext': 'm4v',
  73. 'title': 'Tegenlicht: Zwart geld. De toekomst komt uit Afrika',
  74. 'description': 'md5:52cf4eefbc96fffcbdc06d024147abea',
  75. 'upload_date': '20130225',
  76. 'duration': 3000,
  77. },
  78. }, {
  79. 'url': 'http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706',
  80. 'info_dict': {
  81. 'id': 'WO_VPRO_043706',
  82. 'ext': 'm4v',
  83. 'title': 'De nieuwe mens - Deel 1',
  84. 'description': 'md5:518ae51ba1293ffb80d8d8ce90b74e4b',
  85. 'duration': 4680,
  86. },
  87. 'params': {
  88. 'skip_download': True,
  89. }
  90. }, {
  91. # non asf in streams
  92. 'url': 'http://www.npo.nl/hoe-gaat-europa-verder-na-parijs/10-01-2015/WO_NOS_762771',
  93. 'info_dict': {
  94. 'id': 'WO_NOS_762771',
  95. 'ext': 'mp4',
  96. 'title': 'Hoe gaat Europa verder na Parijs?',
  97. },
  98. 'params': {
  99. 'skip_download': True,
  100. }
  101. }, {
  102. 'url': 'http://www.ntr.nl/Aap-Poot-Pies/27/detail/Aap-poot-pies/VPWON_1233944#content',
  103. 'info_dict': {
  104. 'id': 'VPWON_1233944',
  105. 'ext': 'm4v',
  106. 'title': 'Aap, poot, pies',
  107. 'description': 'md5:c9c8005d1869ae65b858e82c01a91fde',
  108. 'upload_date': '20150508',
  109. 'duration': 599,
  110. },
  111. 'params': {
  112. 'skip_download': True,
  113. }
  114. }, {
  115. 'url': 'http://www.omroepwnl.nl/video/fragment/vandaag-de-dag-verkiezingen__POMS_WNL_853698',
  116. 'info_dict': {
  117. 'id': 'POW_00996502',
  118. 'ext': 'm4v',
  119. 'title': '''"Dit is wel een 'landslide'..."''',
  120. 'description': 'md5:f8d66d537dfb641380226e31ca57b8e8',
  121. 'upload_date': '20150508',
  122. 'duration': 462,
  123. },
  124. 'params': {
  125. 'skip_download': True,
  126. }
  127. }, {
  128. # audio
  129. 'url': 'http://www.npo.nl/jouw-stad-rotterdam/29-01-2017/RBX_FUNX_6683215/RBX_FUNX_7601437',
  130. 'info_dict': {
  131. 'id': 'RBX_FUNX_6683215',
  132. 'ext': 'mp3',
  133. 'title': 'Jouw Stad Rotterdam',
  134. 'description': 'md5:db251505244f097717ec59fabc372d9f',
  135. },
  136. 'params': {
  137. 'skip_download': True,
  138. }
  139. }, {
  140. 'url': 'http://www.zapp.nl/de-bzt-show/gemist/KN_1687547',
  141. 'only_matching': True,
  142. }, {
  143. 'url': 'http://www.zapp.nl/de-bzt-show/filmpjes/POMS_KN_7315118',
  144. 'only_matching': True,
  145. }, {
  146. 'url': 'http://www.zapp.nl/beste-vrienden-quiz/extra-video-s/WO_NTR_1067990',
  147. 'only_matching': True,
  148. }, {
  149. 'url': 'https://www.npo3.nl/3onderzoekt/16-09-2015/VPWON_1239870',
  150. 'only_matching': True,
  151. }, {
  152. # live stream
  153. 'url': 'npo:LI_NL1_4188102',
  154. 'only_matching': True,
  155. }, {
  156. 'url': 'http://www.npo.nl/radio-gaga/13-06-2017/BNN_101383373',
  157. 'only_matching': True,
  158. }, {
  159. 'url': 'https://www.zapp.nl/1803-skelterlab/instructie-video-s/740-instructievideo-s/POMS_AT_11736927',
  160. 'only_matching': True,
  161. }, {
  162. 'url': 'https://www.npostart.nl/broodje-gezond-ei/28-05-2018/KN_1698996',
  163. 'only_matching': True,
  164. }, {
  165. 'url': 'https://npo.nl/KN_1698996',
  166. 'only_matching': True,
  167. }]
  168. @classmethod
  169. def suitable(cls, url):
  170. return (False if any(ie.suitable(url)
  171. for ie in (NPOLiveIE, NPORadioIE, NPORadioFragmentIE))
  172. else super(NPOIE, cls).suitable(url))
  173. def _real_extract(self, url):
  174. video_id = self._match_id(url)
  175. try:
  176. return self._get_info(url, video_id)
  177. except ExtractorError:
  178. return self._get_old_info(video_id)
  179. def _get_info(self, url, video_id):
  180. token = self._download_json(
  181. 'https://www.npostart.nl/api/token', video_id,
  182. 'Downloading token', headers={
  183. 'Referer': url,
  184. 'X-Requested-With': 'XMLHttpRequest',
  185. })['token']
  186. player = self._download_json(
  187. 'https://www.npostart.nl/player/%s' % video_id, video_id,
  188. 'Downloading player JSON', data=urlencode_postdata({
  189. 'autoplay': 0,
  190. 'share': 1,
  191. 'pageUrl': url,
  192. 'hasAdConsent': 0,
  193. '_token': token,
  194. }))
  195. player_token = player['token']
  196. format_urls = set()
  197. formats = []
  198. for profile in ('hls', 'dash-widevine', 'dash-playready', 'smooth'):
  199. streams = self._download_json(
  200. 'https://start-player.npo.nl/video/%s/streams' % video_id,
  201. video_id, 'Downloading %s profile JSON' % profile, fatal=False,
  202. query={
  203. 'profile': profile,
  204. 'quality': 'npo',
  205. 'tokenId': player_token,
  206. 'streamType': 'broadcast',
  207. })
  208. if not streams:
  209. continue
  210. stream = streams.get('stream')
  211. if not isinstance(stream, dict):
  212. continue
  213. stream_url = url_or_none(stream.get('src'))
  214. if not stream_url or stream_url in format_urls:
  215. continue
  216. format_urls.add(stream_url)
  217. if stream.get('protection') is not None:
  218. continue
  219. stream_type = stream.get('type')
  220. stream_ext = determine_ext(stream_url)
  221. if stream_type == 'application/dash+xml' or stream_ext == 'mpd':
  222. formats.extend(self._extract_mpd_formats(
  223. stream_url, video_id, mpd_id='dash', fatal=False))
  224. elif stream_type == 'application/vnd.apple.mpegurl' or stream_ext == 'm3u8':
  225. formats.extend(self._extract_m3u8_formats(
  226. stream_url, video_id, ext='mp4',
  227. entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
  228. elif re.search(r'\.isml?/Manifest', stream_url):
  229. formats.extend(self._extract_ism_formats(
  230. stream_url, video_id, ism_id='mss', fatal=False))
  231. else:
  232. formats.append({
  233. 'url': stream_url,
  234. })
  235. self._sort_formats(formats)
  236. info = {
  237. 'id': video_id,
  238. 'title': video_id,
  239. 'formats': formats,
  240. }
  241. embed_url = url_or_none(player.get('embedUrl'))
  242. if embed_url:
  243. webpage = self._download_webpage(
  244. embed_url, video_id, 'Downloading embed page', fatal=False)
  245. if webpage:
  246. video = self._parse_json(
  247. self._search_regex(
  248. r'\bvideo\s*=\s*({.+?})\s*;', webpage, 'video',
  249. default='{}'), video_id)
  250. if video:
  251. title = video.get('episodeTitle')
  252. subtitles = {}
  253. subtitles_list = video.get('subtitles')
  254. if isinstance(subtitles_list, list):
  255. for cc in subtitles_list:
  256. cc_url = url_or_none(cc.get('src'))
  257. if not cc_url:
  258. continue
  259. lang = str_or_none(cc.get('language')) or 'nl'
  260. subtitles.setdefault(lang, []).append({
  261. 'url': cc_url,
  262. })
  263. return merge_dicts({
  264. 'title': title,
  265. 'description': video.get('description'),
  266. 'thumbnail': url_or_none(
  267. video.get('still_image_url') or video.get('orig_image_url')),
  268. 'duration': int_or_none(video.get('duration')),
  269. 'timestamp': unified_timestamp(video.get('broadcastDate')),
  270. 'creator': video.get('channel'),
  271. 'series': video.get('title'),
  272. 'episode': title,
  273. 'episode_number': int_or_none(video.get('episodeNumber')),
  274. 'subtitles': subtitles,
  275. }, info)
  276. return info
  277. def _get_old_info(self, video_id):
  278. metadata = self._download_json(
  279. 'http://e.omroep.nl/metadata/%s' % video_id,
  280. video_id,
  281. # We have to remove the javascript callback
  282. transform_source=strip_jsonp,
  283. )
  284. error = metadata.get('error')
  285. if error:
  286. raise ExtractorError(error, expected=True)
  287. # For some videos actual video id (prid) is different (e.g. for
  288. # http://www.omroepwnl.nl/video/fragment/vandaag-de-dag-verkiezingen__POMS_WNL_853698
  289. # video id is POMS_WNL_853698 but prid is POW_00996502)
  290. video_id = metadata.get('prid') or video_id
  291. # titel is too generic in some cases so utilize aflevering_titel as well
  292. # when available (e.g. http://tegenlicht.vpro.nl/afleveringen/2014-2015/access-to-africa.html)
  293. title = metadata['titel']
  294. sub_title = metadata.get('aflevering_titel')
  295. if sub_title and sub_title != title:
  296. title += ': %s' % sub_title
  297. token = self._get_token(video_id)
  298. formats = []
  299. urls = set()
  300. def is_legal_url(format_url):
  301. return format_url and format_url not in urls and re.match(
  302. r'^(?:https?:)?//', format_url)
  303. QUALITY_LABELS = ('Laag', 'Normaal', 'Hoog')
  304. QUALITY_FORMATS = ('adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std')
  305. quality_from_label = qualities(QUALITY_LABELS)
  306. quality_from_format_id = qualities(QUALITY_FORMATS)
  307. items = self._download_json(
  308. 'http://ida.omroep.nl/app.php/%s' % video_id, video_id,
  309. 'Downloading formats JSON', query={
  310. 'adaptive': 'yes',
  311. 'token': token,
  312. })['items'][0]
  313. for num, item in enumerate(items):
  314. item_url = item.get('url')
  315. if not is_legal_url(item_url):
  316. continue
  317. urls.add(item_url)
  318. format_id = self._search_regex(
  319. r'video/ida/([^/]+)', item_url, 'format id',
  320. default=None)
  321. item_label = item.get('label')
  322. def add_format_url(format_url):
  323. width = int_or_none(self._search_regex(
  324. r'(\d+)[xX]\d+', format_url, 'width', default=None))
  325. height = int_or_none(self._search_regex(
  326. r'\d+[xX](\d+)', format_url, 'height', default=None))
  327. if item_label in QUALITY_LABELS:
  328. quality = quality_from_label(item_label)
  329. f_id = item_label
  330. elif item_label in QUALITY_FORMATS:
  331. quality = quality_from_format_id(format_id)
  332. f_id = format_id
  333. else:
  334. quality, f_id = [None] * 2
  335. formats.append({
  336. 'url': format_url,
  337. 'format_id': f_id,
  338. 'width': width,
  339. 'height': height,
  340. 'quality': quality,
  341. })
  342. # Example: http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706
  343. if item.get('contentType') in ('url', 'audio'):
  344. add_format_url(item_url)
  345. continue
  346. try:
  347. stream_info = self._download_json(
  348. item_url + '&type=json', video_id,
  349. 'Downloading %s stream JSON'
  350. % item_label or item.get('format') or format_id or num)
  351. except ExtractorError as ee:
  352. if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 404:
  353. error = (self._parse_json(
  354. ee.cause.read().decode(), video_id,
  355. fatal=False) or {}).get('errorstring')
  356. if error:
  357. raise ExtractorError(error, expected=True)
  358. raise
  359. # Stream URL instead of JSON, example: npo:LI_NL1_4188102
  360. if isinstance(stream_info, compat_str):
  361. if not stream_info.startswith('http'):
  362. continue
  363. video_url = stream_info
  364. # JSON
  365. else:
  366. video_url = stream_info.get('url')
  367. if not video_url or 'vodnotavailable.' in video_url or video_url in urls:
  368. continue
  369. urls.add(video_url)
  370. if determine_ext(video_url) == 'm3u8':
  371. formats.extend(self._extract_m3u8_formats(
  372. video_url, video_id, ext='mp4',
  373. entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
  374. else:
  375. add_format_url(video_url)
  376. is_live = metadata.get('medium') == 'live'
  377. if not is_live:
  378. for num, stream in enumerate(metadata.get('streams', [])):
  379. stream_url = stream.get('url')
  380. if not is_legal_url(stream_url):
  381. continue
  382. urls.add(stream_url)
  383. # smooth streaming is not supported
  384. stream_type = stream.get('type', '').lower()
  385. if stream_type in ['ss', 'ms']:
  386. continue
  387. if stream_type == 'hds':
  388. f4m_formats = self._extract_f4m_formats(
  389. stream_url, video_id, fatal=False)
  390. # f4m downloader downloads only piece of live stream
  391. for f4m_format in f4m_formats:
  392. f4m_format['preference'] = -1
  393. formats.extend(f4m_formats)
  394. elif stream_type == 'hls':
  395. formats.extend(self._extract_m3u8_formats(
  396. stream_url, video_id, ext='mp4', fatal=False))
  397. # Example: http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706
  398. elif '.asf' in stream_url:
  399. asx = self._download_xml(
  400. stream_url, video_id,
  401. 'Downloading stream %d ASX playlist' % num,
  402. transform_source=fix_xml_ampersands, fatal=False)
  403. if not asx:
  404. continue
  405. ref = asx.find('./ENTRY/Ref')
  406. if ref is None:
  407. continue
  408. video_url = ref.get('href')
  409. if not video_url or video_url in urls:
  410. continue
  411. urls.add(video_url)
  412. formats.append({
  413. 'url': video_url,
  414. 'ext': stream.get('formaat', 'asf'),
  415. 'quality': stream.get('kwaliteit'),
  416. 'preference': -10,
  417. })
  418. else:
  419. formats.append({
  420. 'url': stream_url,
  421. 'quality': stream.get('kwaliteit'),
  422. })
  423. self._sort_formats(formats)
  424. subtitles = {}
  425. if metadata.get('tt888') == 'ja':
  426. subtitles['nl'] = [{
  427. 'ext': 'vtt',
  428. 'url': 'http://tt888.omroep.nl/tt888/%s' % video_id,
  429. }]
  430. return {
  431. 'id': video_id,
  432. 'title': self._live_title(title) if is_live else title,
  433. 'description': metadata.get('info'),
  434. 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
  435. 'upload_date': unified_strdate(metadata.get('gidsdatum')),
  436. 'duration': parse_duration(metadata.get('tijdsduur')),
  437. 'formats': formats,
  438. 'subtitles': subtitles,
  439. 'is_live': is_live,
  440. }
  441. class NPOLiveIE(NPOBaseIE):
  442. IE_NAME = 'npo.nl:live'
  443. _VALID_URL = r'https?://(?:www\.)?npo(?:start)?\.nl/live(?:/(?P<id>[^/?#&]+))?'
  444. _TESTS = [{
  445. 'url': 'http://www.npo.nl/live/npo-1',
  446. 'info_dict': {
  447. 'id': 'LI_NL1_4188102',
  448. 'display_id': 'npo-1',
  449. 'ext': 'mp4',
  450. 'title': 're:^NPO 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  451. 'is_live': True,
  452. },
  453. 'params': {
  454. 'skip_download': True,
  455. }
  456. }, {
  457. 'url': 'http://www.npo.nl/live',
  458. 'only_matching': True,
  459. }, {
  460. 'url': 'https://www.npostart.nl/live/npo-1',
  461. 'only_matching': True,
  462. }]
  463. def _real_extract(self, url):
  464. display_id = self._match_id(url) or 'npo-1'
  465. webpage = self._download_webpage(url, display_id)
  466. live_id = self._search_regex(
  467. [r'media-id="([^"]+)"', r'data-prid="([^"]+)"'], webpage, 'live id')
  468. return {
  469. '_type': 'url_transparent',
  470. 'url': 'npo:%s' % live_id,
  471. 'ie_key': NPOIE.ie_key(),
  472. 'id': live_id,
  473. 'display_id': display_id,
  474. }
  475. class NPORadioIE(InfoExtractor):
  476. IE_NAME = 'npo.nl:radio'
  477. _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/(?P<id>[^/]+)'
  478. _TEST = {
  479. 'url': 'http://www.npo.nl/radio/radio-1',
  480. 'info_dict': {
  481. 'id': 'radio-1',
  482. 'ext': 'mp3',
  483. 'title': 're:^NPO Radio 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  484. 'is_live': True,
  485. },
  486. 'params': {
  487. 'skip_download': True,
  488. }
  489. }
  490. @classmethod
  491. def suitable(cls, url):
  492. return False if NPORadioFragmentIE.suitable(url) else super(NPORadioIE, cls).suitable(url)
  493. @staticmethod
  494. def _html_get_attribute_regex(attribute):
  495. return r'{0}\s*=\s*\'([^\']+)\''.format(attribute)
  496. def _real_extract(self, url):
  497. video_id = self._match_id(url)
  498. webpage = self._download_webpage(url, video_id)
  499. title = self._html_search_regex(
  500. self._html_get_attribute_regex('data-channel'), webpage, 'title')
  501. stream = self._parse_json(
  502. self._html_search_regex(self._html_get_attribute_regex('data-streams'), webpage, 'data-streams'),
  503. video_id)
  504. codec = stream.get('codec')
  505. return {
  506. 'id': video_id,
  507. 'url': stream['url'],
  508. 'title': self._live_title(title),
  509. 'acodec': codec,
  510. 'ext': codec,
  511. 'is_live': True,
  512. }
  513. class NPORadioFragmentIE(InfoExtractor):
  514. IE_NAME = 'npo.nl:radio:fragment'
  515. _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/[^/]+/fragment/(?P<id>\d+)'
  516. _TEST = {
  517. 'url': 'http://www.npo.nl/radio/radio-5/fragment/174356',
  518. 'md5': 'dd8cc470dad764d0fdc70a9a1e2d18c2',
  519. 'info_dict': {
  520. 'id': '174356',
  521. 'ext': 'mp3',
  522. 'title': 'Jubileumconcert Willeke Alberti',
  523. },
  524. }
  525. def _real_extract(self, url):
  526. audio_id = self._match_id(url)
  527. webpage = self._download_webpage(url, audio_id)
  528. title = self._html_search_regex(
  529. r'href="/radio/[^/]+/fragment/%s" title="([^"]+)"' % audio_id,
  530. webpage, 'title')
  531. audio_url = self._search_regex(
  532. r"data-streams='([^']+)'", webpage, 'audio url')
  533. return {
  534. 'id': audio_id,
  535. 'url': audio_url,
  536. 'title': title,
  537. }
  538. class NPODataMidEmbedIE(InfoExtractor):
  539. def _real_extract(self, url):
  540. display_id = self._match_id(url)
  541. webpage = self._download_webpage(url, display_id)
  542. video_id = self._search_regex(
  543. r'data-mid=(["\'])(?P<id>(?:(?!\1).)+)\1', webpage, 'video_id', group='id')
  544. return {
  545. '_type': 'url_transparent',
  546. 'ie_key': 'NPO',
  547. 'url': 'npo:%s' % video_id,
  548. 'display_id': display_id
  549. }
  550. class SchoolTVIE(NPODataMidEmbedIE):
  551. IE_NAME = 'schooltv'
  552. _VALID_URL = r'https?://(?:www\.)?schooltv\.nl/video/(?P<id>[^/?#&]+)'
  553. _TEST = {
  554. 'url': 'http://www.schooltv.nl/video/ademhaling-de-hele-dag-haal-je-adem-maar-wat-gebeurt-er-dan-eigenlijk-in-je-lichaam/',
  555. 'info_dict': {
  556. 'id': 'WO_NTR_429477',
  557. 'display_id': 'ademhaling-de-hele-dag-haal-je-adem-maar-wat-gebeurt-er-dan-eigenlijk-in-je-lichaam',
  558. 'title': 'Ademhaling: De hele dag haal je adem. Maar wat gebeurt er dan eigenlijk in je lichaam?',
  559. 'ext': 'mp4',
  560. 'description': 'md5:abfa0ff690adb73fd0297fd033aaa631'
  561. },
  562. 'params': {
  563. # Skip because of m3u8 download
  564. 'skip_download': True
  565. }
  566. }
  567. class HetKlokhuisIE(NPODataMidEmbedIE):
  568. IE_NAME = 'hetklokhuis'
  569. _VALID_URL = r'https?://(?:www\.)?hetklokhuis\.nl/[^/]+/\d+/(?P<id>[^/?#&]+)'
  570. _TEST = {
  571. 'url': 'http://hetklokhuis.nl/tv-uitzending/3471/Zwaartekrachtsgolven',
  572. 'info_dict': {
  573. 'id': 'VPWON_1260528',
  574. 'display_id': 'Zwaartekrachtsgolven',
  575. 'ext': 'm4v',
  576. 'title': 'Het Klokhuis: Zwaartekrachtsgolven',
  577. 'description': 'md5:c94f31fb930d76c2efa4a4a71651dd48',
  578. 'upload_date': '20170223',
  579. },
  580. 'params': {
  581. 'skip_download': True
  582. }
  583. }
  584. class NPOPlaylistBaseIE(NPOIE):
  585. def _real_extract(self, url):
  586. playlist_id = self._match_id(url)
  587. webpage = self._download_webpage(url, playlist_id)
  588. entries = [
  589. self.url_result('npo:%s' % video_id if not video_id.startswith('http') else video_id)
  590. for video_id in orderedSet(re.findall(self._PLAYLIST_ENTRY_RE, webpage))
  591. ]
  592. playlist_title = self._html_search_regex(
  593. self._PLAYLIST_TITLE_RE, webpage, 'playlist title',
  594. default=None) or self._og_search_title(webpage)
  595. return self.playlist_result(entries, playlist_id, playlist_title)
  596. class VPROIE(NPOPlaylistBaseIE):
  597. IE_NAME = 'vpro'
  598. _VALID_URL = r'https?://(?:www\.)?(?:(?:tegenlicht\.)?vpro|2doc)\.nl/(?:[^/]+/)*(?P<id>[^/]+)\.html'
  599. _PLAYLIST_TITLE_RE = (r'<h1[^>]+class=["\'].*?\bmedia-platform-title\b.*?["\'][^>]*>([^<]+)',
  600. r'<h5[^>]+class=["\'].*?\bmedia-platform-subtitle\b.*?["\'][^>]*>([^<]+)')
  601. _PLAYLIST_ENTRY_RE = r'data-media-id="([^"]+)"'
  602. _TESTS = [
  603. {
  604. 'url': 'http://tegenlicht.vpro.nl/afleveringen/2012-2013/de-toekomst-komt-uit-afrika.html',
  605. 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
  606. 'info_dict': {
  607. 'id': 'VPWON_1169289',
  608. 'ext': 'm4v',
  609. 'title': 'De toekomst komt uit Afrika',
  610. 'description': 'md5:52cf4eefbc96fffcbdc06d024147abea',
  611. 'upload_date': '20130225',
  612. },
  613. 'skip': 'Video gone',
  614. },
  615. {
  616. 'url': 'http://www.vpro.nl/programmas/2doc/2015/sergio-herman.html',
  617. 'info_dict': {
  618. 'id': 'sergio-herman',
  619. 'title': 'sergio herman: fucking perfect',
  620. },
  621. 'playlist_count': 2,
  622. },
  623. {
  624. # playlist with youtube embed
  625. 'url': 'http://www.vpro.nl/programmas/2doc/2015/education-education.html',
  626. 'info_dict': {
  627. 'id': 'education-education',
  628. 'title': 'education education',
  629. },
  630. 'playlist_count': 2,
  631. },
  632. {
  633. 'url': 'http://www.2doc.nl/documentaires/series/2doc/2015/oktober/de-tegenprestatie.html',
  634. 'info_dict': {
  635. 'id': 'de-tegenprestatie',
  636. 'title': 'De Tegenprestatie',
  637. },
  638. 'playlist_count': 2,
  639. }, {
  640. 'url': 'http://www.2doc.nl/speel~VARA_101375237~mh17-het-verdriet-van-nederland~.html',
  641. 'info_dict': {
  642. 'id': 'VARA_101375237',
  643. 'ext': 'm4v',
  644. 'title': 'MH17: Het verdriet van Nederland',
  645. 'description': 'md5:09e1a37c1fdb144621e22479691a9f18',
  646. 'upload_date': '20150716',
  647. },
  648. 'params': {
  649. # Skip because of m3u8 download
  650. 'skip_download': True
  651. },
  652. }
  653. ]
  654. class WNLIE(NPOPlaylistBaseIE):
  655. IE_NAME = 'wnl'
  656. _VALID_URL = r'https?://(?:www\.)?omroepwnl\.nl/video/detail/(?P<id>[^/]+)__\d+'
  657. _PLAYLIST_TITLE_RE = r'(?s)<h1[^>]+class="subject"[^>]*>(.+?)</h1>'
  658. _PLAYLIST_ENTRY_RE = r'<a[^>]+href="([^"]+)"[^>]+class="js-mid"[^>]*>Deel \d+'
  659. _TESTS = [{
  660. 'url': 'http://www.omroepwnl.nl/video/detail/vandaag-de-dag-6-mei__060515',
  661. 'info_dict': {
  662. 'id': 'vandaag-de-dag-6-mei',
  663. 'title': 'Vandaag de Dag 6 mei',
  664. },
  665. 'playlist_count': 4,
  666. }]
  667. class AndereTijdenIE(NPOPlaylistBaseIE):
  668. IE_NAME = 'anderetijden'
  669. _VALID_URL = r'https?://(?:www\.)?anderetijden\.nl/programma/(?:[^/]+/)+(?P<id>[^/?#&]+)'
  670. _PLAYLIST_TITLE_RE = r'(?s)<h1[^>]+class=["\'].*?\bpage-title\b.*?["\'][^>]*>(.+?)</h1>'
  671. _PLAYLIST_ENTRY_RE = r'<figure[^>]+class=["\']episode-container episode-page["\'][^>]+data-prid=["\'](.+?)["\']'
  672. _TESTS = [{
  673. 'url': 'http://anderetijden.nl/programma/1/Andere-Tijden/aflevering/676/Duitse-soldaten-over-de-Slag-bij-Arnhem',
  674. 'info_dict': {
  675. 'id': 'Duitse-soldaten-over-de-Slag-bij-Arnhem',
  676. 'title': 'Duitse soldaten over de Slag bij Arnhem',
  677. },
  678. 'playlist_count': 3,
  679. }]