From 5f2c0ab958f72e148c56e15f12cd9193174037b9 Mon Sep 17 00:00:00 2001 From: Apehum Date: Sun, 21 Jul 2024 00:59:34 +0800 Subject: [PATCH] fix: set YoutubeOauth2Handler#enabled to true if refresh token is provided --- .../su/plo/voice/discs/PlasmoAudioPlayerManager.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt b/src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt index 5f8c811..ce30682 100644 --- a/src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt +++ b/src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt @@ -16,6 +16,7 @@ import su.plo.voice.lavaplayer.libs.com.sedmelluq.discord.lavaplayer.source.vime import su.plo.voice.lavaplayer.libs.com.sedmelluq.discord.lavaplayer.tools.FriendlyException import su.plo.voice.lavaplayer.libs.com.sedmelluq.discord.lavaplayer.track.* import su.plo.voice.lavaplayer.libs.dev.lavalink.youtube.YoutubeAudioSourceManager +import su.plo.voice.lavaplayer.libs.dev.lavalink.youtube.http.YoutubeOauth2Handler import su.plo.voice.proto.packets.tcp.clientbound.SourceAudioEndPacket import su.plo.voice.proto.packets.udp.clientbound.SourceAudioPacket import java.io.File @@ -157,6 +158,19 @@ class PlasmoAudioPlayerManager( ?.readText() ?.trim() source.useOauth2(refreshToken, false) + + if (refreshToken != null) { + // todo: token validation is not implemented yet, + // so for now I just forcibly set enabled to true in YoutubeOauth2Handler + + val oauth2HandlerField = YoutubeAudioSourceManager::class.java.getDeclaredField("oauth2Handler") + oauth2HandlerField.isAccessible = true + val oauth2Handler = oauth2HandlerField.get(source) as YoutubeOauth2Handler + + val enabledField = YoutubeOauth2Handler::class.java.getDeclaredField("enabled") + enabledField.isAccessible = true + enabledField.set(oauth2Handler, true) + } } } )