Skip to content

Commit

Permalink
Merge pull request #74 from nano-devs/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
madeyoga authored Dec 4, 2020
2 parents 51ce2ea + 4fb0a55 commit 239f73c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/client/NanoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/service/music/TrackScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<AudioTrack> queue;
private boolean inLoopState;
Expand Down Expand Up @@ -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();

Expand All @@ -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);
}
}

0 comments on commit 239f73c

Please sign in to comment.