ndr.py 18 KB

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