Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local File Support #206

Merged
merged 7 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,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
localFiles: false # Enable local files support with Spotify playlists.
clapann marked this conversation as resolved.
Show resolved Hide resolved
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
mediaAPIToken: "your apple music api token" # apple music api token
Expand Down Expand Up @@ -318,6 +319,7 @@ LavaSrc adds the following fields to tracks & playlists in Lavalink
* https://open.spotify.com/album/7qemUq4n71awwVPOaX7jw4
* https://open.spotify.com/playlist/7HAO9R9v203gkaPAgknOMp
clapann marked this conversation as resolved.
Show resolved Hide resolved
* https://open.spotify.com/artist/3ZztVuWxHzNpl0THurTFCv
* Local files (URI and ISRC are null, and ID is set to "local" for all local files)
clapann marked this conversation as resolved.
Show resolved Hide resolved

(including new regional links like https://open.spotify.com/intl-de/track/0eG08cBeKk0mzykKjw4hcQ)

Expand Down
2 changes: 1 addition & 1 deletion application.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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
localFiles: false # Enable local files support with Spotify playlists
localFiles: false # Enable local files support with Spotify playlists. (URI and ISRC are null, and ID is set to "local" for all local files)
clapann marked this conversation as resolved.
Show resolved Hide resolved
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
mediaAPIToken: "..." # apple music api token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ protected AudioTrack makeShallowClone() {
return new SpotifyAudioTrack(this.trackInfo, (SpotifySourceManager) this.sourceManager);
}

public boolean isLocal() {
return this.trackInfo.identifier.equals("local");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ private AudioTrack parseTrack(JsonBrowser json, boolean preview, boolean thisLoc
}

String name = json.get("name").text();
String artist = thisLocalFiles ? (json.get("artists").index(0).get("name").text() != null ? json.get("artists").index(0).get("name").text() : "unknown") : json.get("artists").index(0).get("name").text();
String id = thisLocalFiles ? (json.get("id").text() != null ? json.get("id").text() : "unknown") : json.get("id").text();
String artist = thisLocalFiles ? (json.get("artists").index(0).get("name").text() != null ? json.get("artists").index(0).get("name").text() : "local") : json.get("artists").index(0).get("name").text();
String id = thisLocalFiles ? (json.get("id").text() != null ? json.get("id").text() : "local") : json.get("id").text();

return new SpotifyAudioTrack(
new AudioTrackInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.topi314.lavasrc.ExtendedAudioPlaylist;
import com.github.topi314.lavasrc.ExtendedAudioTrack;
import com.github.topi314.lavasrc.spotify.SpotifyAudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import dev.arbjerg.lavalink.api.AudioPluginInfoModifier;
Expand All @@ -12,6 +13,7 @@
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.HashMap;

@Component
public class LavaSrcAudioPluginInfoModifier implements AudioPluginInfoModifier {
Expand All @@ -31,19 +33,24 @@ public JsonObject modifyAudioPlaylistPluginInfo(@NotNull AudioPlaylist playlist)
}

@Nullable
@Override
public JsonObject modifyAudioTrackPluginInfo(@NotNull AudioTrack track) {
if (track instanceof ExtendedAudioTrack extendedTrack) {
return new JsonObject(Map.of(
"albumName", JsonElementKt.JsonPrimitive(extendedTrack.getAlbumName()),
"albumUrl", JsonElementKt.JsonPrimitive(extendedTrack.getAlbumUrl()),
"artistUrl", JsonElementKt.JsonPrimitive(extendedTrack.getArtistUrl()),
"artistArtworkUrl", JsonElementKt.JsonPrimitive(extendedTrack.getArtistArtworkUrl()),
"previewUrl", JsonElementKt.JsonPrimitive(extendedTrack.getPreviewUrl()),
"isPreview", JsonElementKt.JsonPrimitive(extendedTrack.isPreview())
@Override
public JsonObject modifyAudioTrackPluginInfo(@NotNull AudioTrack track) {
if (track instanceof ExtendedAudioTrack extendedTrack) {
var json = new HashMap<>(Map.of(
"albumName", JsonElementKt.JsonPrimitive(extendedTrack.getAlbumName()),
"albumUrl", JsonElementKt.JsonPrimitive(extendedTrack.getAlbumUrl()),
"artistUrl", JsonElementKt.JsonPrimitive(extendedTrack.getArtistUrl()),
"artistArtworkUrl", JsonElementKt.JsonPrimitive(extendedTrack.getArtistArtworkUrl()),
"previewUrl", JsonElementKt.JsonPrimitive(extendedTrack.getPreviewUrl()),
"isPreview", JsonElementKt.JsonPrimitive(extendedTrack.isPreview())
));

));
}
return null;
}
if (track instanceof SpotifyAudioTrack spotifyTrack) {
json.put("isLocal", JsonElementKt.JsonPrimitive(spotifyTrack.isLocal()));
}

return new JsonObject(json);
}
return null;
}
}