Skip to content

Commit

Permalink
add option to disable resolving of artsits in track search results
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Aug 20, 2024
1 parent f4b0409 commit 81ed5d9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ plugins:
countryCode: "US" # the country code you want to use for filtering the artists top tracks. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
playlistLoadLimit: 6 # The number of pages at 100 tracks each
albumLoadLimit: 6 # The number of pages at 50 tracks each
resolveArtistsInSearch: true # Whether to resolve artists in track search results (can be slow)
localFiles: false # Enable local files support with Spotify playlists. Please note `uri` & `isrc` will be `null` & `identifier` will be `"local"`
applemusic:
countryCode: "US" # the country code you want to use for filtering the artists top tracks and language. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -60,6 +63,7 @@ public class SpotifySourceManager extends MirroringAudioSourceManager implements
private int playlistPageLimit = 6;
private int albumPageLimit = 6;
private boolean localFiles;
private boolean resolveArtistsInSearch = true;

private String spToken;
private Instant spTokenExpire;
Expand Down Expand Up @@ -104,6 +108,10 @@ public void setLocalFiles(boolean localFiles) {
this.localFiles = localFiles;
}

public void setResolveArtistsInSearch(boolean resolveArtistsInSearch) {
this.resolveArtistsInSearch = resolveArtistsInSearch;
}

@NotNull
@Override
public String getSourceName() {
Expand Down Expand Up @@ -343,13 +351,15 @@ public AudioItem getSearch(String query, boolean preview) throws IOException {
return AudioReference.NO_TRACK;
}

var artistIds = json.get("tracks").get("items").values().stream().map(track -> track.get("artists").index(0).get("id").text()).collect(Collectors.joining(","));
var artistJson = this.getJson(API_BASE + "artists?ids=" + artistIds);
if (artistJson != null) {
for (var artist : artistJson.get("artists").values()) {
for (var track : json.get("tracks").get("items").values()) {
if (track.get("artists").index(0).get("id").text().equals(artist.get("id").text())) {
track.get("artists").index(0).put("images", artist.get("images"));
if (this.resolveArtistsInSearch) {
var artistIds = json.get("tracks").get("items").values().stream().map(track -> track.get("artists").index(0).get("id").text()).collect(Collectors.joining(","));
var artistJson = this.getJson(API_BASE + "artists?ids=" + artistIds);
if (artistJson != null) {
for (var artist : artistJson.get("artists").values()) {
for (var track : json.get("tracks").get("items").values()) {
if (track.get("artists").index(0).get("id").text().equals(artist.get("id").text())) {
track.get("artists").index(0).put("images", artist.get("images"));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public LavaSrcPlugin(LavaSrcConfig pluginConfig, SourcesConfig sourcesConfig, Ly
if (spotifyConfig.getAlbumLoadLimit() > 0) {
this.spotify.setAlbumPageLimit(spotifyConfig.getAlbumLoadLimit());
}
if (!spotifyConfig.isResolveArtistsInSearch()) {
this.spotify.setResolveArtistsInSearch(spotifyConfig.isResolveArtistsInSearch());
}
if(spotifyConfig.isLocalFiles()) {
this.spotify.setLocalFiles(spotifyConfig.isLocalFiles());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class SpotifyConfig {
private String countryCode = "US";
private int playlistLoadLimit = 6;
private int albumLoadLimit = 6;
private boolean resolveArtistsInSearch = true;
private boolean localFiles = false;

public String getClientId() {
Expand Down Expand Up @@ -63,6 +64,14 @@ public void setAlbumLoadLimit(int albumLoadLimit) {
this.albumLoadLimit = albumLoadLimit;
}

public boolean isResolveArtistsInSearch() {
return this.resolveArtistsInSearch;
}

public void setResolveArtistsInSearch(boolean resolveArtistsInSearch) {
this.resolveArtistsInSearch = resolveArtistsInSearch;
}

public boolean isLocalFiles() {
return this.localFiles;
}
Expand Down

0 comments on commit 81ed5d9

Please sign in to comment.