Skip to content

Commit 2d70c63

Browse files
committed
add new registerRemoteSources method with exclude arg
1 parent 3fdfd74 commit 2d70c63

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

main/src/main/java/com/sedmelluq/discord/lavaplayer/source/AudioSourceManagers.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import com.sedmelluq.discord.lavaplayer.source.vimeo.VimeoAudioSourceManager;
1313
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager;
1414

15+
import java.util.Set;
16+
1517
/**
1618
* A helper class for registering built-in source managers to a player manager.
1719
*/
@@ -50,6 +52,55 @@ public static void registerLocalSource(AudioPlayerManager playerManager) {
5052
registerLocalSource(playerManager, MediaContainerRegistry.DEFAULT_REGISTRY);
5153
}
5254

55+
/**
56+
* Registers all built-in remote audio sources to the specified player manager, excluding the specified sources.
57+
* Local file audio source must be registered separately.
58+
*
59+
* @param playerManager Player manager to register the source managers to
60+
* @param excludedSources Source managers to exclude from registration
61+
*/
62+
@SafeVarargs
63+
public static void registerRemoteSources(AudioPlayerManager playerManager, Class<? extends AudioSourceManager>... excludedSources) {
64+
registerRemoteSources(playerManager, MediaContainerRegistry.DEFAULT_REGISTRY, excludedSources);
65+
}
66+
67+
/**
68+
* Registers all built-in remote audio sources to the specified player manager, excluding the specified sources.
69+
* Local file audio source must be registered separately.
70+
*
71+
* @param playerManager Player manager to register the source managers to
72+
* @param containerRegistry Media container registry to be used by any probing sources.
73+
* @param excludedSources Source managers to exclude from registration
74+
*/
75+
@SafeVarargs
76+
public static void registerRemoteSources(AudioPlayerManager playerManager, MediaContainerRegistry containerRegistry, Class<? extends AudioSourceManager>... excludedSources) {
77+
Set<Class<? extends AudioSourceManager>> excluded = Set.of(excludedSources);
78+
if (!excluded.contains(YoutubeAudioSourceManager.class)) {
79+
playerManager.registerSourceManager(new YoutubeAudioSourceManager(true, null, null));
80+
}
81+
if (!excluded.contains(SoundCloudAudioSourceManager.class)) {
82+
playerManager.registerSourceManager(SoundCloudAudioSourceManager.createDefault());
83+
}
84+
if (!excluded.contains(BandcampAudioSourceManager.class)) {
85+
playerManager.registerSourceManager(new BandcampAudioSourceManager());
86+
}
87+
if (!excluded.contains(VimeoAudioSourceManager.class)) {
88+
playerManager.registerSourceManager(new VimeoAudioSourceManager());
89+
}
90+
if (!excluded.contains(TwitchStreamAudioSourceManager.class)) {
91+
playerManager.registerSourceManager(new TwitchStreamAudioSourceManager());
92+
}
93+
if (!excluded.contains(BeamAudioSourceManager.class)) {
94+
playerManager.registerSourceManager(new BeamAudioSourceManager());
95+
}
96+
if (!excluded.contains(GetyarnAudioSourceManager.class)) {
97+
playerManager.registerSourceManager(new GetyarnAudioSourceManager());
98+
}
99+
if (!excluded.contains(HttpAudioSourceManager.class)) {
100+
playerManager.registerSourceManager(new HttpAudioSourceManager(containerRegistry));
101+
}
102+
}
103+
53104
/**
54105
* Registers the local file source manager to the specified player manager.
55106
*

0 commit comments

Comments
 (0)