ndr.py 16 KB

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