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.

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