Skip to content

Commit

Permalink
Add Spotify support
Browse files Browse the repository at this point in the history
Needs API credentials.
Only works with open.spotify.com**/intl/** urls
  • Loading branch information
ErdbeerbaerLP committed Jul 10, 2024
1 parent d9f94ae commit f4d24bc
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
<name>ErdbeerbaerLP Repository</name>
<url>https://repo.erdbeerbaerlp.de/repository/maven-public/</url>
</repository>
<repository>
<id>TopiWTF-releases</id>
<name>Topis Maven Repo</name>
<url>https://maven.topi.wtf/releases</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -124,6 +129,20 @@
<version>1.3</version>
<scope>test</scope>
</dependency>




<dependency>
<groupId>com.github.topi314.lavasrc</groupId>
<artifactId>lavasrc</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>com.github.topi314.lavasrc</groupId>
<artifactId>protocol-jvm</artifactId>
<version>4.1.1</version>
</dependency>
</dependencies>

<build>
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/com/jagrosh/jmusicbot/BotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public class BotConfig
private Config aliases, transforms;

private boolean valid = false;

private String sfClientSecret;
private String sfClientID;

public BotConfig(Prompt prompt)
{
this.prompt = prompt;
Expand Down Expand Up @@ -82,6 +84,8 @@ public void load()
errorEmoji = config.getString("error");
loadingEmoji = config.getString("loading");
searchingEmoji = config.getString("searching");
sfClientID = config.getString("spotifyclientid");
sfClientSecret = config.getString("spotifyclientsecret");
game = OtherUtil.parseGame(config.getString("game"));
status = OtherUtil.parseStatus(config.getString("status"));
stayInChannel = config.getBoolean("stayinchannel");
Expand Down Expand Up @@ -227,6 +231,14 @@ public String getPrefix()
{
return prefix;
}
public String getSpotifyClientID()
{
return sfClientID;
}
public String getSpotifyClientSecret()
{
return sfClientSecret;
}

public String getAltPrefix()
{
Expand All @@ -242,7 +254,7 @@ public double getSkipRatio()
{
return skipratio;
}

public long getOwnerId()
{
return owner;
Expand Down Expand Up @@ -292,7 +304,7 @@ public String getHelp()
{
return helpWord;
}

public boolean getStay()
{
return stayInChannel;
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/com/jagrosh/jmusicbot/audio/PlayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.jagrosh.jmusicbot.audio;

import com.dunctebot.sourcemanagers.DuncteBotSources;
import com.github.topi314.lavasrc.spotify.SpotifySourceManager;
import com.jagrosh.jmusicbot.Bot;
import com.sedmelluq.discord.lavaplayer.container.MediaContainerRegistry;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
Expand All @@ -39,12 +40,12 @@
public class PlayerManager extends DefaultAudioPlayerManager
{
private final Bot bot;

public PlayerManager(Bot bot)
{
this.bot = bot;
}

public void init()
{
TransformativeAudioSourceManager.createTransforms(bot.getConfig().getTransforms()).forEach(t -> registerSourceManager(t));
Expand All @@ -62,21 +63,24 @@ public void init()
registerSourceManager(new NicoAudioSourceManager());
registerSourceManager(new HttpAudioSourceManager(MediaContainerRegistry.DEFAULT_REGISTRY));

if (!bot.getConfig().getSpotifyClientID().isEmpty() && !bot.getConfig().getSpotifyClientSecret().isEmpty()) {
registerSourceManager(new SpotifySourceManager(null,bot.getConfig().getSpotifyClientID(),bot.getConfig().getSpotifyClientSecret(), "DE", this));
}
AudioSourceManagers.registerLocalSource(this);

DuncteBotSources.registerAll(this, "en-US");
}

public Bot getBot()
{
return bot;
}

public boolean hasHandler(Guild guild)
{
return guild.getAudioManager().getSendingHandler()!=null;
}

public AudioHandler setUpHandler(Guild guild)
{
AudioHandler handler;
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,8 @@ transforms = {}
eval=false
evalengine="Nashorn"

// If you intend to use Spotify, you can create an app on https://developer.spotify.com/dashboard and add your client id and secret here.
spotifyclientid = "";
spotifyclientsecret = "";

/// END OF JMUSICBOT CONFIG ///

0 comments on commit f4d24bc

Please sign in to comment.