diff --git a/changelog.md b/changelog.md index ac52d23..de30fde 100644 --- a/changelog.md +++ b/changelog.md @@ -1,2 +1,5 @@ +**Requires [pv-addon-lavaplayer-lib 1.0.11+](https://modrinth.com/plugin/pv-addon-lavaplayer-lib/version/1.0.11) to work** + Changelog: -- Fixed an issue where inserting a disc with shift-click caused it to start playing on 1.21 \ No newline at end of file +- Fixed an issue where inserting a disc with shift-click caused it to start playing on 1.21 +- Reintroduced YouTube authorization \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index e6f7fa3..00b62e8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ paperVersion=1.20.1-R0.1-SNAPSHOT foliaVersion=1.20.1-R0.1-SNAPSHOT plasmoVoiceVersion=2.0.3 -lavaplayerLibVersion=1.0.8 +lavaplayerLibVersion=1.0.11 # Version mavenGroup=su.plo.voice.discs diff --git a/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt b/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt index e944749..7932b97 100644 --- a/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt +++ b/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt @@ -109,6 +109,27 @@ class AddonConfig { @ConfigField val httpSource = HttpSourceConfig() + @Config + class YouTubeSourceConfig { + @ConfigField( + comment = """ + If you see a error like "Sign in to confirm you're not a bot", + you can try using YouTube oauth2 authorization. + + On the first start with authorization enabled, + you will see "OAUTH INTEGRATION" in your console. + Follow the instructions in this prompt. + If you do everything right, you will see "Token retrieved successfully" in your console. + You only need to do this once; + the token will be stored in "pv-addon-discs/.youtube-token" on plugin shutdown. + """ + ) + val useOauth2: Boolean = false + } + + @ConfigField + val youtubeSource = YouTubeSourceConfig() + @Config class BurnableTag { @ConfigField( diff --git a/src/main/kotlin/su/plo/voice/discs/DiscsPlugin.kt b/src/main/kotlin/su/plo/voice/discs/DiscsPlugin.kt index 4680872..7d6b308 100644 --- a/src/main/kotlin/su/plo/voice/discs/DiscsPlugin.kt +++ b/src/main/kotlin/su/plo/voice/discs/DiscsPlugin.kt @@ -66,7 +66,6 @@ class DiscsPlugin : JavaPlugin() { loadConfig() } - @EventSubscribe override fun onEnable() { loadConfig() @@ -100,6 +99,10 @@ class DiscsPlugin : JavaPlugin() { override fun onDisable() { PlasmoVoiceServer.getAddonsLoader().unload(this) + + if (::audioPlayerManager.isInitialized) { + audioPlayerManager.save() + } } private fun loadConfig() { diff --git a/src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt b/src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt index dd97746..5f8c811 100644 --- a/src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt +++ b/src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt @@ -18,6 +18,7 @@ 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.proto.packets.tcp.clientbound.SourceAudioEndPacket import su.plo.voice.proto.packets.udp.clientbound.SourceAudioPacket +import java.io.File import java.net.URI import java.util.concurrent.CompletableFuture import java.util.concurrent.TimeUnit @@ -34,6 +35,17 @@ class PlasmoAudioPlayerManager( registerSources() } + fun save() { + lavaPlayerManager.sourceManagers + .filterIsInstance() + .firstOrNull() + ?.takeIf { it.oauth2RefreshToken != null } + ?.let { + val refreshTokenFile = File(plugin.dataFolder, ".youtube-token") + refreshTokenFile.writeText(it.oauth2RefreshToken!!) + } + } + fun startTrackJob(track: AudioTrack, source: ServerStaticSource, distance: Short) = scope.launch { val player = lavaPlayerManager.createPlayer() @@ -136,7 +148,18 @@ class PlasmoAudioPlayerManager( } private fun registerSources() { - lavaPlayerManager.registerSourceManager(YoutubeAudioSourceManager(true)) + lavaPlayerManager.registerSourceManager( + YoutubeAudioSourceManager(true) + .also { source -> + if (plugin.addonConfig.youtubeSource.useOauth2) { + val refreshToken = File(plugin.dataFolder, ".youtube-token") + .takeIf { it.isFile && it.exists() } + ?.readText() + ?.trim() + source.useOauth2(refreshToken, false) + } + } + ) lavaPlayerManager.registerSourceManager(SoundCloudAudioSourceManager.createDefault()) lavaPlayerManager.registerSourceManager(BandcampAudioSourceManager()) lavaPlayerManager.registerSourceManager(VimeoAudioSourceManager())