Skip to content

Commit

Permalink
Throw cheap exception for disabled client options
Browse files Browse the repository at this point in the history
  • Loading branch information
devoxin committed Sep 26, 2024
1 parent 1ef9ebf commit 9360f15
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.lavalink.youtube;

public class OptionDisabledException extends RuntimeException {
public OptionDisabledException(String message) {
super(message, null, true, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.sedmelluq.discord.lavaplayer.tools.io.HttpClientTools;
import com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface;
import com.sedmelluq.discord.lavaplayer.track.*;
import dev.lavalink.youtube.OptionDisabledException;
import dev.lavalink.youtube.YoutubeAudioSourceManager;
import dev.lavalink.youtube.clients.ClientConfig;
import dev.lavalink.youtube.track.format.TrackFormats;
Expand Down Expand Up @@ -141,7 +142,7 @@ public AudioItem loadSearchMusic(@NotNull YoutubeAudioSourceManager source,
@NotNull String searchQuery) {
if (!getOptions().getSearching()) {
// why would you even disable searching for this client lol
throw new RuntimeException("Searching is disabled for this client");
throw new OptionDisabledException("Searching is disabled for this client");
}

JsonBrowser json = getMusicSearchResult(httpInterface, searchQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface;
import com.sedmelluq.discord.lavaplayer.track.*;
import dev.lavalink.youtube.CannotBeLoaded;
import dev.lavalink.youtube.OptionDisabledException;
import dev.lavalink.youtube.YoutubeAudioSourceManager;
import dev.lavalink.youtube.cipher.SignatureCipher;
import dev.lavalink.youtube.cipher.SignatureCipherManager;
import dev.lavalink.youtube.cipher.SignatureCipherManager.CachedPlayerScript;
import dev.lavalink.youtube.clients.ClientConfig;
import dev.lavalink.youtube.track.TemporalInfo;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
Expand Down Expand Up @@ -335,7 +335,7 @@ public AudioItem loadVideo(@NotNull YoutubeAudioSourceManager source,
@NotNull HttpInterface httpInterface,
@NotNull String videoId) throws CannotBeLoaded, IOException {
if (!getOptions().getVideoLoading()) {
throw new RuntimeException("Video loading is disabled for this client");
throw new OptionDisabledException("Video loading is disabled for this client");
}

JsonBrowser json = loadTrackInfoFromInnertube(source, httpInterface, videoId, null);
Expand All @@ -359,7 +359,7 @@ public AudioItem loadSearch(@NotNull YoutubeAudioSourceManager source,
@NotNull HttpInterface httpInterface,
@NotNull String searchQuery) {
if (!getOptions().getSearching()) {
throw new RuntimeException("Searching is disabled for this client");
throw new OptionDisabledException("Searching is disabled for this client");
}

JsonBrowser json = loadSearchResults(httpInterface, searchQuery);
Expand All @@ -378,7 +378,7 @@ public AudioItem loadMix(@NotNull YoutubeAudioSourceManager source,
@NotNull String mixId,
@Nullable String selectedVideoId) {
if (!getOptions().getPlaylistLoading()) {
throw new RuntimeException("Mix loading is disabled for this client");
throw new OptionDisabledException("Mix loading is disabled for this client");
}

JsonBrowser json = loadMixResult(httpInterface, mixId, selectedVideoId);
Expand Down Expand Up @@ -407,7 +407,7 @@ public AudioItem loadPlaylist(@NotNull YoutubeAudioSourceManager source,
@NotNull String playlistId,
@Nullable String selectedVideoId) {
if (!getOptions().getPlaylistLoading()) {
throw new RuntimeException("Playlist loading is disabled for this client");
throw new OptionDisabledException("Playlist loading is disabled for this client");
}

JsonBrowser json = loadPlaylistResult(httpInterface, playlistId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import dev.lavalink.youtube.CannotBeLoaded;
import dev.lavalink.youtube.OptionDisabledException;
import dev.lavalink.youtube.YoutubeAudioSourceManager;
import dev.lavalink.youtube.track.TemporalInfo;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -89,6 +90,10 @@ protected AudioTrack extractAudioTrack(@NotNull JsonBrowser json,
public AudioItem loadVideo(@NotNull YoutubeAudioSourceManager source,
@NotNull HttpInterface httpInterface,
@NotNull String videoId) throws CannotBeLoaded, IOException {
if (!getOptions().getVideoLoading()) {
throw new OptionDisabledException("Video loading is disabled for this client");
}

JsonBrowser json = loadTrackInfoFromInnertube(source, httpInterface, videoId, null);
JsonBrowser playabilityStatus = json.get("playabilityStatus");
JsonBrowser videoDetails = json.get("videoDetails");
Expand Down

0 comments on commit 9360f15

Please sign in to comment.