Use datasyncIdToken as poTokenIdentity

This commit is contained in:
Brahim Hadriche committed 2026-06-25 15:47:26 -04:00
1 parent 6a4a61b61f
commit 5e798f19de
12 files changed
+132

No files matched your search

@@ -9,6 +9,7 @@
<!-- Innertube fields --> <!-- Innertube fields -->
<field id="activeIdentifyToken" type="string" /> <field id="activeIdentifyToken" type="string" />
<field id="selectActiveIdentityEndpoint" type="assocarray" />
<field id="thumbnail" type="uri" /> <field id="thumbnail" type="uri" />
<field id="refreshToken" type="string" /> <field id="refreshToken" type="string" />
<field id="scope" type="string" /> <field id="scope" type="string" />
@@ -12,6 +12,7 @@ namespace YouTubeLoginAccountItemUtils
end if end if
profile.username = username profile.username = username
profile.activeIdentifyToken = accountItem.activeIdentifyToken profile.activeIdentifyToken = accountItem.activeIdentifyToken
profile.selectActiveIdentityEndpoint = accountItem.selectActiveIdentityEndpoint
profile.thumbnail = accountItem.accountPhoto profile.thumbnail = accountItem.accountPhoto
profile.accessToken = accessToken.accessToken profile.accessToken = accessToken.accessToken
profile.refreshToken = accessToken.refreshToken profile.refreshToken = accessToken.refreshToken
@@ -28,6 +28,13 @@ namespace InnertubeService
accessToken = OptionUtils.Get(options, "accessToken") accessToken = OptionUtils.Get(options, "accessToken")
raw = OptionUtils.GetOrDefault(options, "raw", false) 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 nextRequest = invalid
if fetchNext if fetchNext
nextRequest = Innertube.CreateNextRequest({ "videoId": videoId }, options) nextRequest = Innertube.CreateNextRequest({ "videoId": videoId }, options)
@@ -760,6 +767,39 @@ namespace InnertubeService
return Innertube.ListAccounts(accessToken, cancellation) return Innertube.ListAccounts(accessToken, cancellation)
end function 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 function GetDrmLicense(options as object) as dynamic
request = Innertube.CreateGetDrmLicenceRequest(options) request = Innertube.CreateGetDrmLicenceRequest(options)
@@ -248,6 +248,7 @@ namespace Innertube
"accountByline": ParseText(accountItem["accountByline"]) "accountByline": ParseText(accountItem["accountByline"])
"channelHandle": ParseText(accountItem["channelHandle"]) "channelHandle": ParseText(accountItem["channelHandle"])
"activeIdentifyToken": ParseAccountItemIdentityToken(accountItem) "activeIdentifyToken": ParseAccountItemIdentityToken(accountItem)
"selectActiveIdentityEndpoint": ValidAssociativeArray(ObjectUtils.Dig(accountItem, ["serviceEndpoint", "selectActiveIdentityEndpoint"]))
} }
parsedAccounts.Push(parsedAccount) parsedAccounts.Push(parsedAccount)
end for end for
@@ -297,6 +298,26 @@ namespace Innertube
return "" return ""
end function 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 function ToCamelCase(obj as object) as object
if not IsAssociativeArray(obj) if not IsAssociativeArray(obj)
return obj return obj
@@ -14,6 +14,7 @@ namespace Innertube
cancellation = OptionUtils.Get(options, "cancellation") cancellation = OptionUtils.Get(options, "cancellation")
visitorData = OptionUtils.Get(options, "visitorData") visitorData = OptionUtils.Get(options, "visitorData")
accessToken = OptionUtils.Get(options, "accessToken") accessToken = OptionUtils.Get(options, "accessToken")
datasyncIdToken = OptionUtils.Get(options, "datasyncIdToken")
cpn = InnertubeService.CreateClientPlaybackNonce() cpn = InnertubeService.CreateClientPlaybackNonce()
useAccessToken = (client = Innertube.ClientType.Tv or client = Innertube.ClientType.TvDowngraded) and not StringUtils.IsNullOrEmpty(accessToken) 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 if not StringUtils.IsNullOrEmpty(visitorData) and not useAccessToken
request.Header("x-goog-visitor-id", visitorData) request.Header("x-goog-visitor-id", visitorData)
request.poTokenIdentity = visitorData request.poTokenIdentity = visitorData
else if useAccessToken and not StringUtils.IsNullOrEmpty(datasyncIdToken)
request.poTokenIdentity = datasyncIdToken
end if end if
request.signatureTimestamp = signatureTimestamp request.signatureTimestamp = signatureTimestamp
@@ -547,6 +550,7 @@ namespace Innertube
if not StringUtils.IsNullOrEmpty(poTokenIdentity) if not StringUtils.IsNullOrEmpty(poTokenIdentity)
body["identity"] = poTokenIdentity body["identity"] = poTokenIdentity
end if end if
LogDebug("decipher poToken identity:", poTokenIdentity)
request = HttpClient.PostJson(`${PLAYLET_SUPPORT_SERVER}/v2/decipher`, body) request = HttpClient.PostJson(`${PLAYLET_SUPPORT_SERVER}/v2/decipher`, body)
request.Cancellation(cancellation) request.Cancellation(cancellation)
@@ -58,6 +58,7 @@ function LoadProfilesFromRegistry()
profileNode.accessToken = profile.accessToken profileNode.accessToken = profile.accessToken
profileNode.activeIdentifyToken = profile.activeIdentifyToken profileNode.activeIdentifyToken = profile.activeIdentifyToken
profileNode.selectActiveIdentityEndpoint = profile.selectActiveIdentityEndpoint
profileNode.refreshToken = profile.refreshToken profileNode.refreshToken = profile.refreshToken
profileNode.scope = profile.scope profileNode.scope = profile.scope
profileNode.tokenType = profile.tokenType profileNode.tokenType = profile.tokenType
@@ -182,6 +183,7 @@ function GetProfilesDto(includeAccessToken as boolean) as object
profile["expiresTimestamp"] = profileNode.expiresTimestamp profile["expiresTimestamp"] = profileNode.expiresTimestamp
profile["clientId"] = profileNode.clientId profile["clientId"] = profileNode.clientId
profile["clientSecret"] = profileNode.clientSecret profile["clientSecret"] = profileNode.clientSecret
profile["selectActiveIdentityEndpoint"] = ValidAssociativeArray(profileNode.selectActiveIdentityEndpoint)
end if end if
userProfiles.profiles.Push(profile) userProfiles.profiles.Push(profile)
@@ -13,6 +13,7 @@ function ExecuteJob() as void
preferencesNode = input.preferences preferencesNode = input.preferences
loungeServiceNode = input.loungeService loungeServiceNode = input.loungeService
playletServerPort = input.playletServerPort playletServerPort = input.playletServerPort
profilesService = input.profilesService
if JobIsCancelled() if JobIsCancelled()
JobCancel() JobCancel()
@@ -47,10 +48,12 @@ function ExecuteJob() as void
accessToken = invalid accessToken = invalid
onBehalfOfUser = invalid onBehalfOfUser = invalid
profileNode = invalid
authToken = invidiousNode.authToken authToken = invidiousNode.authToken
if authToken <> invalid and authToken.profileNode <> invalid and authToken.profileNode.type = "youtube" and not StringUtils.IsNullOrEmpty(authToken.token) if authToken <> invalid and authToken.profileNode <> invalid and authToken.profileNode.type = "youtube" and not StringUtils.IsNullOrEmpty(authToken.token)
accessToken = authToken.token accessToken = authToken.token
onBehalfOfUser = authToken.activeIdentifyToken onBehalfOfUser = authToken.activeIdentifyToken
profileNode = authToken.profileNode
end if end if
metadata = InnertubeService.GetVideoMetadata(contentNode.videoId, { metadata = InnertubeService.GetVideoMetadata(contentNode.videoId, {
@@ -59,6 +62,8 @@ function ExecuteJob() as void
"visitorData": visitorData.visitorData "visitorData": visitorData.visitorData
"accessToken": accessToken "accessToken": accessToken
"onBehalfOfUser": onBehalfOfUser "onBehalfOfUser": onBehalfOfUser
"profileNode": profileNode
"profilesService": profilesService
}) })
if IsAssociativeArray(metadata) if IsAssociativeArray(metadata)
contentNode.addFields({ contentNode.addFields({
@@ -187,6 +187,7 @@ function StartVideoContentJob(videoContentNode as object)
preferences: m.top.preferences preferences: m.top.preferences
loungeService: m.top.loungeService loungeService: m.top.loungeService
playletServerPort: m.top.webServer.port playletServerPort: m.top.webServer.port
profilesService: m.top.profilesService
} }
m.videoContentJob = JobSystem.CreateCallback(OnVideoContentJobDone) m.videoContentJob = JobSystem.CreateCallback(OnVideoContentJobDone)
@@ -10,6 +10,7 @@
<field id="invidious" type="node" bind="../../Invidious" /> <field id="invidious" type="node" bind="../../Invidious" />
<field id="webServer" type="node" bind="../../WebServer" /> <field id="webServer" type="node" bind="../../WebServer" />
<field id="loungeService" type="node" bind="../../LoungeService" /> <field id="loungeService" type="node" bind="../../LoungeService" />
<field id="profilesService" type="node" bind="../../ProfilesService" />
<field id="previousPlayer" type="node" /> <field id="previousPlayer" type="node" />
<field id="minRect" type="rect2D" value="[834,460,426,240]" /> <field id="minRect" type="rect2D" value="[834,460,426,240]" />
<field id="maxRect" type="rect2D" value="[0,0,1280,720]" /> <field id="maxRect" type="rect2D" value="[0,0,1280,720]" />
@@ -1075,6 +1075,7 @@ function StartVideoContentJob(videoContentNode as object)
preferences: m.top.preferences preferences: m.top.preferences
loungeService: m.top.loungeService loungeService: m.top.loungeService
playletServerPort: m.top.webServer.port playletServerPort: m.top.webServer.port
profilesService: m.top.profilesService
} }
m.videoContentJob = JobSystem.CreateCallback(OnVideoContentJobDone) m.videoContentJob = JobSystem.CreateCallback(OnVideoContentJobDone)
@@ -24,6 +24,7 @@
<field id="invidious" type="node" bind="../../Invidious" /> <field id="invidious" type="node" bind="../../Invidious" />
<field id="webServer" type="node" bind="../../WebServer" /> <field id="webServer" type="node" bind="../../WebServer" />
<field id="loungeService" type="node" bind="../../LoungeService" /> <field id="loungeService" type="node" bind="../../LoungeService" />
<field id="profilesService" type="node" bind="../../ProfilesService" />
<field id="previousPlayer" type="node" /> <field id="previousPlayer" type="node" />
<!-- PiP rects: minRect/maxRect drive width/height/translation. --> <!-- PiP rects: minRect/maxRect drive width/height/translation. -->
<field id="minRect" type="rect2D" value="[834,460,426,240]" /> <field id="minRect" type="rect2D" value="[834,460,426,240]" />
@@ -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