Skip to content

Commit

Permalink
feat: add poToken support
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum committed Nov 12, 2024
1 parent 9d3217b commit d580ac8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
21 changes: 21 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 @@ -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
Expand All @@ -176,6 +188,15 @@ class AddonConfig {
"""
)
val clients: List<String>? = null

@Config
class PoToken {
@ConfigField
val token: String = ""

@ConfigField
val visitorData: String = ""
}
}

@ConfigField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d580ac8

Please sign in to comment.