Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use credentialTransferToken to play age restricted videos #498

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions playlet-lib/src/components/Services/Innertube/InnertubeService.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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": "*/*"
Expand All @@ -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 = {
Expand Down Expand Up @@ -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": "*/*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ class LoungeApi

function HandleSetPlaylist(_commandId as integer, commandType as string, commandArgs as object, _messagesToSend as object)
LogDebug(commandType, commandArgs)
if not StringUtils.IsNullOrEmpty(commandArgs.ctt)
m.loungeServiceNode.ctt = commandArgs.ctt
end if
LoungeVideoQueue.SetPlaylist(m.videoQueueNode, m.invService, commandArgs)
end function

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
6 changes: 5 additions & 1 deletion playlet-lib/src/components/VideoPlayer/VideoContentTask.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions playlet-lib/src/components/VideoPlayer/VideoPlayer.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down