Skip to content

Commit

Permalink
Play Command works on Spotify Playlist links
Browse files Browse the repository at this point in the history
  • Loading branch information
cmorley191 committed Feb 7, 2022
1 parent c404e92 commit 469c942
Show file tree
Hide file tree
Showing 8 changed files with 460 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/target/
/Playlists/
/test/
/maven/
*.json
*.txt
nb*.xml
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@

# JMusicBot

# cmorley191 Fork

## Extra Features
- Play command works on spotify playlist links (Playlist Settings -> Share -> Copy link to playlist)
- Does NOT work on single spotify song links (just play the title+artist, you lazy gamer)

## Setup
- Get the latest release at https://github.com/cmorley191/MusicBot/releases
- Or compile from source, see section below
- Setup a Spotify "application" at https://developer.spotify.com/dashboard
- This is incredibly straightforward. Name it whatever you want (hopefully something useful to you).
- Your spotify account will be linked as the "owner" of this application, but your private spotify account data won't be accessible by it AFAIK.
- Edit the config.txt created by JMusicBot to add the app's Client ID and Secret, or (if you haven't run the bot yet) let the startup prompts of the bot program guide you.

That's it. Do the other standard setup described on the main JMusicBot repo.

## Compiling from source
The main JMusicBot repo makes this sound way harder than it actually is, and doesn't provide instructions. Here they are:
- Clone this repo.
- Install the JDK (Java SE Development Kit), which allows you to compile java programs: https://www.oracle.com/java/technologies/downloads/
- Setup a JAVA_HOME environment variable with the path to where this is installed (e.g. C:\Program Files\Java\jdk1.8.0_201)
- Download maven - it's a zip: https://maven.apache.org/download.cgi
- Copy the extracted contents to a folder called "maven" in the top level of this repository. (so maven's "bin" folder should be at "MusicBot\maven\bin")
- Run "buildandrun.bat" in a command window, which essentially just runs "mvn compile && mvn package && java -jar MusicBot.jar".

Again, not sure why this was made to sound so difficult in the main repo.

# JMusicBot Readme:

[![Downloads](https://img.shields.io/github/downloads/jagrosh/MusicBot/total.svg)](https://github.com/jagrosh/MusicBot/releases/latest)
[![Stars](https://img.shields.io/github/stars/jagrosh/MusicBot.svg)](https://github.com/jagrosh/MusicBot/stargazers)
[![Release](https://img.shields.io/github/release/jagrosh/MusicBot.svg)](https://github.com/jagrosh/MusicBot/releases/latest)
Expand Down
1 change: 1 addition & 0 deletions buildandrun.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.\maven\bin\mvn compile && .\maven\bin\mvn package && java -Dnogui=true -jar .\target\JMusicBot-Snapshot-All.jar
15 changes: 15 additions & 0 deletions src/main/java/com/jagrosh/jmusicbot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.jagrosh.jmusicbot.audio.PlayerManager;
import com.jagrosh.jmusicbot.gui.GUI;
import com.jagrosh.jmusicbot.playlist.PlaylistLoader;
import com.jagrosh.jmusicbot.playlist.SpotifyAPI;
import com.jagrosh.jmusicbot.settings.SettingsManager;
import java.util.Objects;
import net.dv8tion.jda.api.JDA;
Expand All @@ -44,6 +45,7 @@ public class Bot
private final PlaylistLoader playlists;
private final NowplayingHandler nowplaying;
private final AloneInVoiceHandler aloneInVoiceHandler;
private final SpotifyAPI spotifyApi;

private boolean shuttingDown = false;
private JDA jda;
Expand All @@ -62,6 +64,14 @@ public Bot(EventWaiter waiter, BotConfig config, SettingsManager settings)
this.nowplaying.init();
this.aloneInVoiceHandler = new AloneInVoiceHandler(this);
this.aloneInVoiceHandler.init();
this.spotifyApi = new SpotifyAPI(config);
try {
this.spotifyApi.init();
} catch (Exception e) {
System.err.println("Exiting application due to error: ");
e.printStackTrace();
System.exit(1);
}
}

public BotConfig getConfig()
Expand Down Expand Up @@ -103,6 +113,11 @@ public AloneInVoiceHandler getAloneInVoiceHandler()
{
return aloneInVoiceHandler;
}

public SpotifyAPI getSpotifyAPI()
{
return spotifyApi;
}

public JDA getJDA()
{
Expand Down
56 changes: 55 additions & 1 deletion src/main/java/com/jagrosh/jmusicbot/BotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public class BotConfig

private Path path = null;
private String token, prefix, altprefix, helpWord, playlistsFolder,
successEmoji, warningEmoji, errorEmoji, loadingEmoji, searchingEmoji;
successEmoji, warningEmoji, errorEmoji, loadingEmoji, searchingEmoji,
spotifyClientId, spotifyClientSecret;
private boolean stayInChannel, songInGame, npImages, updatealerts, useEval, dbots;
private long owner, maxSeconds, aloneTimeUntilStop;
private OnlineStatus status;
Expand Down Expand Up @@ -86,6 +87,8 @@ public void load()
errorEmoji = config.getString("error");
loadingEmoji = config.getString("loading");
searchingEmoji = config.getString("searching");
spotifyClientId = config.getString("spotClient");
spotifyClientSecret = config.getString("spotSecret");
game = OtherUtil.parseGame(config.getString("game"));
status = OtherUtil.parseStatus(config.getString("status"));
stayInChannel = config.getBoolean("stayinchannel");
Expand Down Expand Up @@ -146,6 +149,47 @@ public void load()
write = true;
}
}

// validate spotify stuff
if(spotifyClientId==null || spotifyClientId.isEmpty() || spotifyClientId.equalsIgnoreCase("CLIENT_ID_HERE"))
{
spotifyClientId = prompt.prompt("Please provide a Spotify App Client ID."
+ "\nYou can create a spotify application, which provides access to the spotify API, at"
+ "\nhttps://developer.spotify.com/dashboard"
+ "\n(the spotify application will be associated to your account as the app owner, but it"
+ "\nwon't have access to your private spotify data)"
+ "\nThe bot needs the Client ID and Client Secret of the application you create."
+ "\nSpotify App Client ID: ");
if(spotifyClientId==null)
{
prompt.alert(Prompt.Level.WARNING, CONTEXT, "No Spotify Client ID provided! Exiting.\n\nConfig Location: " + path.toAbsolutePath().toString());
return;
}
else
{
write = true;
}
}

if(spotifyClientSecret==null || spotifyClientSecret.isEmpty() || spotifyClientSecret.equalsIgnoreCase("CLIENT_SECRET_HERE"))
{
spotifyClientSecret = prompt.prompt("Please provide a Spotify App Client Secret."
+ "\nYou can create a spotify application, which provides access to the spotify API, at"
+ "\nhttps://developer.spotify.com/dashboard"
+ "\n(the spotify application will be associated to your account as the app owner, but it"
+ "\nwon't have access to your private spotify data)"
+ "\nThe bot needs the Client ID and Client Secret of the application you create."
+ "\nSpotify App Client Secret: ");
if(spotifyClientSecret==null)
{
prompt.alert(Prompt.Level.WARNING, CONTEXT, "No Spotify Client Secret provided! Exiting.\n\nConfig Location: " + path.toAbsolutePath().toString());
return;
}
else
{
write = true;
}
}

if(write)
writeToFile();
Expand Down Expand Up @@ -240,6 +284,16 @@ public String getSearching()
{
return searchingEmoji;
}

public String getSpotClient()
{
return spotifyClientId;
}

public String getSpotSecret()
{
return spotifyClientSecret;
}

public Activity getGame()
{
Expand Down
Loading

0 comments on commit 469c942

Please sign in to comment.