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

Feature: delegate track in json #73

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1dd7d6b
implement audio track & playlist custom json fields
topi314 Nov 28, 2022
38e36b8
use new plugin data appender interface
topi314 Nov 28, 2022
7e9226e
implement audio track & playlist custom json fields
topi314 Nov 28, 2022
d67912c
Merge branch 'master' into feature/custom-json-fields
topi314 Dec 17, 2022
0674522
Merge branch 'feature/custom-json-fields2' into feature/custom-json-f…
topi314 Dec 17, 2022
a0a5a35
update to lavalink v4 with plugin info modification
topi314 Dec 17, 2022
388bb37
Merge branch 'master' into feature/custom-json-fields
topi314 Dec 31, 2022
6bceb3e
Merge branch 'master' into feature/custom-json-fields
topi314 Jan 1, 2023
d51b619
Merge branch 'master' into feature/custom-json-fields
topi314 Jan 6, 2023
7bd20fd
cleanup playlist stuff
topi314 Jan 6, 2023
933c901
Merge branch 'master' into feature/custom-json-fields
topi314 Jan 13, 2023
a4a6700
rename artworkURL -> artworkUrl
topi314 Jan 14, 2023
538cf8f
update to lavalink repo
topi314 Feb 2, 2023
8073d35
Merge branch 'master' into feature/custom-json-fields
topi314 Apr 30, 2023
a7f5703
bleh
topi314 Apr 30, 2023
cfaea5e
Merge branch 'master' into feature/custom-json-fields
topi314 Apr 30, 2023
f1bc02e
fix plugin api version
topi314 Apr 30, 2023
85b39d1
Merge branch 'master' into feature/custom-json-fields
topi314 Apr 30, 2023
218199b
Merge branch 'master' into feature/custom-json-fields
topi314 May 22, 2023
d81d18f
update to latest lavalink
topi314 May 25, 2023
5afe4eb
add delegate track into track json
topi314 May 25, 2023
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
4 changes: 3 additions & 1 deletion main/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ plugins {
archivesBaseName = "lavasrc"

dependencies {
compileOnly "com.github.walkyst:lavaplayer-fork:1.3.98.4"
implementation 'org.jetbrains:annotations:24.0.0'
compileOnly "com.github.walkyst:lavaplayer-fork:ef075855da"
implementation "org.jsoup:jsoup:1.14.3"
implementation "commons-io:commons-io:2.6"
compileOnly "org.slf4j:slf4j-api:1.7.25"
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.github.topisenpai.lavasrc;

import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist;

import java.util.List;

public class ExtendedAudioPlaylist extends BasicAudioPlaylist {
private final String type;
private final String identifier;
private final String artworkURL;
private final String author;

public ExtendedAudioPlaylist(String name, List<AudioTrack> tracks, String type, String identifier, String artworkURL, String author) {
super(name, tracks, null, false);
this.type = type;
this.identifier = identifier;
this.artworkURL = artworkURL;
this.author = author;
}

public String getType() {
return type;
}

public String getIdentifier() {
return this.identifier;
}

public String getArtworkURL() {
return this.artworkURL;
}

public String getAuthor() {
return this.author;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.topisenpai.lavasrc.applemusic;

import com.github.topisenpai.lavasrc.ExtendedAudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;

import java.util.List;

public class AppleMusicAudioPlaylist extends ExtendedAudioPlaylist {

public AppleMusicAudioPlaylist(String name, List<AudioTrack> tracks, String type, String identifier, String artworkURL, String author) {
super(name, tracks, type, identifier, artworkURL, author);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

public class AppleMusicAudioTrack extends MirroringAudioTrack {

public AppleMusicAudioTrack(AudioTrackInfo trackInfo, String isrc, String artworkURL, AppleMusicSourceManager sourceManager) {
super(trackInfo, isrc, artworkURL, sourceManager);
public AppleMusicAudioTrack(AudioTrackInfo trackInfo, AppleMusicSourceManager sourceManager) {
super(trackInfo, sourceManager);
}

@Override
protected AudioTrack makeShallowClone() {
return new AppleMusicAudioTrack(this.trackInfo, this.isrc, this.artworkURL, (AppleMusicSourceManager) this.sourceManager);
return new AppleMusicAudioTrack(this.trackInfo, (AppleMusicSourceManager) this.sourceManager);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.github.topisenpai.lavasrc.mirror.MirroringAudioSourceManager;
import com.github.topisenpai.lavasrc.mirror.MirroringAudioTrackResolver;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.tools.DataFormatTools;
import com.sedmelluq.discord.lavaplayer.tools.JsonBrowser;
import com.sedmelluq.discord.lavaplayer.tools.io.HttpClientTools;
import com.sedmelluq.discord.lavaplayer.tools.io.HttpConfigurable;
Expand All @@ -23,6 +22,7 @@
import org.slf4j.LoggerFactory;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -83,12 +83,17 @@ public String getSourceName() {
}

@Override
public AudioTrack decodeTrack(AudioTrackInfo trackInfo, DataInput input) throws IOException {
return new AppleMusicAudioTrack(trackInfo,
DataFormatTools.readNullableText(input),
DataFormatTools.readNullableText(input),
this
);
public boolean isTrackEncodable(AudioTrack track) {
return true;
}

@Override
public void encodeTrack(AudioTrack track, DataOutput output) {
}

@Override
public AudioTrack decodeTrack(AudioTrackInfo trackInfo, DataInput input) {
return new AppleMusicAudioTrack(trackInfo, this);
}

@Override
Expand Down Expand Up @@ -210,7 +215,9 @@ public AudioItem getAlbum(String id, String countryCode) throws IOException {
return AudioReference.NO_TRACK;
}

return new BasicAudioPlaylist(json.get("data").index(0).get("attributes").get("name").text(), tracks, null, false);
var artworkUrl = this.parseArtworkUrl(json.get("data").index(0).get("attributes").get("artwork"));
var author = json.get("data").index(0).get("attributes").get("artistName").text();
return new AppleMusicAudioPlaylist(json.get("data").index(0).get("attributes").get("name").text(), tracks, "album", id, artworkUrl, author);
}

public AudioItem getPlaylist(String id, String countryCode) throws IOException {
Expand All @@ -235,15 +242,22 @@ public AudioItem getPlaylist(String id, String countryCode) throws IOException {
return AudioReference.NO_TRACK;
}

return new BasicAudioPlaylist(json.get("data").index(0).get("attributes").get("name").text(), tracks, null, false);
var artworkUrl = this.parseArtworkUrl(json.get("data").index(0).get("attributes").get("artwork"));
var author = json.get("data").index(0).get("attributes").get("curatorName").text();
return new AppleMusicAudioPlaylist(json.get("data").index(0).get("attributes").get("name").text(), tracks, "playlist", id, artworkUrl, author);
}

public AudioItem getArtist(String id, String countryCode) throws IOException {
var json = this.getJson(API_BASE + "catalog/" + countryCode + "/artists/" + id + "/view/top-songs");
if (json == null || json.get("data").values().isEmpty()) {
return AudioReference.NO_TRACK;
}
return new BasicAudioPlaylist(json.get("data").index(0).get("attributes").get("artistName").text() + "'s Top Tracks", parseTracks(json), null, false);

var jsonArtist = this.getJson(API_BASE + "catalog/" + countryCode + "/artists/" + id);

var artworkUrl = this.parseArtworkUrl(jsonArtist.get("data").index(0).get("attributes").get("artwork"));
var author = jsonArtist.get("data").index(0).get("attributes").get("name").text();
return new AppleMusicAudioPlaylist(author + "'s Top Tracks", parseTracks(json), "artist", id, artworkUrl, author);
}

public AudioItem getSong(String id, String countryCode) throws IOException {
Expand All @@ -264,22 +278,25 @@ private List<AudioTrack> parseTracks(JsonBrowser json) {

private AudioTrack parseTrack(JsonBrowser json) {
var attributes = json.get("attributes");
var artwork = attributes.get("artwork");
return new AppleMusicAudioTrack(
new AudioTrackInfo(
attributes.get("name").text(),
attributes.get("artistName").text(),
attributes.get("durationInMillis").asLong(0),
json.get("id").text(),
false,
attributes.get("url").text()
attributes.get("url").text(),
this.parseArtworkUrl(attributes.get("artwork")),
attributes.get("isrc").text()
),
attributes.get("isrc").text(),
artwork.get("url").text().replace("{w}", artwork.get("width").text()).replace("{h}", artwork.get("height").text()),
this
);
}

private String parseArtworkUrl(JsonBrowser json) {
return json.get("url").text().replace("{w}", json.get("width").text()).replace("{h}", json.get("height").text());
}

@Override
public void shutdown() {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.topisenpai.lavasrc.deezer;

import com.github.topisenpai.lavasrc.ExtendedAudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;

import java.util.List;

public class DeezerAudioPlaylist extends ExtendedAudioPlaylist {

public DeezerAudioPlaylist(String name, List<AudioTrack> tracks, String type, String identifier, String artworkURL, String author) {
super(name, tracks, type, identifier, artworkURL, author);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManager;
import com.sedmelluq.discord.lavaplayer.tools.DataFormatTools;
import com.sedmelluq.discord.lavaplayer.tools.JsonBrowser;
import com.sedmelluq.discord.lavaplayer.tools.io.HttpClientTools;
import com.sedmelluq.discord.lavaplayer.tools.io.HttpConfigurable;
Expand Down Expand Up @@ -130,15 +129,17 @@ private List<AudioTrack> parseTracks(JsonBrowser json) {

private AudioTrack parseTrack(JsonBrowser json) {
var id = json.get("id").text();
return new DeezerAudioTrack(new AudioTrackInfo(
json.get("title").text(),
json.get("artist").get("name").text(),
json.get("duration").as(Long.class) * 1000,
id,
false,
"https://deezer.com/track/" + id),
json.get("isrc").text(),
json.get("album").get("cover_xl").text(),
return new DeezerAudioTrack(
new AudioTrackInfo(
json.get("title").text(),
json.get("artist").get("name").text(),
json.get("duration").as(Long.class) * 1000,
id,
false,
"https://deezer.com/track/" + id,
json.get("album").get("cover_xl").text(),
json.get("isrc").text()
),
this
);
}
Expand Down Expand Up @@ -166,7 +167,10 @@ private AudioItem getAlbum(String id) throws IOException {
if (json == null || json.get("tracks").get("data").values().isEmpty()) {
return AudioReference.NO_TRACK;
}
return new BasicAudioPlaylist(json.get("title").text(), this.parseTracks(json.get("tracks")), null, false);

var artworkUrl = json.get("cover_xl").text();
var author = json.get("contributors").values().get(0).get("name").text();
return new DeezerAudioPlaylist(json.get("title").text(), this.parseTracks(json.get("tracks")), "album", id, artworkUrl, author);
}

private AudioItem getTrack(String id) throws IOException {
Expand All @@ -182,15 +186,21 @@ private AudioItem getPlaylist(String id) throws IOException {
if (json == null || json.get("tracks").get("data").values().isEmpty()) {
return AudioReference.NO_TRACK;
}
return new BasicAudioPlaylist(json.get("title").text(), this.parseTracks(json.get("tracks")), null, false);

var artworkUrl = json.get("picture_xl").text();
var author = json.get("creator").get("name").text();
return new DeezerAudioPlaylist(json.get("title").text(), this.parseTracks(json.get("tracks")), "playlist", id, artworkUrl, author);
}

private AudioItem getArtist(String id) throws IOException {
var json = this.getJson(PUBLIC_API_BASE + "/artist/" + id + "/top?limit=50");
if (json == null || json.get("data").values().isEmpty()) {
return AudioReference.NO_TRACK;
}
return new BasicAudioPlaylist(json.get("data").index(0).get("artist").get("name").text() + "'s Top Tracks", this.parseTracks(json), null, false);

var artworkUrl = json.get("data").index(0).get("contributors").get("picture_xl").text();
var author = json.get("data").index(0).get("contributors").get("name").text();
return new DeezerAudioPlaylist(author + "'s Top Tracks", this.parseTracks(json), "artist", id, artworkUrl, author);
}

@Override
Expand All @@ -199,19 +209,12 @@ public boolean isTrackEncodable(AudioTrack track) {
}

@Override
public void encodeTrack(AudioTrack track, DataOutput output) throws IOException {
var deezerAudioTrack = ((DeezerAudioTrack) track);
DataFormatTools.writeNullableText(output, deezerAudioTrack.getISRC());
DataFormatTools.writeNullableText(output, deezerAudioTrack.getArtworkURL());
public void encodeTrack(AudioTrack track, DataOutput output) {
}

@Override
public AudioTrack decodeTrack(AudioTrackInfo trackInfo, DataInput input) throws IOException {
return new DeezerAudioTrack(trackInfo,
DataFormatTools.readNullableText(input),
DataFormatTools.readNullableText(input),
this
);
public AudioTrack decodeTrack(AudioTrackInfo trackInfo, DataInput input) {
return new DeezerAudioTrack(trackInfo, this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,13 @@

public class DeezerAudioTrack extends DelegatedAudioTrack {

private final String isrc;
private final String artworkURL;
private final DeezerAudioSourceManager sourceManager;

public DeezerAudioTrack(AudioTrackInfo trackInfo, String isrc, String artworkURL, DeezerAudioSourceManager sourceManager) {
public DeezerAudioTrack(AudioTrackInfo trackInfo, DeezerAudioSourceManager sourceManager) {
super(trackInfo);
this.isrc = isrc;
this.artworkURL = artworkURL;
this.sourceManager = sourceManager;
}

public String getISRC() {
return this.isrc;
}

public String getArtworkURL() {
return this.artworkURL;
}

private URI getTrackMediaURI() throws IOException, URISyntaxException {
var getSessionID = new HttpPost(DeezerAudioSourceManager.PRIVATE_API_BASE + "?method=deezer.ping&input=3&api_version=1.0&api_token=");
var json = HttpClientTools.fetchResponseAsJson(this.sourceManager.getHttpInterface(), getSessionID);
Expand Down Expand Up @@ -101,7 +89,7 @@ public void process(LocalAudioTrackExecutor executor) throws Exception {

@Override
protected AudioTrack makeShallowClone() {
return new DeezerAudioTrack(this.trackInfo, this.isrc, this.artworkURL, this.sourceManager);
return new DeezerAudioTrack(this.trackInfo, this.sourceManager);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.sedmelluq.discord.lavaplayer.tools.io.ByteBufferInputStream;
import com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface;
import com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream;
import org.apache.http.HttpResponse;

import javax.crypto.BadPaddingException;
Expand Down
Loading