Skip to content

Commit

Permalink
feat: change default youtube clients and add them to config
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum committed Oct 12, 2024
1 parent 0f36ace commit 8b50de1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
10 changes: 10 additions & 0 deletions core/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ class AddonConfig {
"""
)
val useOauth2: Boolean = false

@ConfigField(
comment = """
You can check available clients here: https://github.com/lavalink-devs/youtube-source?tab=readme-ov-file#available-clients
""",
nullComment = """
clients = ["WEB", "ANDROID", "TVHTML5EMBEDDED", "MUSIC"]
"""
)
val clients: List<String>? = null
}

@ConfigField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import su.plo.voice.api.server.audio.provider.AudioFrameProvider
import su.plo.voice.api.server.audio.provider.AudioFrameResult
import su.plo.voice.api.server.audio.source.ServerProximitySource
import su.plo.voice.discs.utils.PluginKoinComponent
import su.plo.voice.discs.config.YoutubeClient
import su.plo.voice.lavaplayer.libs.com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler
import su.plo.voice.lavaplayer.libs.com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager
import su.plo.voice.lavaplayer.libs.com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager
Expand Down Expand Up @@ -197,8 +198,26 @@ class PlasmoAudioPlayerManager : PluginKoinComponent {
val proxyHttpBuilder = proxyHttpBuilder()
proxyHttpBuilder?.let { lavaPlayerManager.setHttpBuilderConfigurator(it) }

val youtubeClients = config.youtubeSource.clients
?.mapNotNull {
try {
// todo: config resolver don't support list of enums for some reason
YoutubeClient.valueOf(it)
} catch (e: IllegalArgumentException) {
null
}
}
?.takeIf { it.isNotEmpty() }
?: listOf(
YoutubeClient.WEB,
YoutubeClient.ANDROID,
YoutubeClient.TVHTML5EMBEDDED,
YoutubeClient.MUSIC
)
plugin.slF4JLogger.info("YouTube clients: {}", youtubeClients)

lavaPlayerManager.registerSourceManager(
YoutubeAudioSourceManager(true)
YoutubeAudioSourceManager(true, *youtubeClients.map { it.client }.toTypedArray())
.also { source ->
proxyHttpBuilder?.let { source.httpInterfaceManager.configureBuilder(it) }

Expand Down
28 changes: 28 additions & 0 deletions core/src/main/kotlin/su/plo/voice/discs/config/YoutubeClient.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package su.plo.voice.discs.config

import su.plo.voice.lavaplayer.libs.dev.lavalink.youtube.clients.Android
import su.plo.voice.lavaplayer.libs.dev.lavalink.youtube.clients.AndroidLite
import su.plo.voice.lavaplayer.libs.dev.lavalink.youtube.clients.AndroidMusic
import su.plo.voice.lavaplayer.libs.dev.lavalink.youtube.clients.AndroidTestsuite
import su.plo.voice.lavaplayer.libs.dev.lavalink.youtube.clients.Ios
import su.plo.voice.lavaplayer.libs.dev.lavalink.youtube.clients.MediaConnect
import su.plo.voice.lavaplayer.libs.dev.lavalink.youtube.clients.Music
import su.plo.voice.lavaplayer.libs.dev.lavalink.youtube.clients.TvHtml5Embedded
import su.plo.voice.lavaplayer.libs.dev.lavalink.youtube.clients.Web
import su.plo.voice.lavaplayer.libs.dev.lavalink.youtube.clients.WebEmbedded
import su.plo.voice.lavaplayer.libs.dev.lavalink.youtube.clients.skeleton.Client

enum class YoutubeClient(
val client: Client
) {
MUSIC(Music()),
WEB(Web()),
WEBEMBEDDED(WebEmbedded()),
ANDROID(Android()),
ANDROID_TESTSUITE(AndroidTestsuite()),
ANDROID_LITE(AndroidLite()),
ANDROID_MUSIC(AndroidMusic()),
MEDIA_CONNECT(MediaConnect()),
IOS(Ios()),
TVHTML5EMBEDDED(TvHtml5Embedded())
}

0 comments on commit 8b50de1

Please sign in to comment.