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

Merge #3

Merged
merged 11 commits into from
Jan 23, 2024
4 changes: 3 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
LAVALINK_MAVEN_USERNAME: ${{ secrets.LAVALINK_MAVEN_USERNAME }}
LAVALINK_MAVEN_PASSWORD: ${{ secrets.LAVALINK_MAVEN_PASSWORD }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -26,7 +28,7 @@ jobs:
uses: gradle/gradle-build-action@v2

- name: Build and Publish
run: ./gradlew build publish --no-daemon -PMAVEN_USERNAME=$MAVEN_USERNAME -PMAVEN_PASSWORD=$MAVEN_PASSWORD
run: ./gradlew build publish --no-daemon -PMAVEN_USERNAME=$MAVEN_USERNAME -PMAVEN_PASSWORD=$MAVEN_PASSWORD -PLAVALINK_MAVEN_USERNAME=$LAVALINK_MAVEN_USERNAME -PLAVALINK_MAVEN_PASSWORD=$LAVALINK_MAVEN_PASSWORD

- name: Upload main Artifact
uses: actions/upload-artifact@v3
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ dependencies {
```xml
<repositories>
<repository>
<id>TopiWTF-releases</id>
<name>Topis Maven Repo</name>
<url>https://maven.topi.wtf/releases</url>
</repository>
</repositories>
Expand All @@ -67,7 +69,7 @@ dependencies {
</dependency>
<dependency>
<groupId>com.github.topi314.lavasrc</groupId>
<artifactId>lavasrc-protocol</artifactId>
<artifactId>lavasrc-protocol-jvm</artifactId>
<version>x.y.z</version>
</dependency>
</dependencies>
Expand Down Expand Up @@ -177,17 +179,18 @@ This plugin requires Lavalink `v4` or greater
To install this plugin either download the latest release and place it into your `plugins` folder or add the following into your `application.yml`

> **Note**
> For a full `application.yml` example see [here](https://github.com/TopiSenpai/LavaSrc/blob/master/application.yml.example)
> For a full `application.yml` example see [here](application.example.yml)

Replace x.y.z with the latest version number
```yaml
lavalink:
plugins:
- dependency: "com.github.topi314.lavasrc:lavasrc-plugin:x.y.z"
repository: "https://maven.topi.wtf/releases"
repository: "https://maven.lavalink.dev/releases" # this is optional for lavalink v4.0.0-beta.5 or greater
snapshot: false # set to true if you want to use snapshot builds (see below)
```

Snapshot builds are available in https://maven.topi.wtf/snapshots with the short commit hash as the version
Snapshot builds are available in https://maven.lavalink.dev/snapshots with the short commit hash as the version

### Configuration

Expand Down
1 change: 0 additions & 1 deletion application.yml.example → application.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ server: # REST and WS server
lavalink:
plugins:
- dependency: "com.github.topi314.lavasrc:lavasrc-plugin:x.y.z"
repository: "https://maven.topi.wtf/releases"
server:
password: "youshallnotpass"
sources:
Expand Down
23 changes: 20 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def getGitVersion() {
}

var isMavenDefined = findProperty("MAVEN_USERNAME") != null && findProperty("MAVEN_PASSWORD") != null
var isLavalinkMavenDefined = findProperty("LAVALINK_MAVEN_USERNAME") != null && findProperty("LAVALINK_MAVEN_PASSWORD") != null

subprojects {
apply plugin: "java"
Expand All @@ -53,9 +54,10 @@ subprojects {
compileJava.options.encoding = "UTF-8"

publishing {
if (isMavenDefined) {
System.out.println("Publishing to Maven Repo")
repositories {
repositories {
if (isMavenDefined) {
System.out.println("Publishing to Maven Repo")

def snapshots = "https://maven.topi.wtf/snapshots"
def releases = "https://maven.topi.wtf/releases"

Expand All @@ -66,6 +68,21 @@ subprojects {
username = findProperty("MAVEN_USERNAME")
password = findProperty("MAVEN_PASSWORD")
}

}
}
if (isLavalinkMavenDefined && name == "plugin") {
System.out.println("Publishing to Lavalink Maven Repo")
def lavalinkSnapshots = "https://maven.lavalink.dev/snapshots"
def lavalinkReleases = "https://maven.lavalink.dev/releases"

maven {
name = "Reposilite-Lavalink"
url = isSnapshot ? lavalinkSnapshots : lavalinkReleases
credentials {
username = findProperty("LAVALINK_MAVEN_USERNAME")
password = findProperty("LAVALINK_MAVEN_PASSWORD")
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions main/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ java {
}

dependencies {
api "com.github.topi314.lavasearch:lavasearch:1.0.0-beta.2"
compileOnly "dev.arbjerg:lavaplayer:2.0.1"
api "com.github.topi314.lavasearch:lavasearch:1.0.0"
compileOnly "dev.arbjerg:lavaplayer:2.0.4"
implementation "org.jsoup:jsoup:1.15.3"
implementation "commons-io:commons-io:2.7"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public AudioSearchResult getSearchSuggestions(String query, Set<AudioSearchResul
}
}

return new BasicAudioSearchResult(tracks, playLists, albums, artists, terms);
return new BasicAudioSearchResult(tracks, albums, artists, playLists, terms);
}

public JsonBrowser getJson(String uri) throws IOException {
Expand Down Expand Up @@ -331,11 +331,11 @@ public AudioItem getAlbum(String id, String countryCode, boolean preview) throws
page = this.getJson(API_BASE + "catalog/" + countryCode + "/albums/" + id + "/tracks?limit=" + MAX_PAGE_ITEMS + "&offset=" + offset);
offset += MAX_PAGE_ITEMS;

page.values().forEach(tracksRaw::add);
page.get("data").values().forEach(tracksRaw::add);
}
while (page.get("next").text() != null && ++pages < albumPageLimit);

var tracks = parseTracks(tracksRaw, preview);
var tracks = parseTrackList(tracksRaw, preview);
if (tracks.isEmpty()) {
return AudioReference.NO_TRACK;
}
Expand Down Expand Up @@ -363,9 +363,7 @@ public AudioItem getPlaylist(String id, String countryCode, boolean preview) thr
}
while (page.get("next").text() != null && ++pages < playlistPageLimit);

var dataRaw = JsonBrowser.newMap();
dataRaw.put("data", tracksRaw);
var tracks = parseTracks(dataRaw, preview);
var tracks = parseTrackList(tracksRaw, preview);
if (tracks.isEmpty()) {
return AudioReference.NO_TRACK;
}
Expand Down Expand Up @@ -411,11 +409,22 @@ public AudioItem getSong(String id, String countryCode, boolean preview) throws
private List<AudioTrack> parseTracks(JsonBrowser json, boolean preview, Map<String, String> artistArtwork) {
var tracks = new ArrayList<AudioTrack>();
for (var value : json.get("data").values()) {
tracks.add(this.parseTrack(value, preview, artistArtwork.get(this.parseArtistId(value))));
var artistId = this.parseArtistId(value);
String artworkUrl = null;
if (artistId != null) {
artworkUrl = artistArtwork.get(artistId);
}
tracks.add(this.parseTrack(value, preview, artworkUrl));
}
return tracks;
}

private List<AudioTrack> parseTrackList(JsonBrowser json, boolean preview) throws IOException {
var jsonData = JsonBrowser.newMap();
jsonData.put("data", json);
return parseTracks(jsonData, preview);
}

private List<AudioTrack> parseTracks(JsonBrowser json, boolean preview) throws IOException {
var ids = json.get("data").values().stream().map(this::parseArtistId).filter(Predicate.not(Objects::isNull)).collect(Collectors.toList());
return parseTracks(json, preview, getArtistCover(ids));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
Expand All @@ -43,6 +44,7 @@ public class SpotifySourceManager extends MirroringAudioSourceManager implements
public static final String RECOMMENDATIONS_PREFIX = "sprec:";
public static final String PREVIEW_PREFIX = "spprev:";
public static final long PREVIEW_LENGTH = 30000;
public static final String SHARE_URL = "https://spotify.link/";
public static final int PLAYLIST_MAX_PAGE_ITEMS = 100;
public static final int ALBUM_MAX_PAGE_ITEMS = 50;
public static final String API_BASE = "https://api.spotify.com/v1/";
Expand Down Expand Up @@ -146,6 +148,21 @@ public AudioItem loadItem(String identifier, boolean preview) {
return this.getRecommendations(identifier.substring(RECOMMENDATIONS_PREFIX.length()).trim(), preview);
}

// If the identifier is a share URL, we need to follow the redirect to find out the real url behind it
if (identifier.startsWith(SHARE_URL)) {
var request = new HttpHead(identifier);
request.setConfig(RequestConfig.custom().setRedirectsEnabled(false).build());
try (var response = this.httpInterfaceManager.getInterface().execute(request)) {
if (response.getStatusLine().getStatusCode() == 307) {
var location = response.getFirstHeader("Location").getValue();
if (location.startsWith("https://open.spotify.com/")) {
return this.loadItem(location, preview);
}
}
return null;
}
}

var matcher = URL_PATTERN.matcher(identifier);
if (!matcher.find()) {
return null;
Expand Down
10 changes: 5 additions & 5 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
plugins {
id "dev.arbjerg.lavalink.gradle-plugin" version "1.0.14"
id "dev.arbjerg.lavalink.gradle-plugin" version "1.0.15"
}

archivesBaseName = "lavasrc-plugin"
lavalinkPlugin {
name = "lavasrc-plugin"
apiVersion = "4.0.0-beta.3"
serverVersion = "4.0.0-beta.3"
apiVersion = "4.0.0"
serverVersion = "4.0.0"
configurePublishing = false
}

Expand All @@ -15,8 +15,8 @@ targetCompatibility = JavaVersion.VERSION_17

dependencies {
implementation project(":main")
compileOnly "com.github.topi314.lavasearch:lavasearch:1.0.0-beta.2"
implementation "com.github.topi314.lavasearch:lavasearch-plugin-api:1.0.0-beta.2"
compileOnly "com.github.topi314.lavasearch:lavasearch:1.0.0"
implementation "com.github.topi314.lavasearch:lavasearch-plugin-api:1.0.0"
}

publishing {
Expand Down