diff --git a/playlet-lib/src/components/ContentNode/ProfileContentNode.xml b/playlet-lib/src/components/ContentNode/ProfileContentNode.xml
index e8d2e238..28494b6f 100644
--- a/playlet-lib/src/components/ContentNode/ProfileContentNode.xml
+++ b/playlet-lib/src/components/ContentNode/ProfileContentNode.xml
@@ -9,6 +9,7 @@
+
diff --git a/playlet-lib/src/components/Dialog/YouTubeLoginAccountItemUtils.bs b/playlet-lib/src/components/Dialog/YouTubeLoginAccountItemUtils.bs
index e7ff84f2..66853669 100644
--- a/playlet-lib/src/components/Dialog/YouTubeLoginAccountItemUtils.bs
+++ b/playlet-lib/src/components/Dialog/YouTubeLoginAccountItemUtils.bs
@@ -12,6 +12,7 @@ namespace YouTubeLoginAccountItemUtils
end if
profile.username = username
profile.activeIdentifyToken = accountItem.activeIdentifyToken
+ profile.selectActiveIdentityEndpoint = accountItem.selectActiveIdentityEndpoint
profile.thumbnail = accountItem.accountPhoto
profile.accessToken = accessToken.accessToken
profile.refreshToken = accessToken.refreshToken
diff --git a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs
index 97a0f4f7..210e56e9 100644
--- a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs
+++ b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs
@@ -28,6 +28,13 @@ namespace InnertubeService
accessToken = OptionUtils.Get(options, "accessToken")
raw = OptionUtils.GetOrDefault(options, "raw", false)
+ if not StringUtils.IsNullOrEmpty(accessToken)
+ profileNode = OptionUtils.Get(options, "profileNode")
+ if profileNode <> invalid
+ options["datasyncIdToken"] = GetProfileDatasyncIdToken(profileNode, accessToken, OptionUtils.Get(options, "profilesService"), cancellation)
+ end if
+ end if
+
nextRequest = invalid
if fetchNext
nextRequest = Innertube.CreateNextRequest({ "videoId": videoId }, options)
@@ -760,6 +767,39 @@ namespace InnertubeService
return Innertube.ListAccounts(accessToken, cancellation)
end function
+ function GetProfileDatasyncIdToken(profileNode as object, accessToken as string, profilesService as object, cancellation as object) as string
+ endpoint = profileNode.selectActiveIdentityEndpoint
+ if not IsAssociativeArray(endpoint) or endpoint.Count() = 0
+ endpoint = BackfillSelectActiveIdentityEndpoint(profileNode, accessToken, profilesService, cancellation)
+ end if
+ return Innertube.GetDatasyncIdToken(endpoint)
+ end function
+
+ function BackfillSelectActiveIdentityEndpoint(profileNode as object, accessToken as string, profilesService as object, cancellation as object) as object
+ LogInfo("Backfilling selectActiveIdentityEndpoint for signed-in profile")
+ accounts = Innertube.ListAccounts(accessToken, cancellation)
+ if not IsArray(accounts)
+ return invalid
+ end if
+
+ for each account in accounts
+ if account.activeIdentifyToken <> profileNode.activeIdentifyToken
+ continue for
+ end if
+ endpoint = account.selectActiveIdentityEndpoint
+ if IsAssociativeArray(endpoint) and endpoint.Count() > 0
+ profileNode.selectActiveIdentityEndpoint = endpoint
+ if profilesService <> invalid
+ profilesService@.SaveUserProfilesToRegistry()
+ end if
+ return endpoint
+ end if
+ exit for
+ end for
+
+ return invalid
+ end function
+
function GetDrmLicense(options as object) as dynamic
request = Innertube.CreateGetDrmLicenceRequest(options)
diff --git a/playlet-lib/src/components/Services/Innertube/OAuth.bs b/playlet-lib/src/components/Services/Innertube/OAuth.bs
index cb4cafa4..85bb02f5 100644
--- a/playlet-lib/src/components/Services/Innertube/OAuth.bs
+++ b/playlet-lib/src/components/Services/Innertube/OAuth.bs
@@ -248,6 +248,7 @@ namespace Innertube
"accountByline": ParseText(accountItem["accountByline"])
"channelHandle": ParseText(accountItem["channelHandle"])
"activeIdentifyToken": ParseAccountItemIdentityToken(accountItem)
+ "selectActiveIdentityEndpoint": ValidAssociativeArray(ObjectUtils.Dig(accountItem, ["serviceEndpoint", "selectActiveIdentityEndpoint"]))
}
parsedAccounts.Push(parsedAccount)
end for
@@ -297,6 +298,26 @@ namespace Innertube
return ""
end function
+ function GetDatasyncIdToken(selectActiveIdentityEndpoint as object) as string
+ supportedTokens = ObjectUtils.Dig(selectActiveIdentityEndpoint, ["supportedTokens"])
+ if not IsArray(supportedTokens)
+ return ""
+ end if
+
+ for each supportedToken in supportedTokens
+ if not IsAssociativeArray(supportedToken)
+ continue for
+ end if
+
+ datasyncIdToken = ObjectUtils.Dig(supportedToken, ["datasyncIdToken", "datasyncIdToken"])
+ if not StringUtils.IsNullOrEmpty(datasyncIdToken)
+ return datasyncIdToken
+ end if
+ end for
+
+ return ""
+ end function
+
function ToCamelCase(obj as object) as object
if not IsAssociativeArray(obj)
return obj
diff --git a/playlet-lib/src/components/Services/Innertube/PlayerEndpoint.bs b/playlet-lib/src/components/Services/Innertube/PlayerEndpoint.bs
index 07ab90e4..5fa8b6d1 100644
--- a/playlet-lib/src/components/Services/Innertube/PlayerEndpoint.bs
+++ b/playlet-lib/src/components/Services/Innertube/PlayerEndpoint.bs
@@ -14,6 +14,7 @@ namespace Innertube
cancellation = OptionUtils.Get(options, "cancellation")
visitorData = OptionUtils.Get(options, "visitorData")
accessToken = OptionUtils.Get(options, "accessToken")
+ datasyncIdToken = OptionUtils.Get(options, "datasyncIdToken")
cpn = InnertubeService.CreateClientPlaybackNonce()
useAccessToken = (client = Innertube.ClientType.Tv or client = Innertube.ClientType.TvDowngraded) and not StringUtils.IsNullOrEmpty(accessToken)
@@ -62,6 +63,8 @@ namespace Innertube
if not StringUtils.IsNullOrEmpty(visitorData) and not useAccessToken
request.Header("x-goog-visitor-id", visitorData)
request.poTokenIdentity = visitorData
+ else if useAccessToken and not StringUtils.IsNullOrEmpty(datasyncIdToken)
+ request.poTokenIdentity = datasyncIdToken
end if
request.signatureTimestamp = signatureTimestamp
@@ -547,6 +550,7 @@ namespace Innertube
if not StringUtils.IsNullOrEmpty(poTokenIdentity)
body["identity"] = poTokenIdentity
end if
+ LogDebug("decipher poToken identity:", poTokenIdentity)
request = HttpClient.PostJson(`${PLAYLET_SUPPORT_SERVER}/v2/decipher`, body)
request.Cancellation(cancellation)
diff --git a/playlet-lib/src/components/Services/ProfilesService/ProfilesService.bs b/playlet-lib/src/components/Services/ProfilesService/ProfilesService.bs
index 2b7c7310..d2b751a7 100644
--- a/playlet-lib/src/components/Services/ProfilesService/ProfilesService.bs
+++ b/playlet-lib/src/components/Services/ProfilesService/ProfilesService.bs
@@ -58,6 +58,7 @@ function LoadProfilesFromRegistry()
profileNode.accessToken = profile.accessToken
profileNode.activeIdentifyToken = profile.activeIdentifyToken
+ profileNode.selectActiveIdentityEndpoint = profile.selectActiveIdentityEndpoint
profileNode.refreshToken = profile.refreshToken
profileNode.scope = profile.scope
profileNode.tokenType = profile.tokenType
@@ -182,6 +183,7 @@ function GetProfilesDto(includeAccessToken as boolean) as object
profile["expiresTimestamp"] = profileNode.expiresTimestamp
profile["clientId"] = profileNode.clientId
profile["clientSecret"] = profileNode.clientSecret
+ profile["selectActiveIdentityEndpoint"] = ValidAssociativeArray(profileNode.selectActiveIdentityEndpoint)
end if
userProfiles.profiles.Push(profile)
diff --git a/playlet-lib/src/components/VideoPlayer/VideoContentJob.bs b/playlet-lib/src/components/VideoPlayer/VideoContentJob.bs
index 3207c5c6..95f8b888 100644
--- a/playlet-lib/src/components/VideoPlayer/VideoContentJob.bs
+++ b/playlet-lib/src/components/VideoPlayer/VideoContentJob.bs
@@ -13,6 +13,7 @@ function ExecuteJob() as void
preferencesNode = input.preferences
loungeServiceNode = input.loungeService
playletServerPort = input.playletServerPort
+ profilesService = input.profilesService
if JobIsCancelled()
JobCancel()
@@ -47,10 +48,12 @@ function ExecuteJob() as void
accessToken = invalid
onBehalfOfUser = invalid
+ profileNode = invalid
authToken = invidiousNode.authToken
if authToken <> invalid and authToken.profileNode <> invalid and authToken.profileNode.type = "youtube" and not StringUtils.IsNullOrEmpty(authToken.token)
accessToken = authToken.token
onBehalfOfUser = authToken.activeIdentifyToken
+ profileNode = authToken.profileNode
end if
metadata = InnertubeService.GetVideoMetadata(contentNode.videoId, {
@@ -59,6 +62,8 @@ function ExecuteJob() as void
"visitorData": visitorData.visitorData
"accessToken": accessToken
"onBehalfOfUser": onBehalfOfUser
+ "profileNode": profileNode
+ "profilesService": profilesService
})
if IsAssociativeArray(metadata)
contentNode.addFields({
diff --git a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs
index 6b10ef6b..de5ae8d4 100644
--- a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs
+++ b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs
@@ -187,6 +187,7 @@ function StartVideoContentJob(videoContentNode as object)
preferences: m.top.preferences
loungeService: m.top.loungeService
playletServerPort: m.top.webServer.port
+ profilesService: m.top.profilesService
}
m.videoContentJob = JobSystem.CreateCallback(OnVideoContentJobDone)
diff --git a/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml b/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml
index d988313f..27275bb6 100644
--- a/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml
+++ b/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml
@@ -10,6 +10,7 @@
+
diff --git a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs
index 1ca91bcb..0d8df1ac 100644
--- a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs
+++ b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs
@@ -1075,6 +1075,7 @@ function StartVideoContentJob(videoContentNode as object)
preferences: m.top.preferences
loungeService: m.top.loungeService
playletServerPort: m.top.webServer.port
+ profilesService: m.top.profilesService
}
m.videoContentJob = JobSystem.CreateCallback(OnVideoContentJobDone)
diff --git a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml
index 4232e682..cec14c96 100644
--- a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml
+++ b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml
@@ -24,6 +24,7 @@
+
diff --git a/playlet-lib/src/source/tests/Innertube/GetDatasyncIdToken.spec.bs b/playlet-lib/src/source/tests/Innertube/GetDatasyncIdToken.spec.bs
new file mode 100644
index 00000000..e34a8ad5
--- /dev/null
+++ b/playlet-lib/src/source/tests/Innertube/GetDatasyncIdToken.spec.bs
@@ -0,0 +1,54 @@
+import "pkg:/components/Services/Innertube/OAuth.bs"
+
+namespace Tests
+
+ @suite
+ class InnertubeGetDatasyncIdTokenTests extends Rooibos.BaseTestSuite
+
+ @describe("Innertube.GetDatasyncIdToken")
+
+ @it("returns the datasyncIdToken verbatim (brand account, both halves)")
+ function brandVerbatim()
+ endpoint = {
+ supportedTokens: [
+ { pageIdToken: { pageId: "100000000000000000001" } }
+ { datasyncIdToken: { datasyncIdToken: "100000000000000000001||200000000000000000002" } }
+ ]
+ }
+ m.assertEqual(Innertube.GetDatasyncIdToken(endpoint), "100000000000000000001||200000000000000000002")
+ end function
+
+ @it("returns the default-account token verbatim, keeping the empty second half")
+ function defaultEmptySecondHalf()
+ endpoint = {
+ supportedTokens: [
+ { datasyncIdToken: { datasyncIdToken: "300000000000000000003||" } }
+ ]
+ }
+ m.assertEqual(Innertube.GetDatasyncIdToken(endpoint), "300000000000000000003||")
+ end function
+
+ @it("returns empty string when no datasyncIdToken is present")
+ function noDatasyncToken()
+ endpoint = {
+ supportedTokens: [
+ { pageIdToken: { pageId: "400000000000000000004" } }
+ { accountStateToken: { obfuscatedGaiaId: "500000000000000000005" } }
+ ]
+ }
+ m.assertEqual(Innertube.GetDatasyncIdToken(endpoint), "")
+ end function
+
+ @it("returns empty string for an invalid endpoint")
+ function invalidEndpoint()
+ m.assertEqual(Innertube.GetDatasyncIdToken(invalid), "")
+ end function
+
+ @it("returns empty string for an endpoint without supportedTokens")
+ function emptyEndpoint()
+ m.assertEqual(Innertube.GetDatasyncIdToken({}), "")
+ end function
+
+ end class
+
+end namespace