|
1 | 1 | package me.duncte123.lyrics; |
2 | 2 |
|
3 | | -import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; |
4 | | -import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager; |
5 | 3 | import com.sedmelluq.discord.lavaplayer.tools.ExceptionTools; |
6 | 4 | import com.sedmelluq.discord.lavaplayer.tools.io.HttpClientTools; |
7 | 5 | import com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface; |
8 | 6 | import com.sedmelluq.discord.lavaplayer.tools.io.HttpInterfaceManager; |
| 7 | +import com.sedmelluq.lava.extensions.youtuberotator.YoutubeIpRotatorSetup; |
| 8 | +import com.sedmelluq.lava.extensions.youtuberotator.planner.*; |
| 9 | +import lavalink.server.config.RateLimitConfig; |
| 10 | +import lavalink.server.config.ServerConfig; |
| 11 | + |
| 12 | +import java.util.Optional; |
9 | 13 |
|
10 | 14 | public class HttpClientProvider implements AutoCloseable { |
11 | 15 | private final HttpInterfaceManager httpInterfaceManager; |
12 | 16 |
|
13 | | - public HttpClientProvider(AudioPlayerManager playerManager) { |
14 | | - final YoutubeAudioSourceManager sourceManager = playerManager.source(YoutubeAudioSourceManager.class); |
| 17 | + public HttpClientProvider(AbstractRoutePlanner routePlanner, ServerConfig serverConfig) { |
| 18 | + this.httpInterfaceManager = HttpClientTools.createDefaultThreadLocalManager(); |
| 19 | + |
| 20 | + if (routePlanner != null) { |
| 21 | + final int retryLimit = Optional.ofNullable(serverConfig.getRatelimit()) |
| 22 | + .map(RateLimitConfig::getRetryLimit) |
| 23 | + .orElse(-1); |
| 24 | + |
| 25 | + final YoutubeIpRotatorSetup rotator; |
| 26 | + |
| 27 | + if (retryLimit < 0) { |
| 28 | + rotator = new YoutubeIpRotatorSetup(routePlanner); |
| 29 | + } else if (retryLimit == 0) { |
| 30 | + rotator = new YoutubeIpRotatorSetup(routePlanner).withRetryLimit(Integer.MAX_VALUE); |
| 31 | + } else { |
| 32 | + rotator = new YoutubeIpRotatorSetup(routePlanner).withRetryLimit(retryLimit); |
| 33 | + } |
15 | 34 |
|
16 | | - if (sourceManager != null) { |
17 | | - this.httpInterfaceManager = (HttpInterfaceManager) sourceManager.getMainHttpConfiguration(); |
18 | | - } else { |
19 | | - this.httpInterfaceManager = HttpClientTools.createDefaultThreadLocalManager(); |
| 35 | + rotator.forConfiguration(this.httpInterfaceManager, false).setup(); |
20 | 36 | } |
21 | 37 | } |
22 | 38 |
|
|
0 commit comments