diff --git a/build.gradle b/build.gradle index b2898a5..a861d9a 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ dependencies { compile 'com.jagrosh:jda-utilities:3.0.4' compile group: 'commons-validator', name: 'commons-validator', version: '1.4.0' compile 'joda-time:joda-time:2.10.6' - implementation 'com.sedmelluq:lavaplayer:1.3.61' + implementation 'com.sedmelluq:lavaplayer:1.3.63' implementation("com.sedmelluq:lavaplayer-ext-youtube-rotator:0.2.1") compile 'com.github.natanbc:lavadsp:0.7.4' implementation 'com.github.Shiroechi:YoutubeSearchApi-Java:1.2.6' diff --git a/src/main/java/client/NanoClient.java b/src/main/java/client/NanoClient.java index 5949349..58b24de 100644 --- a/src/main/java/client/NanoClient.java +++ b/src/main/java/client/NanoClient.java @@ -2,10 +2,10 @@ import com.jagrosh.jdautilities.command.GuildSettingsManager; import com.jagrosh.jdautilities.commons.waiter.EventWaiter; +import com.sedmelluq.discord.lavaplayer.player.AudioConfiguration; import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler; import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; -import com.sedmelluq.discord.lavaplayer.source.AudioSourceManager; import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers; import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager; import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; @@ -41,19 +41,28 @@ public NanoClient(MusicService musicService, EventWaiter waiter) { this.musicManagers = new HashMap<>(); this.playerManager = new DefaultAudioPlayerManager(); + this.playerManager.getConfiguration().setOpusEncodingQuality(AudioConfiguration.OPUS_QUALITY_MAX); + this.playerManager.getConfiguration().setResamplingQuality(AudioConfiguration.ResamplingQuality.HIGH); + this.playerManager.getConfiguration().setFilterHotSwapEnabled(true); + AudioSourceManagers.registerRemoteSources(playerManager); AudioSourceManagers.registerLocalSource(playerManager); + this.playerManager.setHttpRequestConfigurator((config) -> RequestConfig.copy(config).setConnectTimeout(10000).build()); + YoutubeAudioSourceManager youtubeAudioSourceManager = new YoutubeAudioSourceManager(true); + if (System.getenv("ipv6") != null) { String ipv6Block = System.getenv("ipv6block") + "/64"; System.out.println("Setup ipv6: " + ipv6Block); new YoutubeIpRotatorSetup( new NanoIpRoutePlanner(Collections.singletonList(new Ipv6Block(ipv6Block)), true)) - .forManager(this.playerManager) + .forSource(youtubeAudioSourceManager) .setup(); } + this.playerManager.registerSourceManager(youtubeAudioSourceManager); + playerManager.registerSourceManager(new YoutubeAudioSourceManager(true)); this.waiter = waiter; } diff --git a/src/main/java/service/music/TrackScheduler.java b/src/main/java/service/music/TrackScheduler.java index a74b7b1..646801c 100644 --- a/src/main/java/service/music/TrackScheduler.java +++ b/src/main/java/service/music/TrackScheduler.java @@ -6,6 +6,8 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason; import net.dv8tion.jda.api.entities.TextChannel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.HashSet; import java.util.Set; @@ -16,6 +18,7 @@ * This class schedules tracks for the audio player. It contains the queue of tracks. */ public class TrackScheduler extends AudioEventAdapter { + private static final Logger log = LoggerFactory.getLogger(TrackScheduler.class); private final AudioPlayer player; private final BlockingQueue queue; private boolean inLoopState; @@ -78,6 +81,8 @@ public void setInLoopState(boolean inLoopState) { @Override public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) { + log.info("onTrackEnd " + track.getIdentifier() + " " + endReason.name()); + // Reset vote skip skipVoteSet.clear(); @@ -96,21 +101,29 @@ public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason @Override public void onTrackStart(AudioPlayer player, AudioTrack track) { + log.info("onTrackStart " + track.getIdentifier()); + super.onTrackStart(player, track); } @Override public void onTrackException(AudioPlayer player, AudioTrack track, FriendlyException exception) { - super.onTrackException(player, track, exception); + log.info("onTrackException " + track.getIdentifier() + + " Message: " + exception.getMessage() + + " Caused by: " + exception.getCause()); textChannel.sendMessage(":x: | " + exception.getMessage() + ". Try request the song again, if it's still broke, please contact developers... :(").queue(); exception.printStackTrace(); + + super.onTrackException(player, track, exception); } @Override public void onTrackStuck(AudioPlayer player, AudioTrack track, long thresholdMs) { + log.info("onTrackStuck " + track.getIdentifier()); + super.onTrackStuck(player, track, thresholdMs); } }