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.

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