Skip to content

Commit b09ee28

Browse files
Adjust android code to account for upstream changes
1 parent 0bb0f14 commit b09ee28

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

android/app/src/main/java/io/freetubeapp/freetube/javascript/FreeTubeJavaScriptInterface.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,28 +678,28 @@ class FreeTubeJavaScriptInterface {
678678

679679
// region Data Extraction
680680

681-
private fun getBotGuardScript(videoId: String, visitorData: String, sessionContext: String, includeDebugMessage: Boolean = true): String {
681+
private fun getBotGuardScript(videoId: String, sessionContext: String, includeDebugMessage: Boolean = true): String {
682682
val script = context.assets.readText("botGuardScript.js")
683683
val functionName = script.split("export{")[1].split(" as default};")[0]
684684
val exportSection = "export{${functionName} as default};"
685685
val then = if (includeDebugMessage) {
686-
"(TOKEN_RESULT) => { console.log(`Your potoken is \${JSON.stringify(TOKEN_RESULT)}`); Android.returnToken(JSON.stringify(TOKEN_RESULT)) }"
686+
"(TOKEN_RESULT) => { console.log(`Your potoken is \${TOKEN_RESULT}`); Android.returnToken(TOKEN_RESULT) }"
687687
} else {
688688
"(TOKEN_RESULT) => { Android.returnToken(TOKEN_RESULT) }"
689689
}
690690
val bakedScript =
691-
script.replace(exportSection, "; ${functionName}(\"$videoId\",\"$visitorData\", $sessionContext).then($then)")
691+
script.replace(exportSection, "; ${functionName}(\"$videoId\", $sessionContext).then($then)")
692692
return bakedScript
693693
}
694694

695695
@JavascriptInterface
696-
fun generatePOTokens(videoId: String, visitorData: String, sessionContext: String): String {
696+
fun generatePOToken(videoId: String, sessionContext: String): String {
697697
return Promise(context.threadPoolExecutor, {
698698
resolve,
699699
reject
700700
->
701701
try {
702-
val bgScript = getBotGuardScript(videoId, visitorData, sessionContext)
702+
val bgScript = getBotGuardScript(videoId, sessionContext)
703703
val bgWv = context.bgWebView
704704
context.bgJsInterface.onReturnToken {
705705
run {

src/renderer/helpers/android.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,9 @@ export function generatePOTokenFromVisitorData(visitorData) {
354354
return awaitAsyncResult(android.generatePOTokenFromVisitorData(visitorData))
355355
}
356356

357-
export async function generatePOTokens(videoId, visitorData, sessionContext) {
358-
const id = android.generatePOTokens(videoId, visitorData, sessionContext)
359-
const data = JSON.parse(await awaitAsyncResult(id))
360-
console.log(data)
361-
return data
357+
export async function generatePOToken(videoId, sessionContext) {
358+
const id = android.generatePOToken(videoId, sessionContext)
359+
return await awaitAsyncResult(id)
362360
}
363361

364362
export async function selectDataDirectory(copyFiles = false) {

src/renderer/helpers/api/local.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
getChannelPlaylistId,
1212
getRelativeTimeFromDate,
1313
} from '../utils'
14-
import { generatePOTokens, runDecipherScript } from '../android'
14+
import { generatePOToken, runDecipherScript } from '../android'
1515

1616
const TRACKING_PARAM_NAMES = [
1717
'utm_source',
@@ -316,13 +316,11 @@ export async function getLocalVideoInfo(id) {
316316
throw error
317317
}
318318
} else if (process.env.IS_ANDROID) {
319-
({ contentPoToken, sessionPoToken } = await generatePOTokens(
319+
contentPoToken = await generatePOToken(
320320
id,
321-
webInnertube.session.context.client.visitorData,
322321
JSON.stringify(webInnertube.session.context)
323-
))
324-
webInnertube.session.po_token = contentPoToken
325-
webInnertube.session.player.po_token = sessionPoToken
322+
)
323+
webInnertube.session.player.po_token = contentPoToken
326324
}
327325

328326
let clientName = webInnertube.session.context.client.clientName

0 commit comments

Comments
 (0)