You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

402 lines
14 KiB

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