Use credentialTransferToken to play age restricted videos (#498)

* Use credentialTransferToken to play age restricted videos

* changelog
This commit is contained in:
Brahim Hadriche authored and GitHub committed 2024-12-09 20:48:56 -05:00
1 parent ee239c3ea9
commit 1e161e8a77
6 files changed
+41 -5

No files matched your search

@@ -18,6 +18,7 @@ namespace InnertubeService
function GetVideoMetadata(videoId as string, options = invalid as object) as object
cancellation = invalid
fetchNext = true
ctt = ""
if options <> invalid
if options.DoesExist("cancellation")
@@ -26,16 +27,19 @@ namespace InnertubeService
if options.DoesExist("fetchNext")
fetchNext = options.fetchNext
end if
if options.DoesExist("ctt")
ctt = options.ctt
end if
end if
playerRequest = CreatePlayerRequest(videoId)
playerRequest = CreatePlayerRequest(videoId, ctt)
playerRequest.Cancellation(cancellation)
playerRequest.Send()
nextRequest = invalid
nextResponse = invalid
if fetchNext
nextRequest = CreateNextRequest(videoId)
nextRequest = CreateNextRequest(videoId, ctt)
nextRequest.Cancellation(cancellation)
nextRequest.Send()
end if
@@ -67,7 +71,7 @@ namespace InnertubeService
return playerResponse
end function
function CreatePlayerRequest(videoId as string) as object
function CreatePlayerRequest(videoId as string, ctt as string) as object
deviceInfo = CreateObject("roDeviceInfo")
payload = {
@@ -124,6 +128,13 @@ namespace InnertubeService
}
}
if not StringUtils.IsNullOrEmpty(ctt)
payload["context"]["user"]["credentialTransferTokens"] = [{
"token": ctt
"scope": "VIDEO"
}]
end if
request = HttpClient.Post("https://www.youtube.com/youtubei/v1/player?prettyPrint=false&alt=json", FormatJson(payload))
request.Headers({
"accept": "*/*"
@@ -137,7 +148,7 @@ namespace InnertubeService
return request
end function
function CreateNextRequest(videoId as string) as object
function CreateNextRequest(videoId as string, ctt as string) as object
deviceInfo = CreateObject("roDeviceInfo")
payload = {
@@ -185,6 +196,13 @@ namespace InnertubeService
}
}
if not StringUtils.IsNullOrEmpty(ctt)
payload["context"]["user"]["credentialTransferTokens"] = [{
"token": ctt
"scope": "VIDEO"
}]
end if
request = HttpClient.Post("https://www.youtube.com/youtubei/v1/next?prettyPrint=false&alt=json", FormatJson(payload))
request.Headers({
"accept": "*/*"
@@ -404,6 +404,17 @@ class LoungeApi
function HandleSetPlaylist(_commandId as integer, commandType as string, commandArgs as object, _messagesToSend as object)
LogDebug(commandType, commandArgs)
' TODO:P2 ctt: credentialTransferToken
' We receive credentialTransferTokens here that can be attached to innertube requests.
' The tokens belong to the user logged in on the mobile app.
' These allow us to watch age restricted videos and private videos.
' They are scoped by video.
' Right now we just store only the last ctt, which works ok if we're casting one video at a time.
' But if the age restrcited video is added to the queue, we don't capture a token and playing the video would fail.
' These tokens need to be managed better, based on the video they belong to.
if not StringUtils.IsNullOrEmpty(commandArgs.ctt)
m.loungeServiceNode.ctt = commandArgs.ctt
end if
LoungeVideoQueue.SetPlaylist(m.videoQueueNode, m.invService, commandArgs)
end function
@@ -5,6 +5,7 @@
<field id="deviceName" type="string" />
<field id="screenId" type="string" />
<field id="loungeToken" type="string" />
<field id="ctt" type="string" />
<field id="join" type="boolean" alwaysNotify="true" />
<field id="outgoingMessages" type="array" alwaysNotify="true" />
@@ -6,6 +6,7 @@ function VideoContentTask(input as object) as object
contentNode = input.content
invidiousNode = input.invidious
preferencesNode = input.preferences
loungeServiceNode = input.loungeService
playletServerPort = input.playletServerPort
if m.top.cancel
@@ -20,7 +21,10 @@ function VideoContentTask(input as object) as object
backend = preferencesNode["playback.backend"]
if backend = "playlet"
response = InnertubeService.GetVideoMetadata(contentNode.videoId, { cancellation: m.top.cancellation })
response = InnertubeService.GetVideoMetadata(contentNode.videoId, {
cancellation: m.top.cancellation
ctt: loungeServiceNode.ctt
})
else
response = service.GetVideoMetadata(contentNode.videoId, { cancellation: m.top.cancellation })
end if
@@ -152,6 +152,7 @@ function StartVideoContentTask(videoContentNode as object)
content: videoContentNode
invidious: m.top.invidious
preferences: m.top.preferences
loungeService: m.top.loungeService
playletServerPort: m.top.webServer.port
}, OnVideoContentTaskResults)
end function