Skip to content

Commit 4ff4242

Browse files
committed
cleanup
1 parent 3676296 commit 4ff4242

6 files changed

Lines changed: 51 additions & 65 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Adding support for the following sources:
1212
- soundgasm
1313
- streamDeckAudio files
1414
- These files are only accepted over HTTP currently
15+
- Pixelddrain.com
1516

1617
## Lavalink version compatibility
1718

@@ -67,6 +68,7 @@ plugins:
6768
tiktok: true # tiktok.com
6869
mixcloud: true # mixcloud.com
6970
soundgasm: true # soundgasm.net
71+
pixeldrain: true # pixeldrain.com
7072
```
7173
7274
## development

application.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ plugins:
4343
ocremix: true # www.ocremix.org
4444
tiktok: true # tiktok.com
4545
mixcloud: true # mixcloud.com
46+
pixeldrain: true # pixeldrain.com
4647

4748
metrics:
4849
prometheus:

plugin/src/main/java/com/dunctebot/lavalinkplugin/DuncteBotInjector.java

Lines changed: 34 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -18,81 +18,53 @@
1818
import org.slf4j.LoggerFactory;
1919
import org.springframework.stereotype.Service;
2020

21+
import java.util.Map;
2122
import java.util.Objects;
2223

24+
import static java.util.Map.entry;
25+
2326
@Service
2427
public class DuncteBotInjector implements AudioPlayerManagerConfiguration {
25-
private final DuncteBotConfig config;
26-
private final DuncteBotConfig.Sources sourcesConfig;
28+
private final Logger logger = LoggerFactory.getLogger(DuncteBotInjector.class);
29+
private final Map<String, SourceManagerInfo> sourceManagers;
2730

2831
public DuncteBotInjector(DuncteBotConfig config, DuncteBotConfig.Sources sourcesConfig) {
29-
this.config = config;
30-
this.sourcesConfig = sourcesConfig;
32+
33+
this.sourceManagers = Map.ofEntries(
34+
entry("yarn", new SourceManagerInfo(sourcesConfig::isGetyarn, GetyarnAudioSourceManager::new)),
35+
entry("clypit", new SourceManagerInfo(sourcesConfig::isClypit, ClypitAudioSourceManager::new)),
36+
entry("PornHub", new SourceManagerInfo(sourcesConfig::isPornhub, PornHubAudioSourceManager::new)),
37+
entry("Reddit", new SourceManagerInfo(sourcesConfig::isReddit, RedditAudioSourceManager::new)),
38+
entry("OC Remix", new SourceManagerInfo(sourcesConfig::isOcremix, OCRemixAudioSourceManager::new)),
39+
entry("TikTok", new SourceManagerInfo(sourcesConfig::isTiktok, TikTokAudioSourceManager::new)),
40+
entry("Mixcloud", new SourceManagerInfo(sourcesConfig::isMixcloud, MixcloudAudioSourceManager::new)),
41+
entry("Soundgasm", new SourceManagerInfo(sourcesConfig::isSoundgasm, SoundGasmAudioSourceManager::new)),
42+
entry("Elgato (.streamDeckAudio)", new SourceManagerInfo(sourcesConfig::isElgato, StreamDeckAudioSourceManager::new)),
43+
entry("pixeldrain", new SourceManagerInfo(sourcesConfig::isPixeldrain, PixeldrainAudioSourceManager::new)),
44+
entry("Text To Speech", new SourceManagerInfo(sourcesConfig::isTts, () -> {
45+
final String lang = Objects.requireNonNullElse(config.getTtsLanguage(), "en-AU");
46+
47+
logger.info("TTS language is: {}", lang);
48+
49+
return new SpeechAudioSourceManager(lang);
50+
}))
51+
);
3152
}
3253

3354
@NotNull
3455
@Override
3556
public AudioPlayerManager configure(@NotNull AudioPlayerManager manager) {
36-
final Logger logger = LoggerFactory.getLogger(DuncteBotInjector.class);
3757

3858
// register custom source managers
39-
40-
if (this.sourcesConfig.isGetyarn()) {
41-
logger.info("Registering getyarn audio source manager");
42-
manager.registerSourceManager(new GetyarnAudioSourceManager());
43-
}
44-
45-
if (this.sourcesConfig.isClypit()) {
46-
logger.info("Registering clypit audio source manager");
47-
manager.registerSourceManager(new ClypitAudioSourceManager());
48-
}
49-
50-
if (this.sourcesConfig.isTts()) {
51-
final String lang = Objects.requireNonNullElse(this.config.getTtsLanguage(), "en-AU");
52-
53-
logger.info("Registering text to speech audio source manager with language {}", lang);
54-
manager.registerSourceManager(new SpeechAudioSourceManager(lang));
55-
}
56-
57-
if (this.sourcesConfig.isPornhub()) {
58-
logger.info("Registering PornHub audio source manager");
59-
manager.registerSourceManager(new PornHubAudioSourceManager());
60-
}
61-
62-
if (this.sourcesConfig.isReddit()) {
63-
logger.info("Registering reddit audio source manager");
64-
manager.registerSourceManager(new RedditAudioSourceManager());
65-
}
66-
67-
if (this.sourcesConfig.isOcremix()) {
68-
logger.info("Registering OC Remix audio source manager");
69-
manager.registerSourceManager(new OCRemixAudioSourceManager());
70-
}
71-
72-
if (this.sourcesConfig.isTiktok()) {
73-
logger.info("Registering TikTok audio source manager");
74-
manager.registerSourceManager(new TikTokAudioSourceManager());
75-
}
76-
77-
if (this.sourcesConfig.isMixcloud()) {
78-
logger.info("Registering Mixcloud audio source manager");
79-
manager.registerSourceManager(new MixcloudAudioSourceManager());
80-
}
81-
82-
if (this.sourcesConfig.isSoundgasm()) {
83-
logger.info("Registering Soundgasm audio source manager");
84-
manager.registerSourceManager(new SoundGasmAudioSourceManager());
85-
}
86-
87-
if (this.sourcesConfig.isElgato()) {
88-
logger.warn("Elgato (.streamDeckAudio) audio source manager is not supported atm");
89-
// logger.info("Registering Elgato (.streamDeckAudio) audio source manager");
90-
// manager.registerSourceManager(new StreamDeckAudioSourceManager());
91-
}
92-
93-
if (this.sourcesConfig.isPixeldrain()) {
94-
logger.info("Registering pixeldrain audio source manager");
95-
manager.registerSourceManager(new PixeldrainAudioSourceManager());
59+
for (var entry : this.sourceManagers.entrySet()) {
60+
final var info = entry.getValue();
61+
62+
if (info.configSupplier().getAsBoolean()) {
63+
logger.info("Registering {} audio source manager", entry.getKey());
64+
manager.registerSourceManager(info.supplier().get());
65+
} else {
66+
logger.info("{} audio source manager is disabled, skipping it", entry.getKey());
67+
}
9668
}
9769

9870
return manager;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.dunctebot.lavalinkplugin;
2+
3+
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManager;
4+
5+
import java.util.function.BooleanSupplier;
6+
import java.util.function.Supplier;
7+
8+
public record SourceManagerInfo(BooleanSupplier configSupplier, Supplier<AudioSourceManager> supplier) {
9+
}

source-managers/src/main/java/com/dunctebot/sourcemanagers/pixeldrain/PixelDrainAudioTrack.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ protected InternalAudioTrack createAudioTrack(AudioTrackInfo trackInfo, Seekable
2121
public String getPlaybackUrl() {
2222
return String.format(PixeldrainAudioSourceManager.AUDIO_TEMPLATE, this.trackInfo.identifier);
2323
}
24+
25+
@Override
26+
public PixeldrainAudioSourceManager getSourceManager() {
27+
return (PixeldrainAudioSourceManager) super.getSourceManager();
28+
}
2429
}

source-managers/src/main/java/com/dunctebot/sourcemanagers/pixeldrain/PixeldrainAudioSourceManager.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ private AudioTrackInfo downloadInfo(String identifier) throws IOException {
7575
throw new FriendlyException("Type " + type + " is currently not supported", FriendlyException.Severity.COMMON, null);
7676
}
7777

78-
System.out.println(type);
79-
System.out.println(title);
80-
8178
return new AudioTrackInfo(
8279
title,
8380
"Unknown artist",

0 commit comments

Comments
 (0)