use of se.michaelthelin.spotify.model_objects.specification.Track in project spotifybot by NotEchoDE.
the class LastSongCommand method exec.
@Override
@SneakyThrows
public void exec(String userName, String id, UserLevel userLevel, String[] args) {
PagingCursorbased<PlayHistory> historyPagingCursorbased = getRoot().getSpotifyApi().getCurrentUsersRecentlyPlayedTracks().limit(1).build().execute();
String trackId = historyPagingCursorbased.getItems()[0].getTrack().getId();
Track track = getRoot().getSpotifyApi().getTrack(trackId).build().execute();
sendMessage(getModule().getEntry("lastSong"), "$USER", userName, "$LASTSONG", track.getName(), "$ARTISTS", SpotifyUtils.getArtists(track));
}
use of se.michaelthelin.spotify.model_objects.specification.Track in project spotifybot by NotEchoDE.
the class PlayCommand method exec.
@SneakyThrows
@Override
public void exec(String userName, String id, UserLevel userLevel, String[] args) {
ModuleEntry sPlay = getModule().getEntry("sPlay");
if (!userLevel.isHigherOrEquals(sPlay.getUserLevel())) {
sendMessage(getModule(ModuleType.SYSTEM).getEntry("noPerms"), "$USER", userName, "$ROLE", sPlay.getUserLevel().getPrettyName());
return;
}
if (args.length >= 1) {
StringBuilder searchQuery = new StringBuilder();
for (int i = 0; i < args.length; i++) if (i != 0)
searchQuery.append(" ");
else
searchQuery.append(args[i]);
Paging<Track> search = getRoot().getSpotifyApi().searchTracks(searchQuery.toString()).build().execute();
if (search.getTotal() == 0) {
sendMessage(getModule(ModuleType.SONGREQUEST).getEntry("notFound"), "$USER", userName);
return;
}
String uri = search.getItems()[0].getUri();
CountryCode country = getRoot().getSpotifyApi().getCurrentUsersProfile().build().execute().getCountry();
Track track = getRoot().getSpotifyApi().getTrack(uri.replace("spotify:track:", "")).build().execute();
if (Arrays.stream(track.getAvailableMarkets()).noneMatch(countryCode -> countryCode.equals(CountryCode.DE))) {
sendMessage(getModule(ModuleType.SONGREQUEST).getEntry("notAvailable"), "$USER", userName, "$SONG", track.getName());
return;
}
getRoot().getSpotifyApi().addItemToUsersPlaybackQueue(uri).build().execute();
getRoot().getSpotifyApi().skipUsersPlaybackToNextTrack().build().execute();
sendMessage(sPlay, "$USER", userName, "$SONG", track.getName());
return;
}
getRoot().getSpotifyApi().startResumeUsersPlayback().build().execute();
String uri = SpotifyUtils.getUriFromJson(getRoot().getSpotifyApi().getUsersCurrentlyPlayingTrack().build().getJson());
Track track = getRoot().getSpotifyApi().getTrack(SpotifyUtils.getIdFromUri(uri)).build().execute();
sendMessage(sPlay, "$USER", userName, "$SONG", track.getName(), "$ARTISTS", SpotifyUtils.getArtists(track));
}
use of se.michaelthelin.spotify.model_objects.specification.Track in project spotifybot by NotEchoDE.
the class SongrequestReward method exec.
@SneakyThrows
@Override
public void exec(RewardRedeemedEvent event, String userName, String id, String message) {
Paging<Track> search = getRoot().getSpotifyApi().searchTracks(message).build().execute();
if (search.getTotal() == 0) {
sendMessage(getModule().getEntry("notFound"), "$USER", userName);
setRedemptionStatus(event, RedemptionStatus.CANCELED);
return;
}
String uri = search.getItems()[0].getUri();
Track track = getRoot().getSpotifyApi().getTrack(uri.replace("spotify:track:", "")).build().execute();
if (Arrays.stream(track.getAvailableMarkets()).noneMatch(countryCode -> countryCode.equals(CountryCode.DE))) {
sendMessage(getModule(ModuleType.SONGREQUEST).getEntry("notAvailable"), "$USER", userName, "$SONG", track.getName());
setRedemptionStatus(event, RedemptionStatus.CANCELED);
return;
}
getRoot().getSpotifyApi().addItemToUsersPlaybackQueue(uri).build().execute();
sendMessage(getModule().getEntry("requested"), "$USER", userName, "$SONG", track.getName());
}
use of se.michaelthelin.spotify.model_objects.specification.Track in project aiode by robinfriedli.
the class SearchCommand method searchSpotifyTrack.
private void searchSpotifyTrack() throws Exception {
if (getCommandInput().isBlank()) {
throw new InvalidCommandException("No search term entered");
}
int limit = getArgumentValueWithTypeOrElse("select", Integer.class, 20);
Callable<List<Track>> loadTrackCallable = () -> getSpotifyService().searchTrack(getCommandInput(), argumentSet("own"), limit);
List<Track> found;
if (argumentSet("own")) {
found = runWithLogin(loadTrackCallable);
} else {
found = runWithCredentials(loadTrackCallable);
}
if (!found.isEmpty()) {
EmbedBuilder embedBuilder = new EmbedBuilder();
Util.appendEmbedList(embedBuilder, found, track -> track.getName() + " - " + track.getAlbum().getName() + " - " + StringList.create(track.getArtists(), ArtistSimplified::getName).toSeparatedString(", "), "Track - Album - Artist");
sendMessage(embedBuilder);
} else {
throw new NoSpotifyResultsFoundException(String.format("No Spotify track found for '%s'", getCommandInput()));
}
}
use of se.michaelthelin.spotify.model_objects.specification.Track in project aiode by robinfriedli.
the class AbstractPlayableLoadingCommand method loadTrack.
private void loadTrack(AudioManager audioManager) throws Exception {
int limit = getArgumentValueWithTypeOrElse("select", Integer.class, 20);
Callable<List<Track>> loadTrackCallable = () -> getSpotifyService().searchTrack(getCommandInput(), argumentSet("own"), limit);
List<Track> found;
if (argumentSet("own")) {
found = runWithLogin(loadTrackCallable);
} else {
found = runWithCredentials(loadTrackCallable);
}
if (found.size() == 1) {
createPlayableForTrack(found.get(0), audioManager);
} else if (found.isEmpty()) {
throw new NoSpotifyResultsFoundException(String.format("No Spotify track found for '%s'", getCommandInput()));
} else {
if (argumentSet("select")) {
askQuestion(found, track -> {
String artistString = StringList.create(track.getArtists(), ArtistSimplified::getName).toSeparatedString(", ");
return String.format("%s by %s", track.getName(), artistString);
}, track -> track.getAlbum().getName());
} else {
SpotifyTrackResultHandler resultHandler = new SpotifyTrackResultHandler(getContext().getGuild(), getContext().getSession());
createPlayableForTrack(resultHandler.getBestResult(getCommandInput(), found), audioManager);
}
}
}
Aggregations