Skip to content

Commit 3505236

Browse files
FineFindusdhanuarf
authored andcommitted
feat: generate content-bound poToken
YouTube switched to using content-bound poToken, i.e. the poToken is generated for each video using the video's ID. This fixes issues, where the server would respond with 403, as the previously generated poToken was no longer valid. Ref: FreeTubeApp/FreeTube#8137
1 parent 39c467a commit 3505236

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

app/src/main/java/com/github/libretube/api/poToken/PoTokenGenerator.kt

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class PoTokenGenerator : PoTokenProvider {
1919

2020
private object WebPoTokenGenLock
2121
private var webPoTokenVisitorData: String? = null
22-
private var webPoTokenStreamingPot: String? = null
2322
private var webPoTokenGenerator: PoTokenWebView? = null
2423

2524

@@ -37,10 +36,7 @@ class PoTokenGenerator : PoTokenProvider {
3736
* [PoTokenGenerator.getWebClientPoToken] was called
3837
*/
3938
private fun getWebClientPoToken(videoId: String, forceRecreate: Boolean): PoTokenResult {
40-
// just a helper class since Kotlin does not have builtin support for 4-tuples
41-
data class Quadruple<T1, T2, T3, T4>(val t1: T1, val t2: T2, val t3: T3, val t4: T4)
42-
43-
val (poTokenGenerator, visitorData, streamingPot, hasBeenRecreated) =
39+
val (poTokenGenerator, visitorData, hasBeenRecreated) =
4440
synchronized(WebPoTokenGenLock) {
4541
val shouldRecreate = webPoTokenGenerator == null || forceRecreate || webPoTokenGenerator!!.isExpired()
4642

@@ -66,22 +62,17 @@ class PoTokenGenerator : PoTokenProvider {
6662
// create a new webPoTokenGenerator
6763
webPoTokenGenerator = PoTokenWebView
6864
.newPoTokenGenerator(LibreTubeApp.instance)
69-
70-
// The streaming poToken needs to be generated exactly once before generating
71-
// any other (player) tokens.
72-
webPoTokenStreamingPot = webPoTokenGenerator!!.generatePoToken(webPoTokenVisitorData!!)
7365
}
7466
}
7567

76-
return@synchronized Quadruple(
68+
return@synchronized Triple(
7769
webPoTokenGenerator!!,
7870
webPoTokenVisitorData!!,
79-
webPoTokenStreamingPot!!,
8071
shouldRecreate
8172
)
8273
}
8374

84-
val playerPot = try {
75+
val poToken = try {
8576
// Not using synchronized here, since poTokenGenerator would be able to generate
8677
// multiple poTokens in parallel if needed. The only important thing is for exactly one
8778
// visitorData/streaming poToken to be generated before anything else.
@@ -105,13 +96,11 @@ class PoTokenGenerator : PoTokenProvider {
10596

10697
if (BuildConfig.DEBUG) {
10798
Log.d(
108-
TAG,
109-
"poToken for $videoId: playerPot=$playerPot, " +
110-
"streamingPot=$streamingPot, visitor_data=$visitorData"
99+
TAG, "poToken for $videoId: $poToken, visitor_data=$visitorData"
111100
)
112101
}
113102

114-
return PoTokenResult(visitorData, playerPot, streamingPot)
103+
return PoTokenResult(visitorData, poToken, poToken)
115104
}
116105

117106
override fun getWebEmbedClientPoToken(videoId: String?): PoTokenResult? = null

0 commit comments

Comments
 (0)