diff --git a/CHANGELOG.md b/CHANGELOG.md index ed758ffc..c250dfcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/main/src/main/java/com/sedmelluq/discord/lavaplayer/source/AudioSourceManagers.java b/main/src/main/java/com/sedmelluq/discord/lavaplayer/source/AudioSourceManagers.java index d4cca30d..8d997806 100644 --- a/main/src/main/java/com/sedmelluq/discord/lavaplayer/source/AudioSourceManagers.java +++ b/main/src/main/java/com/sedmelluq/discord/lavaplayer/source/AudioSourceManagers.java @@ -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. */ @@ -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... 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. *