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.

389 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,
  177. f4m_id='hds', fatal=False))
  178. elif ext == 'm3u8':
  179. formats.extend(self._extract_m3u8_formats(
  180. src, video_id, 'mp4', m3u8_id='hls',
  181. entry_protocol='m3u8_native', fatal=False))
  182. else:
  183. quality = f.get('quality')
  184. ff = {
  185. 'url': src,
  186. 'format_id': quality or format_id,
  187. 'quality': quality_key(quality),
  188. }
  189. type_ = f.get('type')
  190. if type_ and type_.split('/')[0] == 'audio':
  191. ff['vcodec'] = 'none'
  192. ff['ext'] = ext or 'mp3'
  193. formats.append(ff)
  194. self._sort_formats(formats)
  195. config = playlist['config']
  196. live = playlist.get('config', {}).get('streamType') in ['httpVideoLive', 'httpAudioLive']
  197. title = config['title']
  198. if live:
  199. title = self._live_title(title)
  200. uploader = ppjson.get('config', {}).get('branding')
  201. upload_date = ppjson.get('config', {}).get('publicationDate')
  202. duration = int_or_none(config.get('duration'))
  203. thumbnails = [{
  204. 'id': thumbnail.get('quality') or thumbnail_id,
  205. 'url': thumbnail['src'],
  206. 'preference': quality_key(thumbnail.get('quality')),
  207. } for thumbnail_id, thumbnail in config.get('poster', {}).items() if thumbnail.get('src')]
  208. return {
  209. 'id': video_id,
  210. 'title': title,
  211. 'is_live': live,
  212. 'uploader': uploader if uploader != '-' else None,
  213. 'upload_date': upload_date[0:8] if upload_date else None,
  214. 'duration': duration,
  215. 'thumbnails': thumbnails,
  216. 'formats': formats,
  217. }
  218. class NDREmbedIE(NDREmbedBaseIE):
  219. IE_NAME = 'ndr:embed'
  220. _VALID_URL = r'https?://(?:www\.)?ndr\.de/(?:[^/]+/)*(?P<id>[\da-z]+)-(?:player|externalPlayer)\.html'
  221. _TESTS = [{
  222. 'url': 'http://www.ndr.de/fernsehen/sendungen/ndr_aktuell/ndraktuell28488-player.html',
  223. 'md5': '8b9306142fe65bbdefb5ce24edb6b0a9',
  224. 'info_dict': {
  225. 'id': 'ndraktuell28488',
  226. 'ext': 'mp4',
  227. 'title': 'Norddeutschland begrüßt Flüchtlinge',
  228. 'is_live': False,
  229. 'uploader': 'ndrtv',
  230. 'upload_date': '20150907',
  231. 'duration': 132,
  232. },
  233. }, {
  234. 'url': 'http://www.ndr.de/ndr2/events/soundcheck/soundcheck3366-player.html',
  235. 'md5': '002085c44bae38802d94ae5802a36e78',
  236. 'info_dict': {
  237. 'id': 'soundcheck3366',
  238. 'ext': 'mp4',
  239. 'title': 'Ella Henderson braucht Vergleiche nicht zu scheuen',
  240. 'is_live': False,
  241. 'uploader': 'ndr2',
  242. 'upload_date': '20150912',
  243. 'duration': 3554,
  244. },
  245. 'params': {
  246. 'skip_download': True,
  247. },
  248. }, {
  249. 'url': 'http://www.ndr.de/info/audio51535-player.html',
  250. 'md5': 'bb3cd38e24fbcc866d13b50ca59307b8',
  251. 'info_dict': {
  252. 'id': 'audio51535',
  253. 'ext': 'mp3',
  254. 'title': 'La Valette entgeht der Hinrichtung',
  255. 'is_live': False,
  256. 'uploader': 'ndrinfo',
  257. 'upload_date': '20140729',
  258. 'duration': 884,
  259. },
  260. 'params': {
  261. 'skip_download': True,
  262. },
  263. }, {
  264. 'url': 'http://www.ndr.de/fernsehen/sendungen/visite/visite11010-externalPlayer.html',
  265. 'md5': 'ae57f80511c1e1f2fd0d0d3d31aeae7c',
  266. 'info_dict': {
  267. 'id': 'visite11010',
  268. 'ext': 'mp4',
  269. 'title': 'Visite - die ganze Sendung',
  270. 'is_live': False,
  271. 'uploader': 'ndrtv',
  272. 'upload_date': '20150902',
  273. 'duration': 3525,
  274. },
  275. 'params': {
  276. 'skip_download': True,
  277. },
  278. }, {
  279. # httpVideoLive
  280. 'url': 'http://www.ndr.de/fernsehen/livestream/livestream217-externalPlayer.html',
  281. 'info_dict': {
  282. 'id': 'livestream217',
  283. 'ext': 'flv',
  284. 'title': r're:^NDR Fernsehen Niedersachsen \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
  285. 'is_live': True,
  286. 'upload_date': '20150910',
  287. },
  288. 'params': {
  289. 'skip_download': True,
  290. },
  291. }, {
  292. 'url': 'http://www.ndr.de/ndrkultur/audio255020-player.html',
  293. 'only_matching': True,
  294. }, {
  295. 'url': 'http://www.ndr.de/fernsehen/sendungen/nordtour/nordtour7124-player.html',
  296. 'only_matching': True,
  297. }, {
  298. 'url': 'http://www.ndr.de/kultur/film/videos/videoimport10424-player.html',
  299. 'only_matching': True,
  300. }, {
  301. 'url': 'http://www.ndr.de/fernsehen/sendungen/hamburg_journal/hamj43006-player.html',
  302. 'only_matching': True,
  303. }, {
  304. 'url': 'http://www.ndr.de/fernsehen/sendungen/weltbilder/weltbilder4518-player.html',
  305. 'only_matching': True,
  306. }, {
  307. 'url': 'http://www.ndr.de/fernsehen/doku952-player.html',
  308. 'only_matching': True,
  309. }]
  310. class NJoyEmbedIE(NDREmbedBaseIE):
  311. IE_NAME = 'njoy:embed'
  312. _VALID_URL = r'https?://(?:www\.)?n-joy\.de/(?:[^/]+/)*(?P<id>[\da-z]+)-(?:player|externalPlayer)_[^/]+\.html'
  313. _TESTS = [{
  314. # httpVideo
  315. 'url': 'http://www.n-joy.de/events/reeperbahnfestival/doku948-player_image-bc168e87-5263-4d6d-bd27-bb643005a6de_theme-n-joy.html',
  316. 'md5': '8483cbfe2320bd4d28a349d62d88bd74',
  317. 'info_dict': {
  318. 'id': 'doku948',
  319. 'ext': 'mp4',
  320. 'title': 'Zehn Jahre Reeperbahn Festival - die Doku',
  321. 'is_live': False,
  322. 'upload_date': '20150807',
  323. 'duration': 1011,
  324. },
  325. }, {
  326. # httpAudio
  327. 'url': 'http://www.n-joy.de/news_wissen/stefanrichter100-player_image-d5e938b1-f21a-4b9a-86b8-aaba8bca3a13_theme-n-joy.html',
  328. 'md5': 'd989f80f28ac954430f7b8a48197188a',
  329. 'info_dict': {
  330. 'id': 'stefanrichter100',
  331. 'ext': 'mp3',
  332. 'title': 'Interview mit einem Augenzeugen',
  333. 'is_live': False,
  334. 'uploader': 'njoy',
  335. 'upload_date': '20150909',
  336. 'duration': 140,
  337. },
  338. 'params': {
  339. 'skip_download': True,
  340. },
  341. }, {
  342. # httpAudioLive, no explicit ext
  343. 'url': 'http://www.n-joy.de/news_wissen/webradioweltweit100-player_image-3fec0484-2244-4565-8fb8-ed25fd28b173_theme-n-joy.html',
  344. 'info_dict': {
  345. 'id': 'webradioweltweit100',
  346. 'ext': 'mp3',
  347. 'title': r're:^N-JOY Weltweit \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
  348. 'is_live': True,
  349. 'uploader': 'njoy',
  350. 'upload_date': '20150810',
  351. },
  352. 'params': {
  353. 'skip_download': True,
  354. },
  355. }, {
  356. 'url': 'http://www.n-joy.de/musik/dockville882-player_image-3905259e-0803-4764-ac72-8b7de077d80a_theme-n-joy.html',
  357. 'only_matching': True,
  358. }, {
  359. 'url': 'http://www.n-joy.de/radio/sendungen/morningshow/urlaubsfotos190-player_image-066a5df1-5c95-49ec-a323-941d848718db_theme-n-joy.html',
  360. 'only_matching': True,
  361. }, {
  362. 'url': 'http://www.n-joy.de/entertainment/comedy/krudetv290-player_image-ab261bfe-51bf-4bf3-87ba-c5122ee35b3d_theme-n-joy.html',
  363. 'only_matching': True,
  364. }]