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.

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