From d580ac8c904873cb0623ab856b034211522d042d Mon Sep 17 00:00:00 2001 From: Apehum <36326454+Apehum@users.noreply.github.com> Date: Tue, 12 Nov 2024 22:39:25 +0800 Subject: [PATCH] feat: add poToken support --- .../kotlin/su/plo/voice/discs/AddonConfig.kt | 21 +++++++++++++++++++ .../voice/discs/PlasmoAudioPlayerManager.kt | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/core/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt b/core/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt index 5e9e6b8..4a38137 100644 --- a/core/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt +++ b/core/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt @@ -167,6 +167,18 @@ class AddonConfig { ) val useOauth2: Boolean = false + @ConfigField( + comment = """ + https://github.com/lavalink-devs/youtube-source?tab=readme-ov-file#using-a-potoken + """, + nullComment = """ + [youtube_source.po_token] + token = "paste your po_token here" + visitor_data = "paste your visitor_data here" + """ + ) + val poToken: PoToken? = null + @ConfigField( comment = """ You can check available clients here: https://github.com/lavalink-devs/youtube-source?tab=readme-ov-file#available-clients @@ -176,6 +188,15 @@ class AddonConfig { """ ) val clients: List? = null + + @Config + class PoToken { + @ConfigField + val token: String = "" + + @ConfigField + val visitorData: String = "" + } } @ConfigField diff --git a/core/src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt b/core/src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt index 2c84162..bc45a3e 100644 --- a/core/src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt +++ b/core/src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt @@ -29,6 +29,7 @@ import su.plo.voice.lavaplayer.libs.com.sedmelluq.discord.lavaplayer.track.Audio import su.plo.voice.lavaplayer.libs.com.sedmelluq.discord.lavaplayer.track.AudioTrack import su.plo.voice.lavaplayer.libs.com.sedmelluq.discord.lavaplayer.track.AudioTrackState import su.plo.voice.lavaplayer.libs.dev.lavalink.youtube.YoutubeAudioSourceManager +import su.plo.voice.lavaplayer.libs.dev.lavalink.youtube.clients.Web import su.plo.voice.lavaplayer.libs.org.apache.http.HttpHost import su.plo.voice.lavaplayer.libs.org.apache.http.auth.AuthScope import su.plo.voice.lavaplayer.libs.org.apache.http.auth.UsernamePasswordCredentials @@ -223,7 +224,10 @@ class PlasmoAudioPlayerManager : PluginKoinComponent { .also { source -> proxyHttpBuilder?.let { source.httpInterfaceManager.configureBuilder(it) } - if (config.youtubeSource.useOauth2) { + val poToken = config.youtubeSource.poToken + if (poToken != null) { + Web.setPoTokenAndVisitorData(poToken.token, poToken.visitorData) + } else if (config.youtubeSource.useOauth2) { val refreshToken = File(plugin.dataFolder, ".youtube-token") .takeIf { it.isFile && it.exists() } ?.readText()