Skip to content

Commit

Permalink
add new registerRemoteSources method with exclude arg
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed May 5, 2024
1 parent f3b6ede commit 54dcf84
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Improve handling of some MP3 files with multiple IDv3 blocks https://github.com/lavalink-devs/lavaplayer/pull/108
* Added basic metadata extraction for Matroska files https://github.com/lavalink-devs/lavaplayer/pull/108
* Bump `sourceCompatibility` specifically to Java 11 (Java 11 was already needed anyway) https://github.com/lavalink-devs/lavaplayer/pull/81
* Add new `AudioSourceManagers.registerRemoteSources` method which allows excluding specific source managers from being registered (useful for excluding the old YouTube source manager)

> [!WARNING]
> The `YoutubeSourceManager` is now deprecated and won't receive further updates. Please use https://github.com/lavalink-devs/youtube-source#v2 instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.sedmelluq.discord.lavaplayer.source.yamusic.YandexMusicAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager;

import java.util.Set;

/**
* A helper class for registering built-in source managers to a player manager.
*/
Expand Down Expand Up @@ -45,6 +47,49 @@ public static void registerRemoteSources(AudioPlayerManager playerManager, Media
playerManager.registerSourceManager(new HttpAudioSourceManager(containerRegistry));
}

/**
* Registers all built-in remote audio sources to the specified player manager, excluding the specified sources.
* Local file audio source must be registered separately.
*
* @param playerManager Player manager to register the source managers to
* @param containerRegistry Media container registry to be used by any probing sources.
* @param excludedSources Source managers to exclude from registration
*/
@SafeVarargs
public static void registerRemoteSources(AudioPlayerManager playerManager, MediaContainerRegistry containerRegistry, Class<? extends AudioSourceManager>... excludedSources) {
var excluded = Set.of(excludedSources);
if (!excluded.contains(YoutubeAudioSourceManager.class)) {
playerManager.registerSourceManager(new YoutubeAudioSourceManager(true, null, null));
}
if (!excluded.contains(YandexMusicAudioSourceManager.class)) {
playerManager.registerSourceManager(new YandexMusicAudioSourceManager(true));
}
if (!excluded.contains(SoundCloudAudioSourceManager.class)) {
playerManager.registerSourceManager(SoundCloudAudioSourceManager.createDefault());
}
if (!excluded.contains(BandcampAudioSourceManager.class)) {
playerManager.registerSourceManager(new BandcampAudioSourceManager());
}
if (!excluded.contains(VimeoAudioSourceManager.class)) {
playerManager.registerSourceManager(new VimeoAudioSourceManager());
}
if (!excluded.contains(TwitchStreamAudioSourceManager.class)) {
playerManager.registerSourceManager(new TwitchStreamAudioSourceManager());
}
if (!excluded.contains(BeamAudioSourceManager.class)) {
playerManager.registerSourceManager(new BeamAudioSourceManager());
}
if (!excluded.contains(GetyarnAudioSourceManager.class)) {
playerManager.registerSourceManager(new GetyarnAudioSourceManager());
}
if (!excluded.contains(NicoAudioSourceManager.class)) {
playerManager.registerSourceManager(new NicoAudioSourceManager());
}
if (!excluded.contains(HttpAudioSourceManager.class)) {
playerManager.registerSourceManager(new HttpAudioSourceManager(containerRegistry));
}
}

/**
* Registers the local file source manager to the specified player manager.
*
Expand Down

0 comments on commit 54dcf84

Please sign in to comment.