diff --git a/README.md b/README.md index 3ec4a89..a9686a8 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,9 @@ lavalink: plugins: jiosaavn: apiURL: "https://saavn.dev/api" # JioSaavn API URL + playlistTrackLimit: 50 # The maximum number of tracks to return from given playlist (default 50 tracks) + recommendationsTrackLimit: 20 # The maximum number of track to return from recommendations (default 20 tracks) + metrics: prometheus: enabled: false diff --git a/gradle.properties b/gradle.properties index a0ad737..d698dcb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=0.1.8 +version=0.1.9 diff --git a/main/src/main/java/com/github/appujet/jiosaavn/source/JioSaavnAudioSourceManager.java b/main/src/main/java/com/github/appujet/jiosaavn/source/JioSaavnAudioSourceManager.java index b029aa7..79aac82 100644 --- a/main/src/main/java/com/github/appujet/jiosaavn/source/JioSaavnAudioSourceManager.java +++ b/main/src/main/java/com/github/appujet/jiosaavn/source/JioSaavnAudioSourceManager.java @@ -26,14 +26,19 @@ public class JioSaavnAudioSourceManager extends ExtendedAudioSourceManager { private static final Pattern JIOSAAVN_REGEX = Pattern.compile("(https?://)(www\\.)?jiosaavn\\.com/(song|album|featured|artist|s/playlist)/([a-zA-Z0-9-_]+)(/([a-zA-Z0-9-_]+))?"); private static final Logger log = LoggerFactory.getLogger(JioSaavnAudioSourceManager.class); public static String BASE_API = null; + private final int playlistTrackLimit; + private final int recommendationsTrackLimit; public static final String SEARCH_PREFIX = "jssearch:"; public static final String RECOMMENDATIONS_PREFIX = "jsrec:"; - public JioSaavnAudioSourceManager(String apiURL) { + public JioSaavnAudioSourceManager(String apiURL, int playlistTrackLimit, int recommendationsTrackLimit) { if (apiURL == null || apiURL.isEmpty()) { throw new IllegalArgumentException("API URL must be provided"); } BASE_API = apiURL; + this.playlistTrackLimit = Math.abs(playlistTrackLimit); + this.recommendationsTrackLimit = Math.abs(recommendationsTrackLimit); + } @Override @@ -151,7 +156,7 @@ public AudioItem getAlbum(String identifier) { } public AudioItem getPlaylist(String identifier) { - final JsonBrowser json = this.fetchJson("/playlists?link=" + identifier); + final JsonBrowser json = this.fetchJson("/playlists?link=" + identifier + "&limit=" + playlistTrackLimit); if (json.isNull() || json.get("data").isNull()) { return AudioReference.NO_TRACK; } @@ -172,7 +177,7 @@ public AudioItem getPlaylist(String identifier) { } private AudioItem getArtist(String identifier) { - final JsonBrowser json = this.fetchJson("/artists?link=" + identifier); + final JsonBrowser json = this.fetchJson("/artists?link=" + identifier + "&songCount=50"); if (json.isNull() || json.get("data").isNull()) { return AudioReference.NO_TRACK; } @@ -193,7 +198,7 @@ private AudioItem getArtist(String identifier) { } public AudioItem getRecommendations(String identifier) { - final JsonBrowser json = this.fetchJson("/songs/" + identifier + "/suggestions?limit=10"); + final JsonBrowser json = this.fetchJson("/songs/" + identifier + "/suggestions?limit=" + recommendationsTrackLimit); if (json.isNull() || json.get("data").isNull()) { return AudioReference.NO_TRACK; } diff --git a/plugin/src/main/java/com/github/appujet/plugin/JioSaavnConfig.java b/plugin/src/main/java/com/github/appujet/plugin/JioSaavnConfig.java index f095482..9e6bb5c 100644 --- a/plugin/src/main/java/com/github/appujet/plugin/JioSaavnConfig.java +++ b/plugin/src/main/java/com/github/appujet/plugin/JioSaavnConfig.java @@ -7,6 +7,8 @@ @ConfigurationProperties(prefix = "plugins.jiosaavn") public class JioSaavnConfig { private String apiURL = null; + private int playlistTrackLimit = 50; // default value for playlist track limit + private int recommendationsTrackLimit = 20; // default value for recommendations public String getApiURL() { return apiURL; } @@ -14,4 +16,20 @@ public String getApiURL() { public void setApiURL(String apiURL) { this.apiURL = apiURL; } + + public int getPlaylistTrackLimit() { + return playlistTrackLimit; + } + public void setPlaylistTrackLimit(int playlistTrackLimit) { + this.playlistTrackLimit = playlistTrackLimit; + } + + public int getRecommendationsTrackLimit() { + return recommendationsTrackLimit; + } + + public void setRecommendationsTrackLimit(int recommendationsTrackLimit) { + this.recommendationsTrackLimit = recommendationsTrackLimit; + } + } \ No newline at end of file diff --git a/plugin/src/main/java/com/github/appujet/plugin/JiosaavnPlugin.java b/plugin/src/main/java/com/github/appujet/plugin/JiosaavnPlugin.java index 970abd1..fc0d440 100644 --- a/plugin/src/main/java/com/github/appujet/plugin/JiosaavnPlugin.java +++ b/plugin/src/main/java/com/github/appujet/plugin/JiosaavnPlugin.java @@ -20,7 +20,10 @@ public JiosaavnPlugin(JioSaavnConfig sourcesConfig) { log.info("Loaded JioSaavn plugin..."); this.sourcesConfig = sourcesConfig; if (this.sourcesConfig.getApiURL() != null) { - this.jioSaavn = new JioSaavnAudioSourceManager(this.sourcesConfig.getApiURL()); + this.jioSaavn = new JioSaavnAudioSourceManager( + this.sourcesConfig.getApiURL(), + this.sourcesConfig.getPlaylistTrackLimit(), + this.sourcesConfig.getRecommendationsTrackLimit()); } }