Skip to content

Commit

Permalink
update api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
appujet committed Oct 13, 2024
1 parent 45ab343 commit f525abc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ lavalink:
plugins:
jiosaavn:
apiURL: "https://jiosaavn-plugin-api.vercel.app" # JioSaavn API URL
apiURL: "https://jiosaavn-plugin-api.deno.dev" # JioSaavn API URL
playlistTrackLimit: 50 # The maximum number of tracks to return from given playlist (default 50 tracks)
recommendationsTrackLimit: 10 # The maximum number of track to return from recommendations (default 10 tracks)
Expand Down Expand Up @@ -108,10 +108,3 @@ logging:
## How to get API URL ?

- You can host the api locally using [this guide](https://github.com/appujet/jiosaavn-plugin-api)

- You can easily deploy your own instance of the API by clicking the button below:

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/appujet/jiosaavn-plugin-api)

> [!TIP]
> To ensure the API provides results in the intended language, configure the [Serverless Function Region](https://vercel.com/docs/concepts/functions/serverless-functions/regions) in Vercel to `Mumbai, India (South) - > bom1`.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.0.1
version=1.0.2
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -81,7 +83,8 @@ public AudioTrack decodeTrack(AudioTrackInfo audioTrackInfo, DataInput dataInput
}

private AudioItem getSearchResult(String query) throws IOException {
final JsonBrowser json = this.fetchJson("/api/search?q=" + query);
String encodedQuery = URLEncoder.encode(query, StandardCharsets.UTF_8);
final JsonBrowser json = this.fetchJson("/search?q=" + encodedQuery);

if (json.isNull()) {
return AudioReference.NO_TRACK;
Expand All @@ -105,7 +108,7 @@ private AudioItem getSearchResult(String query) throws IOException {
}

private AudioItem getTrack(String url) throws IOException {
final JsonBrowser json = this.fetchJson("/api/track?url=" + url);
final JsonBrowser json = this.fetchJson("/track?url=" + url);

if (json.isNull() || json.get("track").isNull()) {
return AudioReference.NO_TRACK;
Expand All @@ -115,7 +118,7 @@ private AudioItem getTrack(String url) throws IOException {
}

public AudioItem getAlbum(String url) {
final JsonBrowser json = this.fetchJson("/api/album?url=" + url);
final JsonBrowser json = this.fetchJson("/album?url=" + url);
if (json.isNull() || json.get("album").isNull()) {
return AudioReference.NO_TRACK;
}
Expand All @@ -138,7 +141,7 @@ public AudioItem getAlbum(String url) {

private AudioItem getArtist(String url) {

final JsonBrowser json = this.fetchJson("/api/artist?url=" + url);
final JsonBrowser json = this.fetchJson("/artist?url=" + url);
if (json.isNull() || json.get("artist").isNull()) {
return AudioReference.NO_TRACK;
}
Expand Down Expand Up @@ -167,7 +170,7 @@ private AudioItem getArtist(String url) {

public AudioItem getPlaylist(String identifier) {

final JsonBrowser json = this.fetchJson("/api/playlist?url=" + identifier + "&limit=" + playlistTrackLimit);
final JsonBrowser json = this.fetchJson("/playlist?url=" + identifier + "&limit=" + playlistTrackLimit);
if (json.isNull() || json.get("playlist").isNull()) {
return AudioReference.NO_TRACK;
}
Expand All @@ -191,7 +194,7 @@ public AudioItem getPlaylist(String identifier) {

public AudioItem getRecommendations(String identifier) {

final JsonBrowser json = this.fetchJson("/api/recommendations?id=" + identifier + "&limit=" + recommendationsTrackLimit);
final JsonBrowser json = this.fetchJson("/recommendations?id=" + identifier + "&limit=" + recommendationsTrackLimit);

if (json.isNull() || !json.get("tracks").isList()) {
return AudioReference.NO_TRACK;
Expand Down Expand Up @@ -222,9 +225,9 @@ private AudioTrack buildTrack(JsonBrowser data) {
final String title = cleanString(data.get("title").text());
final String id = data.get("identifier").text();
final String artwork = data.get("artworkUrl").text();
final long duration = data.get("duration").asLong(1);
final long duration = data.get("length").asLong(1);
final String url = data.get("uri").text();
final String artist = cleanString(data.get("artist").text());
final String artist = cleanString(data.get("author").text());

return new JioSaavnAudioTrack(
new AudioTrackInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public JioSaavnAudioTrack(AudioTrackInfo trackInfo, ExtendedAudioSourceManager m
@Override
public String getPlaybackUrl() {

var json = manager.fetchJson("/api/track?id=" + this.trackInfo.identifier);
var json = manager.fetchJson("/track?id=" + this.trackInfo.identifier);

if (json.isNull() || json.get("track").isNull()) {
log.debug("Invalid JSON response or no data found for identifier: {}", this.trackInfo.identifier);
Expand Down

0 comments on commit f525abc

Please sign in to comment.