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.

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