Skip to content

Commit

Permalink
Merge pull request #3 from PandaIN95/master
Browse files Browse the repository at this point in the history
added configurable playlistTrackLimit && recommendationsTrackLimit
  • Loading branch information
appujet authored Oct 12, 2024
2 parents edcd970 + 97c790d commit 251c1aa
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.1.8
version=0.1.9
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
18 changes: 18 additions & 0 deletions plugin/src/main/java/com/github/appujet/plugin/JioSaavnConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,29 @@
@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;
}

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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down

0 comments on commit 251c1aa

Please sign in to comment.