ndr.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_urllib_parse_urlparse
  6. from ..utils import (
  7. determine_ext,
  8. ExtractorError,
  9. int_or_none,
  10. merge_dicts,
  11. parse_iso8601,
  12. qualities,
  13. try_get,
  14. urljoin,
  15. )
  16. class NDRBaseIE(InfoExtractor):
  17. def _real_extract(self, url):
  18. mobj = re.match(self._VALID_URL, url)
  19. display_id = next(group for group in mobj.groups() if group)
  20. webpage = self._download_webpage(url, display_id)
  21. return self._extract_embed(webpage, display_id, url)
  22. class NDRIE(NDRBaseIE):
  23. IE_NAME = 'ndr'
  24. IE_DESC = 'NDR.de - Norddeutscher Rundfunk'
  25. _VALID_URL = r'https?://(?:\w+\.)?ndr\.de/(?:[^/]+/)*(?P<id>[^/?#]+),[\da-z]+\.html'
  26. _TESTS = [{
  27. # httpVideo, same content id
  28. 'url': 'http://www.ndr.de/fernsehen/Party-Poette-und-Parade,hafengeburtstag988.html',
  29. 'md5': '6515bc255dc5c5f8c85bbc38e035a659',
  30. 'info_dict': {
  31. 'id': 'hafengeburtstag988',
  32. 'display_id': 'Party-Poette-und-Parade',
  33. 'ext': 'mp4',
  34. 'title': 'Party, Pötte und Parade',
  35. 'description': 'md5:ad14f9d2f91d3040b6930c697e5f6b4c',
  36. 'uploader': 'ndrtv',
  37. 'timestamp': 1431108900,
  38. 'upload_date': '20150510',
  39. 'duration': 3498,
  40. },
  41. 'params': {
  42. 'skip_download': True,
  43. },
  44. }, {
  45. # httpVideo, different content id
  46. 'url': 'http://www.ndr.de/sport/fussball/40-Osnabrueck-spielt-sich-in-einen-Rausch,osna270.html',
  47. 'md5': '1043ff203eab307f0c51702ec49e9a71',
  48. 'info_dict': {
  49. 'id': 'osna272',
  50. 'display_id': '40-Osnabrueck-spielt-sich-in-einen-Rausch',
  51. 'ext': 'mp4',
  52. 'title': 'Osnabrück - Wehen Wiesbaden: Die Highlights',
  53. 'description': 'md5:32e9b800b3d2d4008103752682d5dc01',
  54. 'uploader': 'ndrtv',
  55. 'timestamp': 1442059200,
  56. 'upload_date': '20150912',
  57. 'duration': 510,
  58. },
  59. 'params': {
  60. 'skip_download': True,
  61. },
  62. }, {
  63. # httpAudio, same content id
  64. 'url': 'http://www.ndr.de/info/La-Valette-entgeht-der-Hinrichtung,audio51535.html',
  65. 'md5': 'bb3cd38e24fbcc866d13b50ca59307b8',
  66. 'info_dict': {
  67. 'id': 'audio51535',
  68. 'display_id': 'La-Valette-entgeht-der-Hinrichtung',
  69. 'ext': 'mp3',
  70. 'title': 'La Valette entgeht der Hinrichtung',
  71. 'description': 'md5:22f9541913a40fe50091d5cdd7c9f536',
  72. 'uploader': 'ndrinfo',
  73. 'timestamp': 1290626100,
  74. 'upload_date': '20140729',
  75. 'duration': 884,
  76. },
  77. 'params': {
  78. 'skip_download': True,
  79. },
  80. }, {
  81. # with subtitles
  82. 'url': 'https://www.ndr.de/fernsehen/sendungen/extra_3/extra-3-Satiremagazin-mit-Christian-Ehring,sendung1091858.html',
  83. 'info_dict': {
  84. 'id': 'extra18674',
  85. 'display_id': 'extra-3-Satiremagazin-mit-Christian-Ehring',
  86. 'ext': 'mp4',
  87. 'title': 'Extra 3 vom 11.11.2020 mit Christian Ehring',
  88. 'description': 'md5:42ee53990a715eaaf4dc7f13a3bd56c6',
  89. 'uploader': 'ndrtv',
  90. 'upload_date': '20201113',
  91. 'duration': 1749,
  92. 'subtitles': {
  93. 'de': [{
  94. 'ext': 'ttml',
  95. 'url': r're:^https://www\.ndr\.de.+',
  96. }],
  97. },
  98. },
  99. 'params': {
  100. 'skip_download': True,
  101. },
  102. 'expected_warnings': ['Unable to download f4m manifest'],
  103. }, {
  104. 'url': 'https://www.ndr.de/Fettes-Brot-Ferris-MC-und-Thees-Uhlmann-live-on-stage,festivalsommer116.html',
  105. 'only_matching': True,
  106. }]
  107. def _extract_embed(self, webpage, display_id, url):
  108. embed_url = (
  109. self._html_search_meta(
  110. 'embedURL', webpage, 'embed URL',
  111. default=None)
  112. or self._search_regex(
  113. r'\bembedUrl["\']\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
  114. 'embed URL', group='url', default=None)
  115. or self._search_regex(
  116. r'\bvar\s*sophoraID\s*=\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
  117. 'embed URL', group='url', default=''))
  118. # some more work needed if we only found sophoraID
  119. if re.match(r'^[a-z]+\d+$', embed_url):
  120. # get the initial part of the url path,. eg /panorama/archiv/2022/
  121. parsed_url = compat_urllib_parse_urlparse(url)
  122. path = self._search_regex(r'(.+/)%s' % display_id, parsed_url.path or '', 'embed URL', default='')
  123. # find tell-tale image with the actual ID
  124. ndr_id = self._search_regex(r'%s([a-z]+\d+)(?!\.)\b' % (path, ), webpage, 'embed URL', default=None)
  125. # or try to use special knowledge!
  126. NDR_INFO_URL_TPL = 'https://www.ndr.de/info/%s-player.html'
  127. embed_url = 'ndr:%s' % (ndr_id, ) if ndr_id else NDR_INFO_URL_TPL % (embed_url, )
  128. if not embed_url:
  129. raise ExtractorError('Unable to extract embedUrl')
  130. description = self._search_regex(
  131. r'<p[^>]+itemprop="description">([^<]+)</p>',
  132. webpage, 'description', default=None) or self._og_search_description(webpage)
  133. timestamp = parse_iso8601(
  134. self._search_regex(
  135. (r'<span[^>]+itemprop="(?:datePublished|uploadDate)"[^>]+content="(?P<cont>[^"]+)"',
  136. r'\bvar\s*pdt\s*=\s*(?P<q>["\'])(?P<cont>(?:(?!(?P=q)).)+)(?P=q)', ),
  137. webpage, 'upload date', group='cont', default=None))
  138. info = self._search_json_ld(webpage, display_id, default={})
  139. return merge_dicts({
  140. '_type': 'url_transparent',
  141. 'url': embed_url,
  142. 'display_id': display_id,
  143. 'description': description,
  144. 'timestamp': timestamp,
  145. }, info)
  146. class NJoyIE(NDRBaseIE):
  147. IE_NAME = 'njoy'
  148. IE_DESC = 'N-JOY'
  149. _VALID_URL = r'https?://(?:www\.)?n-joy\.de/(?:[^/]+/)*(?:(?P<display_id>[^/?#]+),)?(?P<id>[\da-z]+)\.html'
  150. _TESTS = [{
  151. # httpVideo, same content id
  152. 'url': 'http://www.n-joy.de/entertainment/comedy/comedy_contest/Benaissa-beim-NDR-Comedy-Contest,comedycontest2480.html',
  153. 'md5': 'cb63be60cd6f9dd75218803146d8dc67',
  154. 'info_dict': {
  155. 'id': 'comedycontest2480',
  156. 'display_id': 'Benaissa-beim-NDR-Comedy-Contest',
  157. 'ext': 'mp4',
  158. 'title': 'Benaissa beim NDR Comedy Contest',
  159. 'description': 'md5:f057a6c4e1c728b10d33b5ffd36ddc39',
  160. 'uploader': 'ndrtv',
  161. 'upload_date': '20141129',
  162. 'duration': 654,
  163. },
  164. 'params': {
  165. 'skip_download': True,
  166. },
  167. }, {
  168. # httpVideo, different content id
  169. 'url': 'http://www.n-joy.de/musik/Das-frueheste-DJ-Set-des-Nordens-live-mit-Felix-Jaehn-,felixjaehn168.html',
  170. 'md5': '417660fffa90e6df2fda19f1b40a64d8',
  171. 'info_dict': {
  172. 'id': 'dockville882',
  173. 'display_id': 'Das-frueheste-DJ-Set-des-Nordens-live-mit-Felix-Jaehn-',
  174. 'ext': 'mp4',
  175. 'title': '"Ich hab noch nie" mit Felix Jaehn',
  176. 'description': 'md5:85dd312d53be1b99e1f998a16452a2f3',
  177. 'uploader': 'njoy',
  178. 'upload_date': '20150822',
  179. 'duration': 211,
  180. },
  181. 'params': {
  182. 'skip_download': True,
  183. },
  184. }, {
  185. 'url': 'http://www.n-joy.de/radio/webradio/morningshow209.html',
  186. 'only_matching': True,
  187. }]
  188. def _extract_embed(self, webpage, display_id, url=None):
  189. # find tell-tale URL with the actual ID, or ...
  190. video_id = self._search_regex(
  191. (r'''\bsrc\s*=\s*(?:"|')?(?:/\w+)+/([a-z]+\d+)(?!\.)\b''',
  192. r'<iframe[^>]+id="pp_([\da-z]+)"', ),
  193. webpage, 'NDR id', default=None)
  194. description = (
  195. self._html_search_meta('description', webpage)
  196. or self._search_regex(
  197. r'<div[^>]+class="subline"[^>]*>[^<]+</div>\s*<p>([^<]+)</p>',
  198. webpage, 'description', fatal=False))
  199. return {
  200. '_type': 'url_transparent',
  201. 'ie_key': 'NDREmbedBase',
  202. 'url': 'ndr:%s' % video_id,
  203. 'display_id': display_id,
  204. 'description': description,
  205. 'title': display_id.replace('-', ' ').strip(),
  206. }
  207. class NDREmbedBaseIE(InfoExtractor):
  208. IE_NAME = 'ndr:embed:base'
  209. _VALID_URL = r'(?:ndr:(?P<id_s>[\da-z]+)|https?://www\.ndr\.de/(?P<id>[\da-z]+)-ppjson\.json)'
  210. _TESTS = [{
  211. 'url': 'ndr:soundcheck3366',
  212. 'only_matching': True,
  213. }, {
  214. 'url': 'http://www.ndr.de/soundcheck3366-ppjson.json',
  215. 'only_matching': True,
  216. }]
  217. def _real_extract(self, url):
  218. mobj = re.match(self._VALID_URL, url)
  219. video_id = mobj.group('id') or mobj.group('id_s')
  220. ppjson = self._download_json(
  221. 'http://www.ndr.de/%s-ppjson.json' % video_id, video_id)
  222. playlist = ppjson['playlist']
  223. formats = []
  224. quality_key = qualities(('xs', 's', 'm', 'l', 'xl'))
  225. for format_id, f in playlist.items():
  226. src = f.get('src')
  227. if not src:
  228. continue
  229. ext = determine_ext(src, None)
  230. if ext == 'f4m':
  231. formats.extend(self._extract_f4m_formats(
  232. src + '?hdcore=3.7.0&plugin=aasp-3.7.0.39.44', video_id,
  233. f4m_id='hds', fatal=False))
  234. elif ext == 'm3u8':
  235. formats.extend(self._extract_m3u8_formats(
  236. src, video_id, 'mp4', m3u8_id='hls',
  237. entry_protocol='m3u8_native', fatal=False))
  238. else:
  239. quality = f.get('quality')
  240. ff = {
  241. 'url': src,
  242. 'format_id': quality or format_id,
  243. 'quality': quality_key(quality),
  244. }
  245. type_ = f.get('type')
  246. if type_ and type_.split('/')[0] == 'audio':
  247. ff['vcodec'] = 'none'
  248. ff['ext'] = ext or 'mp3'
  249. formats.append(ff)
  250. self._sort_formats(formats)
  251. config = playlist['config']
  252. live = playlist.get('config', {}).get('streamType') in ['httpVideoLive', 'httpAudioLive']
  253. title = config['title']
  254. if live:
  255. title = self._live_title(title)
  256. uploader = ppjson.get('config', {}).get('branding')
  257. upload_date = ppjson.get('config', {}).get('publicationDate')
  258. duration = int_or_none(config.get('duration'))
  259. thumbnails = []
  260. poster = try_get(config, lambda x: x['poster'], dict) or {}
  261. for thumbnail_id, thumbnail in poster.items():
  262. thumbnail_url = urljoin(url, thumbnail.get('src'))
  263. if not thumbnail_url:
  264. continue
  265. thumbnails.append({
  266. 'id': thumbnail.get('quality') or thumbnail_id,
  267. 'url': thumbnail_url,
  268. 'preference': quality_key(thumbnail.get('quality')),
  269. })
  270. subtitles = {}
  271. tracks = config.get('tracks')
  272. if tracks and isinstance(tracks, list):
  273. for track in tracks:
  274. if not isinstance(track, dict):
  275. continue
  276. track_url = urljoin(url, track.get('src'))
  277. if not track_url:
  278. continue
  279. subtitles.setdefault(track.get('srclang') or 'de', []).append({
  280. 'url': track_url,
  281. 'ext': 'ttml',
  282. })
  283. return {
  284. 'id': video_id,
  285. 'title': title,
  286. 'is_live': live,
  287. 'uploader': uploader if uploader != '-' else None,
  288. 'upload_date': upload_date[0:8] if upload_date else None,
  289. 'duration': duration,
  290. 'thumbnails': thumbnails,
  291. 'formats': formats,
  292. 'subtitles': subtitles,
  293. }
  294. class NDREmbedIE(NDREmbedBaseIE):
  295. IE_NAME = 'ndr:embed'
  296. _VALID_URL = r'https?://(?:www\.)?ndr\.de/(?:[^/]+/)*(?P<id>[\da-z]+)-(?:(?:ard)?player|externalPlayer)\.html'
  297. _TESTS = [{
  298. 'url': 'http://www.ndr.de/fernsehen/sendungen/ndr_aktuell/ndraktuell28488-player.html',
  299. 'md5': '8b9306142fe65bbdefb5ce24edb6b0a9',
  300. 'info_dict': {
  301. 'id': 'ndraktuell28488',
  302. 'ext': 'mp4',
  303. 'title': 'Norddeutschland begrüßt Flüchtlinge',
  304. 'is_live': False,
  305. 'uploader': 'ndrtv',
  306. 'upload_date': '20150907',
  307. 'duration': 132,
  308. },
  309. }, {
  310. 'url': 'http://www.ndr.de/ndr2/events/soundcheck/soundcheck3366-player.html',
  311. 'md5': '002085c44bae38802d94ae5802a36e78',
  312. 'info_dict': {
  313. 'id': 'soundcheck3366',
  314. 'ext': 'mp4',
  315. 'title': 'Ella Henderson braucht Vergleiche nicht zu scheuen',
  316. 'is_live': False,
  317. 'uploader': 'ndr2',
  318. 'upload_date': '20150912',
  319. 'duration': 3554,
  320. },
  321. 'params': {
  322. 'skip_download': True,
  323. },
  324. }, {
  325. 'url': 'http://www.ndr.de/info/audio51535-player.html',
  326. 'md5': 'bb3cd38e24fbcc866d13b50ca59307b8',
  327. 'info_dict': {
  328. 'id': 'audio51535',
  329. 'ext': 'mp3',
  330. 'title': 'La Valette entgeht der Hinrichtung',
  331. 'is_live': False,
  332. 'uploader': 'ndrinfo',
  333. 'upload_date': '20140729',
  334. 'duration': 884,
  335. },
  336. 'params': {
  337. 'skip_download': True,
  338. },
  339. }, {
  340. 'url': 'http://www.ndr.de/fernsehen/sendungen/visite/visite11010-externalPlayer.html',
  341. 'md5': 'ae57f80511c1e1f2fd0d0d3d31aeae7c',
  342. 'info_dict': {
  343. 'id': 'visite11010',
  344. 'ext': 'mp4',
  345. 'title': 'Visite - die ganze Sendung',
  346. 'is_live': False,
  347. 'uploader': 'ndrtv',
  348. 'upload_date': '20150902',
  349. 'duration': 3525,
  350. },
  351. 'params': {
  352. 'skip_download': True,
  353. },
  354. }, {
  355. # httpVideoLive
  356. 'url': 'http://www.ndr.de/fernsehen/livestream/livestream217-externalPlayer.html',
  357. 'info_dict': {
  358. 'id': 'livestream217',
  359. 'ext': 'flv',
  360. 'title': r're:^NDR Fernsehen Niedersachsen \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
  361. 'is_live': True,
  362. 'upload_date': '20150910',
  363. },
  364. 'params': {
  365. 'skip_download': True,
  366. },
  367. }, {
  368. 'url': 'http://www.ndr.de/ndrkultur/audio255020-player.html',
  369. 'only_matching': True,
  370. }, {
  371. 'url': 'http://www.ndr.de/fernsehen/sendungen/nordtour/nordtour7124-player.html',
  372. 'only_matching': True,
  373. }, {
  374. 'url': 'http://www.ndr.de/kultur/film/videos/videoimport10424-player.html',
  375. 'only_matching': True,
  376. }, {
  377. 'url': 'http://www.ndr.de/fernsehen/sendungen/hamburg_journal/hamj43006-player.html',
  378. 'only_matching': True,
  379. }, {
  380. 'url': 'http://www.ndr.de/fernsehen/sendungen/weltbilder/weltbilder4518-player.html',
  381. 'only_matching': True,
  382. }, {
  383. 'url': 'http://www.ndr.de/fernsehen/doku952-player.html',
  384. 'only_matching': True,
  385. }]
  386. class NJoyEmbedIE(NDREmbedBaseIE):
  387. IE_NAME = 'njoy:embed'
  388. _VALID_URL = r'https?://(?:www\.)?n-joy\.de/(?:[^/]+/)*(?P<id>[\da-z]+)-(?:player|externalPlayer)_[^/]+\.html'
  389. _TESTS = [{
  390. # httpVideo
  391. 'url': 'http://www.n-joy.de/events/reeperbahnfestival/doku948-player_image-bc168e87-5263-4d6d-bd27-bb643005a6de_theme-n-joy.html',
  392. 'md5': '8483cbfe2320bd4d28a349d62d88bd74',
  393. 'info_dict': {
  394. 'id': 'doku948',
  395. 'ext': 'mp4',
  396. 'title': 'Zehn Jahre Reeperbahn Festival - die Doku',
  397. 'is_live': False,
  398. 'upload_date': '20150807',
  399. 'duration': 1011,
  400. },
  401. }, {
  402. # httpAudio
  403. 'url': 'http://www.n-joy.de/news_wissen/stefanrichter100-player_image-d5e938b1-f21a-4b9a-86b8-aaba8bca3a13_theme-n-joy.html',
  404. 'md5': 'd989f80f28ac954430f7b8a48197188a',
  405. 'info_dict': {
  406. 'id': 'stefanrichter100',
  407. 'ext': 'mp3',
  408. 'title': 'Interview mit einem Augenzeugen',
  409. 'is_live': False,
  410. 'uploader': 'njoy',
  411. 'upload_date': '20150909',
  412. 'duration': 140,
  413. },
  414. 'params': {
  415. 'skip_download': True,
  416. },
  417. }, {
  418. # httpAudioLive, no explicit ext
  419. 'url': 'http://www.n-joy.de/news_wissen/webradioweltweit100-player_image-3fec0484-2244-4565-8fb8-ed25fd28b173_theme-n-joy.html',
  420. 'info_dict': {
  421. 'id': 'webradioweltweit100',
  422. 'ext': 'mp3',
  423. 'title': r're:^N-JOY Weltweit \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
  424. 'is_live': True,
  425. 'uploader': 'njoy',
  426. 'upload_date': '20150810',
  427. },
  428. 'params': {
  429. 'skip_download': True,
  430. },
  431. }, {
  432. 'url': 'http://www.n-joy.de/musik/dockville882-player_image-3905259e-0803-4764-ac72-8b7de077d80a_theme-n-joy.html',
  433. 'only_matching': True,
  434. }, {
  435. 'url': 'http://www.n-joy.de/radio/sendungen/morningshow/urlaubsfotos190-player_image-066a5df1-5c95-49ec-a323-941d848718db_theme-n-joy.html',
  436. 'only_matching': True,
  437. }, {
  438. 'url': 'http://www.n-joy.de/entertainment/comedy/krudetv290-player_image-ab261bfe-51bf-4bf3-87ba-c5122ee35b3d_theme-n-joy.html',
  439. 'only_matching': True,
  440. }]