Skip to content

Commit

Permalink
whats luv
Browse files Browse the repository at this point in the history
  • Loading branch information
Nansess committed May 10, 2024
1 parent 832e797 commit cb1b884
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,18 @@ private AudioItem getAlbum(String id, boolean preview) throws IOException {
var artworkUrl = json.get("cover_xl").text();
var author = json.get("contributors").values().get(0).get("name").text();

for (var track : json.get("tracks").get("data").values()) {
track.get("artist").put("picture_xl", json.get("artist").get("picture_xl"));
var tracks = this.getJson(PUBLIC_API_BASE + "/album/" + id + "/tracks?limit=10000");
for (var track : tracks.get("data").values()) {
track.get("artist").put("picture_xl", json.get("artist").get("picture_xl"));
}

return new DeezerAudioPlaylist(json.get("title").text(), this.parseTracks(json.get("tracks"), preview), DeezerAudioPlaylist.Type.ALBUM, json.get("link").text(), artworkUrl, author, (int) json.get("nb_tracks").asLong(0));
return new DeezerAudioPlaylist(json.get("title").text(),
this.parseTracks(tracks, preview),
DeezerAudioPlaylist.Type.ALBUM,
json.get("link").text(),
artworkUrl,
author,
(int) json.get("nb_tracks").asLong(0)); // changes made from https://github.com/topi314/LavaSrc/commit/1ebc9ea05fc7d4affcb8730a5aafd8c29357b0fa
}

private AudioItem getTrack(String id, boolean preview) throws IOException {
Expand All @@ -308,9 +315,16 @@ private AudioItem getPlaylist(String id, boolean preview) throws IOException {
var artworkUrl = json.get("picture_xl").text();
var author = json.get("creator").get("name").text();

var tracks = this.getJson(PUBLIC_API_BASE + "/playlist/" + id + "/tracks");
// This endpoint returns tracks with ISRC, unlike the other REST call
var tracks = this.getJson(PUBLIC_API_BASE + "/playlist/" + id + "/tracks?limit=10000");

return new DeezerAudioPlaylist(json.get("title").text(), this.parseTracks(tracks, preview), DeezerAudioPlaylist.Type.PLAYLIST, json.get("link").text(), artworkUrl, author, (int) json.get("nb_tracks").asLong(0));
return new DeezerAudioPlaylist(json.get("title").text(),
this.parseTracks(tracks, preview),
DeezerAudioPlaylist.Type.PLAYLIST,
json.get("link").text(),
artworkUrl,
author,
(int) json.get("nb_tracks").asLong(0)); // another change made via https://github.com/topi314/LavaSrc/commit/a7dfa2957a0d8331c1f14692e726c46d9d697012
}

private AudioItem getArtist(String id, boolean preview) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,123 +235,65 @@ public AudioItem loadItem(String identifier, boolean preview) {
return null;
}

public void obtainAccessToken() throws IOException {
var accessTokenUrl =
"https://open.spotify.com/get_access_token?reason=transport&productType=embed";
var request = new HttpGet(accessTokenUrl);
public void obtainAccessToken() throws IOException {
var json = HttpClientTools.fetchResponseAsJson(
this.httpInterfaceManager.getInterface(),
request
this.httpInterfaceManager.getInterface(),
new HttpGet("https://open.spotify.com/get_access_token?reason=transport&productType=embed")
);

this.token = json.get("accessToken").text();
var expirationTimestampMs = json
.get("accessTokenExpirationTimestampMs")
.asLong(0);
this.tokenExpire = Instant.ofEpochMilli(expirationTimestampMs);
}
this.tokenExpire = Instant.ofEpochMilli(json.get("accessTokenExpirationTimestampMs").asLong(0));
}

public String getToken() throws IOException {
if (
this.token == null ||
this.tokenExpire == null ||
this.tokenExpire.isBefore(Instant.now())
) {
this.obtainAccessToken();
public String getToken() throws IOException {
if (this.token == null || this.tokenExpire == null || this.tokenExpire.isBefore(Instant.now())) {
obtainAccessToken();
}
return this.token;
}
}

public JsonBrowser getJson(String uri) throws IOException {
public JsonBrowser getJson(String uri) throws IOException {
var request = new HttpGet(uri);
request.addHeader("Authorization", "Bearer " + this.getToken());
return LavaSrcTools.fetchResponseAsJson(
this.httpInterfaceManager.getInterface(),
request
);
}
request.addHeader("Authorization", "Bearer " + getToken());
return LavaSrcTools.fetchResponseAsJson(this.httpInterfaceManager.getInterface(), request);
}

private AudioSearchResult getAutocomplete(
String query,
Set<AudioSearchResult.Type> types
) throws IOException {
private AudioSearchResult getAutocomplete(String query, Set<AudioSearchResult.Type> types) throws IOException {
if (types.contains(AudioSearchResult.Type.TEXT)) {
throw new IllegalArgumentException(
"text is not a valid search type for Spotify"
);
throw new IllegalArgumentException("text is not a valid search type for Spotify");
}
if (types.isEmpty()) {
types = SEARCH_TYPES;
types = SEARCH_TYPES;
}
var url =
API_BASE +
"search?q=" +
URLEncoder.encode(query, StandardCharsets.UTF_8) +
"&type=" +
types
.stream()
.map(AudioSearchResult.Type::getName)
.collect(Collectors.joining(","));
var json = this.getJson(url);
var url = API_BASE + "search?q=" + URLEncoder.encode(query, StandardCharsets.UTF_8) + "&type=" +
types.stream().map(AudioSearchResult.Type::getName).collect(Collectors.joining(","));
var json = getJson(url);
if (json == null) {
return AudioSearchResult.EMPTY;
return AudioSearchResult.EMPTY;
}

var albums = new ArrayList<AudioPlaylist>();
for (var album : json.get("albums").get("items").values()) {
albums.add(
new SpotifyAudioPlaylist(
album.get("name").text(),
Collections.emptyList(),
ExtendedAudioPlaylist.Type.ALBUM,
album.get("external_urls").get("spotify").text(),
album.get("images").index(0).get("url").text(),
album.get("artists").index(0).get("name").text(),
(int) album.get("total_tracks").asLong(0)
)
);
}
var tracks = parseTrackItems(json.get("tracks"), false);
var albums = parsePlaylistItems(json.get("albums"), ExtendedAudioPlaylist.Type.ALBUM);
var artists = parsePlaylistItems(json.get("artists"), ExtendedAudioPlaylist.Type.ARTIST);
var playlists = parsePlaylistItems(json.get("playlists"), ExtendedAudioPlaylist.Type.PLAYLIST);

var artists = new ArrayList<AudioPlaylist>();
for (var artist : json.get("artists").get("items").values()) {
artists.add(
new SpotifyAudioPlaylist(
artist.get("name").text() + "'s Top Tracks",
Collections.emptyList(),
ExtendedAudioPlaylist.Type.ARTIST,
artist.get("external_urls").get("spotify").text(),
artist.get("images").index(0).get("url").text(),
artist.get("name").text(),
null
)
);
}
return new BasicAudioSearchResult(tracks, albums, artists, playlists, new ArrayList<>());
}

private List<AudioPlaylist> parsePlaylistItems(JsonBrowser items, ExtendedAudioPlaylist.Type type) {
var playlists = new ArrayList<AudioPlaylist>();
for (var playlist : json.get("playlists").get("items").values()) {
playlists.add(
new SpotifyAudioPlaylist(
playlist.get("name").text(),
Collections.emptyList(),
ExtendedAudioPlaylist.Type.PLAYLIST,
playlist.get("external_urls").get("spotify").text(),
playlist.get("images").index(0).get("url").text(),
playlist.get("owner").get("display_name").text(),
(int) playlist.get("tracks").get("total").asLong(0)
)
);
for (var playlist : items.get("items").values()) {
playlists.add(new SpotifyAudioPlaylist(
playlist.get("name").text(),
Collections.emptyList(),
type,
playlist.get("external_urls").get("spotify").text(),
playlist.get("images").index(0).get("url").text(),
playlist.get("owner").get("display_name").text(),
type == ExtendedAudioPlaylist.Type.PLAYLIST ? (int) playlist.get("tracks").get("total").asLong(0) : null
));
}

var tracks = this.parseTrackItems(json.get("tracks"), false);

return new BasicAudioSearchResult(
tracks,
albums,
artists,
playlists,
new ArrayList<>()
);
}
return playlists;
}

public AudioItem getSearch(String query, boolean preview) throws IOException {
var json =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
public class DeezerConfig {

private String masterDecryptionKey;
private String format;

public String getFormat() {
return this.format;
}
private String arl;

public String getMasterDecryptionKey() {
return this.masterDecryptionKey;
}

public String getArl() {
return this.arl;
}

public void setMasterDecryptionKey(String masterDecryptionKey) {
this.masterDecryptionKey = masterDecryptionKey;
}

public void setFormat(String format) {
this.format = format;
public void setArl(String arl) {
this.arl = arl;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.github.topi314.lavasrc.flowerytts.FloweryTTSSourceManager;
import com.github.topi314.lavasrc.spotify.SpotifySourceManager;
import com.github.topi314.lavasrc.tidal.TidalSourceManager;
import com.github.topi314.lavasrc.pandora.PandoraSourceManager;
import com.github.topi314.lavasrc.yandexmusic.YandexMusicSourceManager;
import com.github.topi314.lavasrc.youtube.YoutubeSearchManager;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
Expand Down Expand Up @@ -35,7 +34,6 @@ public class LavaSrcPlugin
private FloweryTTSSourceManager flowerytts;
private YoutubeSearchManager youtube;
private TidalSourceManager tidal;
private PandoraSourceManager pandora;

public LavaSrcPlugin(
LavaSrcConfig pluginConfig,
Expand Down Expand Up @@ -91,9 +89,9 @@ public LavaSrcPlugin(
appleMusic.setAlbumPageLimit(appleMusicConfig.getAlbumLoadLimit());
}
}
if (sourcesConfig.isDeezer()) {
this.deezer = new DeezerAudioSourceManager(deezerConfig.getArl());
}
if (sourcesConfig.isDeezer()) {
this.deezer = new DeezerAudioSourceManager();
}
if (sourcesConfig.isYandexMusic()) {
this.yandexMusic =
new YandexMusicSourceManager(yandexMusicConfig.getAccessToken());
Expand Down Expand Up @@ -131,10 +129,6 @@ public AudioPlayerManager configure(@NotNull AudioPlayerManager manager) {
log.info("Registering Apple Music audio source manager...");
manager.registerSourceManager(this.appleMusic);
}
if (this.pandora != null) {
log.info("Registering Pandora audio source manager...");
manager.registerSourceManager(this.pandora);
}
if (this.deezer != null) {
log.info("Registering Deezer audio source manager...");
manager.registerSourceManager(this.deezer);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.github.topi314.lavasrc.plugin;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@ConfigurationProperties(prefix = "plugins.lavasrc.pandora")
@Component
public class PandoraConfig {

private static String countryCode;

public static String getCountryCode() {
return countryCode;
}

public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
}

0 comments on commit cb1b884

Please sign in to comment.