Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 8733899
Author: John Grosh <[email protected]>
Date:   Wed Jul 10 17:35:50 2024 -0400

    Update bug-report.yml

commit e5fd05e
Author: Moritz Bender <[email protected]>
Date:   Wed Jul 10 13:19:13 2024 +0200

    Update dependencies to fix youtube issues (jagrosh#1609)

commit 6a5a9c7
Author: John Grosh <[email protected]>
Date:   Fri May 10 17:43:49 2024 -0400

    Change playlist page count (jagrosh#1542)

    * change playlist page count

    * make the value configurable

    * small refactor

commit 8557f7a
Author: Michaili K <[email protected]>
Date:   Fri May 10 21:36:43 2024 +0200

    Log track exceptions in the audio handler (jagrosh#1558)

commit 48e62f1
Author: Michaili K <[email protected]>
Date:   Fri May 10 21:32:30 2024 +0200

    Revert "Always self-deafen (jagrosh#1491)" (jagrosh#1551)

    This reverts commit a7807b9.

commit 6f12c33
Author: John Grosh <[email protected]>
Date:   Fri May 10 15:23:30 2024 -0400

    custom eval engine (jagrosh#1530)

commit 0afb3db
Author: Michaili K <[email protected]>
Date:   Fri May 10 20:19:11 2024 +0200

    Switch to lavalink's new YouTube audio source manager (jagrosh#1552)

    * Switch to new lavalink's new YouTube audio source manager

    * Add back setPlaylistPageCount call for the youtube audio source manager

    * Manually add all the individual audio sources EXCEPT for old youtube

    * Remove unused import

    * Upgrade lavaplayer-youtube-source to 1.0.3

    * Upgrade lavaplayer-youtube-source to 1.0.4

commit 81322ef
Author: Michaili K <[email protected]>
Date:   Fri May 10 20:14:28 2024 +0200

    Add seek command (supersedes jagrosh#344) (jagrosh#674)

    * Add seek command

    * Combine nested if statements

    * Put the seek command in correct place to keep alphabetical order

    * Add license header

    * Brackets on next line

    * Restructure if-statements

    * Check for permissions with DJCommand#checkDJPermission

    * Make regex slightly smaller

    * Optimize imports

    * Output length of current track if requested seek time is invalid

    * Restate seeked point when seeked successfully

    * Add empty newline at end of file to keep consistency

    * Create TimeUtil class for parsing and formatting time

    * Move FormatUtil#formatTime to TimeUtil, and refactor

    * Apply requested changes (Pass 2)

    * Seek based on current position in track

    * Apply requested changes (Pass 3)

    * Add javadoc param

    * Apply requested changes (Pass 4)

    * Fix merge

    * Avoid reassigning parameter (Codacy)

    * Rework timestamp parsing

    * Refactor timestamp parsing

    * Apply requested changes (Pass 5)

    * Add examples in help

    * Apply requested changes (Pass 6)

    * Fix missing import

    * Keep track of start timestamp & add "unit" times

    * Fix my abdominal merge with QueuedTrack

    * Use RequestMetadata to store start timestamp

    * Store request info in request metadata

    * Add regex to try getting a timestamp from the url

    * Require RequestMetadata for QueuedTracks

    * Add some unit tests for unit seeking

    * Add docs & examples

    ---------

    Co-authored-by: Whew., Inc <[email protected]>
  • Loading branch information
DaniDipp committed Jul 13, 2024
1 parent 379430c commit d873d2f
Show file tree
Hide file tree
Showing 21 changed files with 516 additions and 109 deletions.
9 changes: 8 additions & 1 deletion .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,12 @@ body:
required: true
- label: I have searched for similar issues [on the issues page](https://github.com/jagrosh/MusicBot/issues?q=is%3Aissue)
required: true
- label: "I am running the latest version of the bot: ![Release](https://img.shields.io/github/release/jagrosh/MusicBot.svg)"
- label: I am using an official release from [the releases page](https://github.com/jagrosh/MusicBot/releases)
required: true
- type: input
id: version
attributes:
label: JMusicBot Version
description: Which version of JMusicBot are you running?
validations:
required: true
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
<url>https://m2.duncte123.dev/releases</url>
</repository>
<repository>
<id>arbjergDev-snapshots</id>
<id>arbjergDev</id>
<name>Lavalink Repository</name>
<url>https://maven.lavalink.dev/snapshots</url>
<url>https://maven.lavalink.dev/releases</url>
</repository>
</repositories>

Expand All @@ -57,7 +57,12 @@
<dependency>
<groupId>dev.arbjerg</groupId>
<artifactId>lavaplayer</artifactId>
<version>0eaeee195f0315b2617587aa3537fa202df07ddc-SNAPSHOT</version>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>dev.lavalink.youtube</groupId>
<artifactId>common</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.github.jagrosh</groupId>
Expand Down
20 changes: 17 additions & 3 deletions src/main/java/com/jagrosh/jmusicbot/BotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package com.jagrosh.jmusicbot;

import com.jagrosh.jmusicbot.entities.Prompt;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import com.jagrosh.jmusicbot.utils.OtherUtil;
import com.jagrosh.jmusicbot.utils.TimeUtil;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.typesafe.config.*;
import java.io.IOException;
Expand All @@ -40,9 +40,11 @@ public class BotConfig

private Path path = null;
private String token, prefix, altprefix, helpWord, playlistsFolder, logLevel,
successEmoji, warningEmoji, errorEmoji, loadingEmoji, searchingEmoji;
successEmoji, warningEmoji, errorEmoji, loadingEmoji, searchingEmoji,
evalEngine;
private boolean stayInChannel, songInGame, npImages, updatealerts, useEval, dbots;
private long owner, maxSeconds, aloneTimeUntilStop;
private int maxYTPlaylistPages;
private double skipratio;
private OnlineStatus status;
private Activity game;
Expand Down Expand Up @@ -88,7 +90,9 @@ public void load()
updatealerts = config.getBoolean("updatealerts");
logLevel = config.getString("loglevel");
useEval = config.getBoolean("eval");
evalEngine = config.getString("evalengine");
maxSeconds = config.getLong("maxtime");
maxYTPlaylistPages = config.getInt("maxytplaylistpages");
aloneTimeUntilStop = config.getLong("alonetimeuntilstop");
playlistsFolder = config.getString("playlistsfolder");
aliases = config.getConfig("aliases");
Expand Down Expand Up @@ -324,6 +328,11 @@ public boolean useEval()
return useEval;
}

public String getEvalEngine()
{
return evalEngine;
}

public boolean useNPImages()
{
return npImages;
Expand All @@ -334,9 +343,14 @@ public long getMaxSeconds()
return maxSeconds;
}

public int getMaxYTPlaylistPages()
{
return maxYTPlaylistPages;
}

public String getMaxTime()
{
return FormatUtil.formatTime(maxSeconds * 1000);
return TimeUtil.formatTime(maxSeconds * 1000);
}

public long getAloneTimeUntilStop()
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/jagrosh/jmusicbot/JMusicBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ private static CommandClient createCommandClient(BotConfig config, SettingsManag
new RemoveCmd(bot),
new SearchCmd(bot),
new SCSearchCmd(bot),
new SeekCmd(bot),
new ShuffleCmd(bot),
new SkipCmd(bot),
new TiliiCmd(bot),
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/jagrosh/jmusicbot/audio/AudioHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
import com.jagrosh.jmusicbot.playlist.PlaylistLoader.Playlist;
import com.jagrosh.jmusicbot.queue.AbstractQueue;
import com.jagrosh.jmusicbot.settings.QueueType;
import com.jagrosh.jmusicbot.utils.TimeUtil;
import com.jagrosh.jmusicbot.settings.RepeatMode;
import com.jagrosh.jmusicbot.utils.OtherUtil;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
Expand All @@ -39,6 +42,7 @@
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.User;
import org.slf4j.LoggerFactory;

/**
*
Expand All @@ -50,6 +54,7 @@ public class AudioHandler extends AudioEventAdapter implements AudioSendHandler
public final static String PAUSE_EMOJI = "\u23F8"; // ⏸
public final static String STOP_EMOJI = "\u23F9"; // ⏹


private final List<AudioTrack> defaultQueue = new LinkedList<>();
private final Set<String> votes = new HashSet<>();

Expand Down Expand Up @@ -197,6 +202,11 @@ public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason
}
}

@Override
public void onTrackException(AudioPlayer player, AudioTrack track, FriendlyException exception) {
LoggerFactory.getLogger("AudioHandler").error("Track " + track.getIdentifier() + " has failed to play", exception);
}

@Override
public void onTrackStart(AudioPlayer player, AudioTrack track)
{
Expand Down Expand Up @@ -246,7 +256,7 @@ public Message getNowPlaying(JDA jda)
double progress = (double)audioPlayer.getPlayingTrack().getPosition()/track.getDuration();
eb.setDescription(getStatusEmoji()
+ " "+FormatUtil.progressBar(progress)
+ " `[" + FormatUtil.formatTime(track.getPosition()) + "/" + FormatUtil.formatTime(track.getDuration()) + "]` "
+ " `[" + TimeUtil.formatTime(track.getPosition()) + "/" + TimeUtil.formatTime(track.getDuration()) + "]` "
+ FormatUtil.volumeIcon(audioPlayer.getVolume()));

return mb.setEmbeds(eb.build()).build();
Expand Down
28 changes: 25 additions & 3 deletions src/main/java/com/jagrosh/jmusicbot/audio/PlayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@

import com.dunctebot.sourcemanagers.DuncteBotSources;
import com.jagrosh.jmusicbot.Bot;
import com.sedmelluq.discord.lavaplayer.container.MediaContainerRegistry;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.bandcamp.BandcampAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.beam.BeamAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.getyarn.GetyarnAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.http.HttpAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.nico.NicoAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.soundcloud.SoundCloudAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.twitch.TwitchStreamAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.vimeo.VimeoAudioSourceManager;
import dev.lavalink.youtube.YoutubeAudioSourceManager;
import net.dv8tion.jda.api.entities.Guild;

/**
Expand All @@ -39,10 +48,23 @@ public PlayerManager(Bot bot)
public void init()
{
TransformativeAudioSourceManager.createTransforms(bot.getConfig().getTransforms()).forEach(t -> registerSourceManager(t));
AudioSourceManagers.registerRemoteSources(this);

YoutubeAudioSourceManager yt = new YoutubeAudioSourceManager(true);
yt.setPlaylistPageCount(bot.getConfig().getMaxYTPlaylistPages());
registerSourceManager(yt);

registerSourceManager(SoundCloudAudioSourceManager.createDefault());
registerSourceManager(new BandcampAudioSourceManager());
registerSourceManager(new VimeoAudioSourceManager());
registerSourceManager(new TwitchStreamAudioSourceManager());
registerSourceManager(new BeamAudioSourceManager());
registerSourceManager(new GetyarnAudioSourceManager());
registerSourceManager(new NicoAudioSourceManager());
registerSourceManager(new HttpAudioSourceManager(MediaContainerRegistry.DEFAULT_REGISTRY));

AudioSourceManagers.registerLocalSource(this);

DuncteBotSources.registerAll(this, "en-US");
source(YoutubeAudioSourceManager.class).setPlaylistPageCount(10);
}

public Bot getBot()
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/com/jagrosh/jmusicbot/audio/QueuedTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package com.jagrosh.jmusicbot.audio;

import com.jagrosh.jmusicbot.utils.TimeUtil;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import com.jagrosh.jmusicbot.queue.Queueable;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import net.dv8tion.jda.api.entities.User;

/**
Expand All @@ -28,33 +28,38 @@
public class QueuedTrack implements Queueable
{
private final AudioTrack track;

public QueuedTrack(AudioTrack track, User owner)
{
this(track, new RequestMetadata(owner));
}

private final RequestMetadata requestMetadata;

public QueuedTrack(AudioTrack track, RequestMetadata rm)
{
this.track = track;
this.track.setUserData(rm == null ? RequestMetadata.EMPTY : rm);

this.requestMetadata = rm;
if (this.track.isSeekable() && rm != null)
track.setPosition(rm.requestInfo.startTimestamp);
}

@Override
public long getIdentifier()
{
return track.getUserData() == null ? 0L : track.getUserData(RequestMetadata.class).getOwner();
return requestMetadata.getOwner();
}

public AudioTrack getTrack()
{
return track;
}

public RequestMetadata getRequestMetadata()
{
return requestMetadata;
}

@Override
public String toString()
{
String entry = "`[" + FormatUtil.formatTime(track.getDuration()) + "]` ";
String entry = "`[" + TimeUtil.formatTime(track.getDuration()) + "]` ";
AudioTrackInfo trackInfo = track.getInfo();
entry = entry + (trackInfo.uri.startsWith("http") ? "[**" + trackInfo.title + "**]("+trackInfo.uri+")" : "**" + trackInfo.title + "**");
return entry + " - <@" + track.getUserData(RequestMetadata.class).getOwner() + ">";
Expand Down
41 changes: 34 additions & 7 deletions src/main/java/com/jagrosh/jmusicbot/audio/RequestMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,67 @@
*/
package com.jagrosh.jmusicbot.audio;

import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.utils.TimeUtil;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import net.dv8tion.jda.api.entities.User;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
*
* @author John Grosh ([email protected])
*/
public class RequestMetadata
{
public static final RequestMetadata EMPTY = new RequestMetadata(null);
public static final RequestMetadata EMPTY = new RequestMetadata(null, null);

public final UserInfo user;
public final RequestInfo requestInfo;

public RequestMetadata(User user)
public RequestMetadata(User user, RequestInfo requestInfo)
{
this.user = user == null ? null : new UserInfo(user.getIdLong(), user.getName(), user.getDiscriminator(), user.getEffectiveAvatarUrl());
this.requestInfo = requestInfo;
}

public long getOwner()
{
return user == null ? 0L : user.id;
}

public static RequestMetadata fromResultHandler(AudioTrack track, CommandEvent event)
{
return new RequestMetadata(event.getAuthor(), new RequestInfo(event.getArgs(), track.getInfo().uri));
}

public class RequestInfo
public static class RequestInfo
{
public final String query, url;

private RequestInfo(String query, String url)
public final long startTimestamp;

public RequestInfo(String query, String url)
{
this(query, url, tryGetTimestamp(query));
}

private RequestInfo(String query, String url, long startTimestamp)
{
this.query = query;
this.url = url;
this.query = query;
this.startTimestamp = startTimestamp;
}

private static final Pattern youtubeTimestampPattern = Pattern.compile("youtu(?:\\.be|be\\..+)/.*\\?.*(?!.*list=)t=([\\dhms]+)");
private static long tryGetTimestamp(String url)
{
Matcher matcher = youtubeTimestampPattern.matcher(url);
return matcher.find() ? TimeUtil.parseUnitTime(matcher.group(1)) : 0;
}
}

public class UserInfo
public static class UserInfo
{
public final long id;
public final String username, discrim, avatar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package com.jagrosh.jmusicbot.audio;

import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.track.AudioItem;
import com.sedmelluq.discord.lavaplayer.track.AudioReference;
import com.typesafe.config.Config;
import dev.lavalink.youtube.YoutubeAudioSourceManager;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.audio.QueuedTrack;
import com.jagrosh.jmusicbot.audio.RequestMetadata;
import com.jagrosh.jmusicbot.commands.DJCommand;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import com.jagrosh.jmusicbot.utils.TimeUtil;
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
Expand Down Expand Up @@ -79,13 +81,13 @@ private void loadSingle(AudioTrack track)
if(bot.getConfig().isTooLong(track))
{
m.editMessage(FormatUtil.filter(event.getClient().getWarning()+" This track (**"+track.getInfo().title+"**) is longer than the allowed maximum: `"
+FormatUtil.formatTime(track.getDuration())+"` > `"+FormatUtil.formatTime(bot.getConfig().getMaxSeconds()*1000)+"`")).queue();
+ TimeUtil.formatTime(track.getDuration())+"` > `"+ TimeUtil.formatTime(bot.getConfig().getMaxSeconds()*1000)+"`")).queue();
return;
}
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
int pos = handler.addTrackToFront(new QueuedTrack(track, event.getAuthor()))+1;
int pos = handler.addTrackToFront(new QueuedTrack(track, RequestMetadata.fromResultHandler(track, event)))+1;
String addMsg = FormatUtil.filter(event.getClient().getSuccess()+" Added **"+track.getInfo().title
+"** (`"+FormatUtil.formatTime(track.getDuration())+"`) "+(pos==0?"to begin playing":" to the queue at position "+pos));
+"** (`"+ TimeUtil.formatTime(track.getDuration())+"`) "+(pos==0?"to begin playing":" to the queue at position "+pos));
m.editMessage(addMsg).queue();
}

Expand Down
Loading

0 comments on commit d873d2f

Please sign in to comment.