logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

ndr.py (18246B)


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