Use living room potoken identity
This commit is contained in:
1 parent
5c5fe19440
commit
4754e1620b
18 files changed
+233
-253
No files matched your search
+1
-1
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Attempt to fix `No valid bitrates` error by adding PoToken generation in server and web app
|
- Attempt to fix `No valid bitrates` error
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ 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
|
||||||
|
|||||||
@@ -51,12 +51,13 @@ namespace Innertube
|
|||||||
|
|
||||||
function CreateContext(client as Innertube.ClientType, deviceInfo as object, options = invalid as object) as object
|
function CreateContext(client as Innertube.ClientType, deviceInfo as object, options = invalid as object) as object
|
||||||
contextClient = invalid
|
contextClient = invalid
|
||||||
|
livingRoomPoTokenId = OptionUtils.Get(options, "livingRoomPoTokenId")
|
||||||
if client = ClientType.Web
|
if client = ClientType.Web
|
||||||
contextClient = CreateContextClientWeb(deviceInfo)
|
contextClient = CreateContextClientWeb(deviceInfo)
|
||||||
else if client = ClientType.IOS
|
else if client = ClientType.IOS
|
||||||
contextClient = CreateContextClientIOS(deviceInfo)
|
contextClient = CreateContextClientIOS(deviceInfo)
|
||||||
else if client = ClientType.Tv or client = ClientType.TvDowngraded
|
else if client = ClientType.Tv or client = ClientType.TvDowngraded
|
||||||
contextClient = CreateContextClientTv(deviceInfo, client)
|
contextClient = CreateContextClientTv(deviceInfo, client, livingRoomPoTokenId)
|
||||||
else
|
else
|
||||||
throw "Invalid client type"
|
throw "Invalid client type"
|
||||||
end if
|
end if
|
||||||
@@ -163,12 +164,12 @@ namespace Innertube
|
|||||||
}
|
}
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function CreateContextClientTv(deviceInfo as object, client as Innertube.ClientType) as object
|
function CreateContextClientTv(deviceInfo as object, client as Innertube.ClientType, livingRoomPoTokenId = "" as dynamic) as object
|
||||||
tvClientVersion = INNERTUBE_TV_CLIENT_VERSION
|
tvClientVersion = INNERTUBE_TV_CLIENT_VERSION
|
||||||
if client = ClientType.TvDowngraded
|
if client = ClientType.TvDowngraded
|
||||||
tvClientVersion = INNERTUBE_TV_CLIENT_VERSION_DOWNGRADED
|
tvClientVersion = INNERTUBE_TV_CLIENT_VERSION_DOWNGRADED
|
||||||
end if
|
end if
|
||||||
return {
|
contextClient = {
|
||||||
"hl": GetCurrentLocale(deviceInfo)
|
"hl": GetCurrentLocale(deviceInfo)
|
||||||
"gl": GetContentRegion(deviceInfo)
|
"gl": GetContentRegion(deviceInfo)
|
||||||
"remoteHost": ""
|
"remoteHost": ""
|
||||||
@@ -205,6 +206,10 @@ namespace Innertube
|
|||||||
"playerType": "UNIPLAYER"
|
"playerType": "UNIPLAYER"
|
||||||
"connectionType": "CONN_CELLULAR_4G"
|
"connectionType": "CONN_CELLULAR_4G"
|
||||||
}
|
}
|
||||||
|
if not StringUtils.IsNullOrEmpty(livingRoomPoTokenId)
|
||||||
|
contextClient.tvAppInfo["livingRoomPoTokenId"] = livingRoomPoTokenId
|
||||||
|
end if
|
||||||
|
return contextClient
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetCurrentLocale(deviceInfo as object) as string
|
function GetCurrentLocale(deviceInfo as object) as string
|
||||||
|
|||||||
@@ -4,29 +4,23 @@ import "pkg:/components/Services/Innertube/Constants.bs"
|
|||||||
import "pkg:/source/utils/StringUtils.bs"
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
m.top.observeField("requestVisitorData", FuncName(OnRequestVisitorData))
|
m.top.observeField("requestSessionData", FuncName(OnRequestSessionData))
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnNodeReady()
|
function OnNodeReady()
|
||||||
OnRequestVisitorData()
|
QueueSessionDataJob()
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnRequestVisitorData() as void
|
function OnRequestSessionData() as void
|
||||||
if m.innertubeSessionDataJob <> invalid and not m.innertubeSessionDataJob.done
|
sessionData = m.top.sessionData
|
||||||
|
if IsAssociativeArray(sessionData) and not StringUtils.IsNullOrEmpty(sessionData.visitorData) and not StringUtils.IsNullOrEmpty(sessionData.livingRoomPoTokenId)
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
QueueSessionDataJob()
|
||||||
RequestVisitorData()
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function RequestVisitorData() as void
|
function QueueSessionDataJob() as void
|
||||||
if m.innertubeSessionDataJob <> invalid
|
if m.innertubeSessionDataJob <> invalid and not m.innertubeSessionDataJob.done
|
||||||
m.innertubeSessionDataJob.cancel = true
|
|
||||||
m.innertubeSessionDataJob = invalid
|
|
||||||
end if
|
|
||||||
|
|
||||||
visitorData = m.top.visitorData
|
|
||||||
if not StringUtils.IsNullOrEmpty(visitorData)
|
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
|
||||||
@@ -41,8 +35,4 @@ end function
|
|||||||
function OnInnertubeSessionDataJobDone(event as object) as void
|
function OnInnertubeSessionDataJobDone(event as object) as void
|
||||||
JobSystem.UnobserveCallback(event.getRoSGNode())
|
JobSystem.UnobserveCallback(event.getRoSGNode())
|
||||||
m.innertubeSessionDataJob = invalid
|
m.innertubeSessionDataJob = invalid
|
||||||
if StringUtils.IsNullOrEmpty(m.top.visitorData)
|
|
||||||
' Trigger observers in case the job threw an error and didn't set the visitorData
|
|
||||||
m.top.visitorData = ""
|
|
||||||
end if
|
|
||||||
end function
|
end function
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
<component name="Innertube" extends="Node" includes="AutoBind">
|
<component name="Innertube" extends="Node" includes="AutoBind">
|
||||||
<interface>
|
<interface>
|
||||||
<field id="timestamp" type="int" />
|
<field id="sessionData" type="assocarray" alwaysNotify="true" />
|
||||||
<field id="visitorData" type="string" alwaysNotify="true" />
|
<field id="requestSessionData" type="boolean" alwaysNotify="true" />
|
||||||
<field id="requestVisitorData" type="boolean" alwaysNotify="true" />
|
|
||||||
<field id="jobQueue" type="node" />
|
<field id="jobQueue" type="node" />
|
||||||
</interface>
|
</interface>
|
||||||
</component>
|
</component>
|
||||||
@@ -28,13 +28,6 @@ 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)
|
||||||
@@ -767,53 +760,6 @@ 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
|
|
||||||
|
|
||||||
' The identity used to bind GVS poTokens: the signed-in profile's datasyncIdToken,
|
|
||||||
' falling back to visitorData when logged out (or when no datasyncIdToken is available).
|
|
||||||
function GetCurrentPoTokenIdentity(profilesService as object, innertubeNode as object) as string
|
|
||||||
currentProfile = profilesService.currentProfile
|
|
||||||
if currentProfile <> invalid and currentProfile.type = "youtube"
|
|
||||||
accessToken = currentProfile.accessToken
|
|
||||||
if not StringUtils.IsNullOrEmpty(accessToken)
|
|
||||||
' Signed in: bind to the datasyncIdToken, matching the decipher request's identity.
|
|
||||||
return GetProfileDatasyncIdToken(currentProfile, accessToken, profilesService, invalid)
|
|
||||||
end if
|
|
||||||
end if
|
|
||||||
return innertubeNode.visitorData
|
|
||||||
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)
|
||||||
|
|
||||||
|
|||||||
@@ -6,23 +6,50 @@ function ExecuteJob() as void
|
|||||||
innertubeNode = JobGetInput().innertube
|
innertubeNode = JobGetInput().innertube
|
||||||
|
|
||||||
cached = Innertube.ReadSessionDataFromRegistry()
|
cached = Innertube.ReadSessionDataFromRegistry()
|
||||||
if cached <> invalid and not StringUtils.IsNullOrEmpty(cached.visitorData)
|
cachedVisitorData = ""
|
||||||
if IsInt(cached.timestamp)
|
cachedLivingRoomPoTokenId = ""
|
||||||
innertubeNode.timestamp = cached.timestamp
|
if IsAssociativeArray(cached)
|
||||||
end if
|
cachedVisitorData = ValidString(cached.visitorData)
|
||||||
innertubeNode.visitorData = cached.visitorData
|
cachedLivingRoomPoTokenId = ValidString(cached.livingRoomPoTokenId)
|
||||||
if Innertube.IsSessionDataFresh(cached)
|
|
||||||
return
|
|
||||||
end if
|
|
||||||
end if
|
end if
|
||||||
|
|
||||||
fetched = Innertube.RequestSessionData(JobGetCancellation())
|
' Publish the cached values immediately so playback isn't blocked while /tv is fetched.
|
||||||
if fetched <> invalid
|
innertubeNode.sessionData = {
|
||||||
Innertube.SaveSessionDataToRegistry(fetched)
|
"visitorData": cachedVisitorData
|
||||||
innertubeNode.timestamp = fetched.timestamp
|
"livingRoomPoTokenId": cachedLivingRoomPoTokenId
|
||||||
innertubeNode.visitorData = fetched.visitorData
|
}
|
||||||
else if StringUtils.IsNullOrEmpty(innertubeNode.visitorData)
|
|
||||||
' Refresh failed and we never had an id — wake a cold waiter to fail. Never blank a valid id.
|
fresh = Innertube.RequestTvClientData(JobGetCancellation())
|
||||||
innertubeNode.visitorData = ""
|
if fresh = invalid
|
||||||
|
return
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
visitorData = cachedVisitorData
|
||||||
|
timestamp = 0
|
||||||
|
if Innertube.IsVisitorDataFresh(cached)
|
||||||
|
visitorData = cached.visitorData
|
||||||
|
timestamp = cached.timestamp
|
||||||
|
else if not StringUtils.IsNullOrEmpty(fresh.visitorData)
|
||||||
|
visitorData = fresh.visitorData
|
||||||
|
timestamp = fresh.timestamp
|
||||||
|
else if not StringUtils.IsNullOrEmpty(cachedVisitorData)
|
||||||
|
visitorData = cachedVisitorData
|
||||||
|
timestamp = cached.timestamp
|
||||||
|
end if
|
||||||
|
|
||||||
|
livingRoomPoTokenId = cachedLivingRoomPoTokenId
|
||||||
|
if not StringUtils.IsNullOrEmpty(fresh.livingRoomPoTokenId)
|
||||||
|
livingRoomPoTokenId = fresh.livingRoomPoTokenId
|
||||||
|
end if
|
||||||
|
|
||||||
|
Innertube.SaveSessionDataToRegistry({
|
||||||
|
"timestamp": timestamp
|
||||||
|
"visitorData": visitorData
|
||||||
|
"livingRoomPoTokenId": livingRoomPoTokenId
|
||||||
|
})
|
||||||
|
|
||||||
|
innertubeNode.sessionData = {
|
||||||
|
"visitorData": visitorData
|
||||||
|
"livingRoomPoTokenId": livingRoomPoTokenId
|
||||||
|
}
|
||||||
end function
|
end function
|
||||||
@@ -248,7 +248,6 @@ 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
|
||||||
@@ -298,26 +297,6 @@ 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
|
||||||
|
|||||||
@@ -15,7 +15,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")
|
livingRoomPoTokenId = OptionUtils.Get(options, "livingRoomPoTokenId")
|
||||||
cpn = InnertubeService.CreateClientPlaybackNonce()
|
cpn = InnertubeService.CreateClientPlaybackNonce()
|
||||||
|
|
||||||
isTv = (client = Innertube.ClientType.Tv or client = Innertube.ClientType.TvDowngraded)
|
isTv = (client = Innertube.ClientType.Tv or client = Innertube.ClientType.TvDowngraded)
|
||||||
@@ -68,12 +68,15 @@ 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
|
end if
|
||||||
else if useAccessToken and not StringUtils.IsNullOrEmpty(datasyncIdToken)
|
|
||||||
request.poTokenIdentity = datasyncIdToken
|
if not StringUtils.IsNullOrEmpty(livingRoomPoTokenId)
|
||||||
|
request.poTokenIdentity = livingRoomPoTokenId
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if not StringUtils.IsNullOrEmpty(request.poTokenIdentity)
|
if not StringUtils.IsNullOrEmpty(request.poTokenIdentity)
|
||||||
|
' NOTE: local potoken (browser-minted) is currently not in use.
|
||||||
|
' GetValidPoTokenForIdentity should return "", and the backend would mint the potoken.
|
||||||
request.poToken = Innertube.PoTokens.GetValidPoTokenForIdentity(request.poTokenIdentity)
|
request.poToken = Innertube.PoTokens.GetValidPoTokenForIdentity(request.poTokenIdentity)
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import "pkg:/components/Services/Innertube/Constants.bs"
|
import "pkg:/components/Services/Innertube/Constants.bs"
|
||||||
|
import "pkg:/components/Services/Innertube/Context.bs"
|
||||||
import "pkg:/source/services/HttpClient.bs"
|
import "pkg:/source/services/HttpClient.bs"
|
||||||
|
import "pkg:/source/utils/CancellationUtils.bs"
|
||||||
import "pkg:/source/utils/Logging.bs"
|
import "pkg:/source/utils/Logging.bs"
|
||||||
import "pkg:/source/utils/ObjectUtils.bs"
|
|
||||||
import "pkg:/source/utils/RegistryUtils.bs"
|
import "pkg:/source/utils/RegistryUtils.bs"
|
||||||
import "pkg:/source/utils/StringUtils.bs"
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
import "pkg:/source/utils/TimeUtils.bs"
|
import "pkg:/source/utils/TimeUtils.bs"
|
||||||
@@ -10,8 +11,9 @@ namespace Innertube
|
|||||||
|
|
||||||
const SESSION_DATA_VERSION = 1
|
const SESSION_DATA_VERSION = 1
|
||||||
const INNERTUBE_VISITOR_DATA_LIFESPAN_SECONDS = 60 * 60 * 24 * 14 ' 14 days
|
const INNERTUBE_VISITOR_DATA_LIFESPAN_SECONDS = 60 * 60 * 24 * 14 ' 14 days
|
||||||
|
const TV_CLIENT_DATA_MAX_ATTEMPTS = 3
|
||||||
|
|
||||||
function IsSessionDataFresh(sessionData as object) as boolean
|
function IsVisitorDataFresh(sessionData as object) as boolean
|
||||||
if sessionData = invalid or not IsInt(sessionData.timestamp)
|
if sessionData = invalid or not IsInt(sessionData.timestamp)
|
||||||
return false
|
return false
|
||||||
end if
|
end if
|
||||||
@@ -19,48 +21,79 @@ namespace Innertube
|
|||||||
return nowSeconds - sessionData.timestamp <= INNERTUBE_VISITOR_DATA_LIFESPAN_SECONDS
|
return nowSeconds - sessionData.timestamp <= INNERTUBE_VISITOR_DATA_LIFESPAN_SECONDS
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function RequestSessionData(cancellation = invalid as object) as object
|
function RequestTvClientData(cancellation = invalid as object) as object
|
||||||
request = HttpClient.Get("https://www.youtube.com/sw.js_data")
|
visitorData = ""
|
||||||
request.Headers({
|
livingRoomPoTokenId = ""
|
||||||
"Accept-Language": "en-US,en;q=0.9"
|
|
||||||
"User-Agent": INNERTUBE_WEB_USER_AGENT
|
|
||||||
"Accept": "*/*"
|
|
||||||
"Referer": "https://www.youtube.com/sw.js"
|
|
||||||
})
|
|
||||||
request.Cancellation(cancellation)
|
|
||||||
request.TryCount(2)
|
|
||||||
request.NoCache()
|
|
||||||
|
|
||||||
response = request.Await()
|
for attempt = 1 to TV_CLIENT_DATA_MAX_ATTEMPTS
|
||||||
if not response.IsSuccess()
|
text = FetchTvClientPage(cancellation)
|
||||||
LogError("Failed to fetch session data: " + response.ErrorMessage())
|
if text <> invalid
|
||||||
return invalid
|
if StringUtils.IsNullOrEmpty(visitorData)
|
||||||
end if
|
visitorData = ExtractEscapedJsonString(text, "visitorData")
|
||||||
|
end if
|
||||||
|
if StringUtils.IsNullOrEmpty(livingRoomPoTokenId)
|
||||||
|
livingRoomPoTokenId = ExtractEscapedJsonString(text, "LIVING_ROOM_PO_TOKEN_ID")
|
||||||
|
end if
|
||||||
|
if not StringUtils.IsNullOrEmpty(visitorData) and not StringUtils.IsNullOrEmpty(livingRoomPoTokenId)
|
||||||
|
exit for
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
if CancellationUtils.IsCancelled(cancellation)
|
||||||
|
exit for
|
||||||
|
end if
|
||||||
|
if attempt < TV_CLIENT_DATA_MAX_ATTEMPTS
|
||||||
|
sleep(attempt * 1000)
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
|
||||||
text = response.Text()
|
|
||||||
text = text.Replace(`)]}'`, "")
|
|
||||||
|
|
||||||
json = StringUtils.ParseJsonSafe(text)
|
|
||||||
if json = invalid
|
|
||||||
LogError("Failed to parse session data: " + text)
|
|
||||||
return invalid
|
|
||||||
end if
|
|
||||||
|
|
||||||
visitorData = ObjectUtils.Dig(json, [0, 2, 0, 0, 13])
|
|
||||||
if StringUtils.IsNullOrEmpty(visitorData)
|
if StringUtils.IsNullOrEmpty(visitorData)
|
||||||
LogError("Failed to find visitorData in session data: " + text)
|
LogError("Could not extract visitorData from tv client data")
|
||||||
|
end if
|
||||||
|
if StringUtils.IsNullOrEmpty(livingRoomPoTokenId)
|
||||||
|
LogError("Could not extract livingRoomPoTokenId from tv client data")
|
||||||
|
end if
|
||||||
|
if StringUtils.IsNullOrEmpty(visitorData) and StringUtils.IsNullOrEmpty(livingRoomPoTokenId)
|
||||||
return invalid
|
return invalid
|
||||||
end if
|
end if
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"timestamp": TimeUtils.Now().AsSeconds()
|
"timestamp": TimeUtils.Now().AsSeconds()
|
||||||
"visitorData": visitorData
|
"visitorData": visitorData
|
||||||
|
"livingRoomPoTokenId": livingRoomPoTokenId
|
||||||
}
|
}
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function FetchTvClientPage(cancellation as object) as dynamic
|
||||||
|
request = HttpClient.Get("https://www.youtube.com/tv")
|
||||||
|
headers = Innertube.CreateHeaders(Innertube.ClientType.Tv)
|
||||||
|
headers["Referer"] = "https://www.youtube.com/tv"
|
||||||
|
request.Headers(headers)
|
||||||
|
request.Cancellation(cancellation)
|
||||||
|
request.NoCache()
|
||||||
|
|
||||||
|
response = request.Await()
|
||||||
|
if not response.IsSuccess()
|
||||||
|
LogError("Failed to fetch tv client data:", response.ErrorMessage())
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
return response.Text()
|
||||||
|
end function
|
||||||
|
|
||||||
|
function ExtractEscapedJsonString(text as string, key as string) as string
|
||||||
|
regex = CreateObject("roRegex", `"${key}":"([^"]*)"`, "")
|
||||||
|
match = regex.Match(text)
|
||||||
|
if match.Count() < 2
|
||||||
|
return ""
|
||||||
|
end if
|
||||||
|
decoded = StringUtils.ParseJsonSafe(`["${match[1]}"]`)
|
||||||
|
if not IsArray(decoded) or decoded.Count() <> 1
|
||||||
|
return ""
|
||||||
|
end if
|
||||||
|
return decoded[0]
|
||||||
|
end function
|
||||||
|
|
||||||
function SaveSessionDataToRegistry(sessionData as object) as void
|
function SaveSessionDataToRegistry(sessionData as object) as void
|
||||||
sessionData.__version = SESSION_DATA_VERSION
|
sessionData.__version = SESSION_DATA_VERSION
|
||||||
|
|
||||||
RegistryUtils.Write(RegistryUtils.INNERTUBE_SESSION_DATA, FormatJson(sessionData))
|
RegistryUtils.Write(RegistryUtils.INNERTUBE_SESSION_DATA, FormatJson(sessionData))
|
||||||
end function
|
end function
|
||||||
|
|
||||||
@@ -70,13 +103,7 @@ namespace Innertube
|
|||||||
return invalid
|
return invalid
|
||||||
end if
|
end if
|
||||||
|
|
||||||
sessionData = StringUtils.ParseJsonSafe(sessionData)
|
return StringUtils.ParseJsonSafe(sessionData)
|
||||||
if sessionData = invalid
|
|
||||||
RegistryUtils.Delete(RegistryUtils.INNERTUBE_SESSION_DATA)
|
|
||||||
return invalid
|
|
||||||
end if
|
|
||||||
|
|
||||||
return sessionData
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
end namespace
|
end namespace
|
||||||
@@ -58,7 +58,6 @@ 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
|
||||||
@@ -183,7 +182,6 @@ 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)
|
||||||
|
|||||||
@@ -36,13 +36,13 @@ function ExecuteJob() as void
|
|||||||
cancellation = JobGetCancellation()
|
cancellation = JobGetCancellation()
|
||||||
if backend = "playlet"
|
if backend = "playlet"
|
||||||
|
|
||||||
visitorData = GetVisitorData(innertubeNode, cancellation)
|
sessionData = GetSessionData(innertubeNode, cancellation)
|
||||||
if visitorData.cancel = true
|
if sessionData.cancel = true
|
||||||
JobCancel()
|
JobCancel()
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
if visitorData.error <> invalid
|
if sessionData.error <> invalid
|
||||||
JobError(visitorData.error)
|
JobError(sessionData.error)
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
|
||||||
@@ -59,7 +59,8 @@ function ExecuteJob() as void
|
|||||||
metadata = InnertubeService.GetVideoMetadata(contentNode.videoId, {
|
metadata = InnertubeService.GetVideoMetadata(contentNode.videoId, {
|
||||||
"cancellation": cancellation
|
"cancellation": cancellation
|
||||||
"credentialTransferToken": loungeServiceNode.credentialTransferToken
|
"credentialTransferToken": loungeServiceNode.credentialTransferToken
|
||||||
"visitorData": visitorData.visitorData
|
"visitorData": sessionData.visitorData
|
||||||
|
"livingRoomPoTokenId": sessionData.livingRoomPoTokenId
|
||||||
"accessToken": accessToken
|
"accessToken": accessToken
|
||||||
"onBehalfOfUser": onBehalfOfUser
|
"onBehalfOfUser": onBehalfOfUser
|
||||||
"profileNode": profileNode
|
"profileNode": profileNode
|
||||||
@@ -164,48 +165,42 @@ function ExecuteJob() as void
|
|||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetVisitorData(innertubeNode as object, cancellation as object) as object
|
function GetSessionData(innertubeNode as object, cancellation as object) as object
|
||||||
port = CreateObject("roMessagePort")
|
sessionData = innertubeNode.sessionData
|
||||||
|
if SessionDataComplete(sessionData)
|
||||||
|
return sessionData
|
||||||
|
end if
|
||||||
|
|
||||||
MessagePortUtils.ObserveFieldScopedExSafe(innertubeNode, "visitorData", port)
|
port = CreateObject("roMessagePort")
|
||||||
|
MessagePortUtils.ObserveFieldScopedExSafe(innertubeNode, "sessionData", port)
|
||||||
CancellationUtils.ObserveCancellationScoped(cancellation, port)
|
CancellationUtils.ObserveCancellationScoped(cancellation, port)
|
||||||
|
|
||||||
visitorData = innertubeNode.visitorData
|
innertubeNode.requestSessionData = true
|
||||||
if not StringUtils.IsNullOrEmpty(visitorData)
|
|
||||||
innertubeNode.unobserveFieldScoped("visitorData")
|
|
||||||
CancellationUtils.UnobserveCancellationScoped(cancellation)
|
|
||||||
|
|
||||||
return {
|
|
||||||
visitorData: visitorData
|
|
||||||
}
|
|
||||||
end if
|
|
||||||
|
|
||||||
innertubeNode.requestVisitorData = true
|
|
||||||
message = wait(30000, port)
|
message = wait(30000, port)
|
||||||
|
|
||||||
innertubeNode.unobserveFieldScoped("visitorData")
|
innertubeNode.unobserveFieldScoped("sessionData")
|
||||||
CancellationUtils.UnobserveCancellationScoped(cancellation)
|
CancellationUtils.UnobserveCancellationScoped(cancellation)
|
||||||
|
|
||||||
if message <> invalid
|
if message <> invalid and CancellationUtils.IsCancellationEvent(cancellation, message)
|
||||||
if CancellationUtils.IsCancellationEvent(cancellation, message)
|
return {
|
||||||
return {
|
cancel: true
|
||||||
cancel: true
|
}
|
||||||
}
|
|
||||||
end if
|
|
||||||
visitorData = message.getData()
|
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if StringUtils.IsNullOrEmpty(visitorData)
|
sessionData = innertubeNode.sessionData
|
||||||
return {
|
if SessionDataComplete(sessionData)
|
||||||
error: "Failed to get visitor data. Please try again later."
|
return sessionData
|
||||||
}
|
|
||||||
end if
|
end if
|
||||||
|
|
||||||
return {
|
return {
|
||||||
visitorData: visitorData
|
error: "Failed to get session data. Please try again later."
|
||||||
}
|
}
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function SessionDataComplete(sessionData as object) as boolean
|
||||||
|
return IsAssociativeArray(sessionData) and not StringUtils.IsNullOrEmpty(sessionData.visitorData) and not StringUtils.IsNullOrEmpty(sessionData.livingRoomPoTokenId)
|
||||||
|
end function
|
||||||
|
|
||||||
function CreateStreamUrls(metadata as object, service as Invidious.InvidiousService, preferences as object, backend as string, playletServerPort as integer) as object
|
function CreateStreamUrls(metadata as object, service as Invidious.InvidiousService, preferences as object, backend as string, playletServerPort as integer) as object
|
||||||
instance = service.GetInstance()
|
instance = service.GetInstance()
|
||||||
proxyVideos = preferences["invidious.proxy_videos"]
|
proxyVideos = preferences["invidious.proxy_videos"]
|
||||||
|
|||||||
@@ -21,12 +21,18 @@ function ExecuteJob() as void
|
|||||||
|
|
||||||
backend = preferencesNode["backend.selected"]
|
backend = preferencesNode["backend.selected"]
|
||||||
|
|
||||||
|
visitorData = ""
|
||||||
|
sessionData = innertubeNode.sessionData
|
||||||
|
if IsAssociativeArray(sessionData)
|
||||||
|
visitorData = ValidString(sessionData.visitorData)
|
||||||
|
end if
|
||||||
|
|
||||||
requestOptions = {
|
requestOptions = {
|
||||||
cacheSeconds: 8640000 ' 100 days
|
cacheSeconds: 8640000 ' 100 days
|
||||||
cancellation: cancellation
|
cancellation: cancellation
|
||||||
tryCount: 1
|
tryCount: 1
|
||||||
fetchNext: false
|
fetchNext: false
|
||||||
visitorData: innertubeNode.visitorData
|
visitorData: visitorData
|
||||||
}
|
}
|
||||||
|
|
||||||
' TODO:P1: Use InnertubeService.GetVideoInfoBatched with an array instead of loading each video individually
|
' TODO:P1: Use InnertubeService.GetVideoInfoBatched with an array instead of loading each video individually
|
||||||
|
|||||||
@@ -20,7 +20,12 @@ namespace Http
|
|||||||
function GetPoToken(context as object) as object
|
function GetPoToken(context as object) as object
|
||||||
response = context.response
|
response = context.response
|
||||||
|
|
||||||
identity = InnertubeService.GetCurrentPoTokenIdentity(m.profilesService, m.innertube)
|
identity = ""
|
||||||
|
sessionData = m.innertube.sessionData
|
||||||
|
if IsAssociativeArray(sessionData)
|
||||||
|
identity = ValidString(sessionData.livingRoomPoTokenId)
|
||||||
|
end if
|
||||||
|
|
||||||
if StringUtils.IsNullOrEmpty(identity)
|
if StringUtils.IsNullOrEmpty(identity)
|
||||||
response.Default(503, "No current identity")
|
response.Default(503, "No current identity")
|
||||||
return true
|
return true
|
||||||
@@ -64,8 +69,20 @@ namespace Http
|
|||||||
return true
|
return true
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
|
||||||
|
identity = ""
|
||||||
|
sessionData = m.innertube.sessionData
|
||||||
|
if IsAssociativeArray(sessionData)
|
||||||
|
identity = ValidString(sessionData.livingRoomPoTokenId)
|
||||||
|
end if
|
||||||
|
|
||||||
|
if StringUtils.IsNullOrEmpty(identity)
|
||||||
|
response.Default(503, "No current identity")
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
' Reject identities other than the device's current one (guards the shared registry).
|
' Reject identities other than the device's current one (guards the shared registry).
|
||||||
if payload.identity <> InnertubeService.GetCurrentPoTokenIdentity(m.profilesService, m.innertube)
|
if payload.identity <> identity
|
||||||
response.Default(409, "identity is not the device's current identity")
|
response.Default(409, "identity is not the device's current identity")
|
||||||
return true
|
return true
|
||||||
end if
|
end if
|
||||||
@@ -146,7 +163,7 @@ namespace Http
|
|||||||
if currentProfile <> invalid and currentProfile.type = "youtube"
|
if currentProfile <> invalid and currentProfile.type = "youtube"
|
||||||
options["accessToken"] = currentProfile.accessToken
|
options["accessToken"] = currentProfile.accessToken
|
||||||
else
|
else
|
||||||
options["visitorData"] = m.innertube.visitorData
|
options["visitorData"] = m.innertube.sessionData.visitorData
|
||||||
end if
|
end if
|
||||||
|
|
||||||
drmResponse = InnertubeService.GetDrmLicense(options)
|
drmResponse = InnertubeService.GetDrmLicense(options)
|
||||||
|
|||||||
+7
-1
@@ -548,9 +548,15 @@ namespace Http
|
|||||||
raw = request.query.raw <> invalid
|
raw = request.query.raw <> invalid
|
||||||
videoInfoBatched = request.query.video_info_batched <> invalid
|
videoInfoBatched = request.query.video_info_batched <> invalid
|
||||||
|
|
||||||
|
visitorData = ""
|
||||||
|
sessionData = m.innertube.sessionData
|
||||||
|
if IsAssociativeArray(sessionData)
|
||||||
|
visitorData = ValidString(sessionData.visitorData)
|
||||||
|
end if
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
"raw": raw
|
"raw": raw
|
||||||
"visitorData": m.innertube.visitorData
|
"visitorData": visitorData
|
||||||
}
|
}
|
||||||
|
|
||||||
if videoInfoBatched
|
if videoInfoBatched
|
||||||
|
|||||||
@@ -315,14 +315,14 @@
|
|||||||
displayText: "Mint PoToken",
|
displayText: "Mint PoToken",
|
||||||
key: "dev.mint_potoken",
|
key: "dev.mint_potoken",
|
||||||
description: "Mint a PoToken for the current identity.",
|
description: "Mint a PoToken for the current identity.",
|
||||||
visibility: "web",
|
visibility: "off",
|
||||||
svelteComponent: "MintPoTokenControl",
|
svelteComponent: "MintPoTokenControl",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayText: "Clear PoTokens",
|
displayText: "Clear PoTokens",
|
||||||
key: "dev.clear_potokens",
|
key: "dev.clear_potokens",
|
||||||
description: "Clear all stored PoTokens.",
|
description: "Clear all stored PoTokens.",
|
||||||
visibility: "web",
|
visibility: "off",
|
||||||
svelteComponent: "ClearPoTokensControl",
|
svelteComponent: "ClearPoTokensControl",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import "pkg:/components/Services/Innertube/SessionData.bs"
|
||||||
|
|
||||||
|
namespace Tests
|
||||||
|
|
||||||
|
@suite
|
||||||
|
class InnertubeExtractEscapedJsonStringTests extends Rooibos.BaseTestSuite
|
||||||
|
|
||||||
|
@describe("Innertube.ExtractEscapedJsonString")
|
||||||
|
|
||||||
|
@it("extracts a plain value")
|
||||||
|
function plain()
|
||||||
|
text = `noise "visitorData":"AbCd123" noise`
|
||||||
|
m.assertEqual(Innertube.ExtractEscapedJsonString(text, "visitorData"), "AbCd123")
|
||||||
|
end function
|
||||||
|
|
||||||
|
@it("decodes the escaped = padding")
|
||||||
|
function decodesPadding()
|
||||||
|
bs = Chr(92)
|
||||||
|
text = `"LIVING_ROOM_PO_TOKEN_ID":"THWY0ox3FA4${bs}u003d"`
|
||||||
|
m.assertEqual(Innertube.ExtractEscapedJsonString(text, "LIVING_ROOM_PO_TOKEN_ID"), "THWY0ox3FA4=")
|
||||||
|
end function
|
||||||
|
|
||||||
|
@it("decodes any escape, not just the padding")
|
||||||
|
function decodesAnyEscape()
|
||||||
|
bs = Chr(92)
|
||||||
|
text = `"key":"a${bs}u002fb"`
|
||||||
|
m.assertEqual(Innertube.ExtractEscapedJsonString(text, "key"), "a/b")
|
||||||
|
end function
|
||||||
|
|
||||||
|
@it("returns empty string when the key is absent")
|
||||||
|
function keyAbsent()
|
||||||
|
m.assertEqual(Innertube.ExtractEscapedJsonString(`"other":"x"`, "visitorData"), "")
|
||||||
|
end function
|
||||||
|
|
||||||
|
end class
|
||||||
|
|
||||||
|
end namespace
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
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
|
|
||||||
Reference in new issue
Block a user