OAuth: mark video watched (#604)
* OAuth: mark video watched * remove comment * Tweaks
This commit is contained in:
1 parent
918b763384
commit
4fc44becd2
2 files changed
+67
-17
No files matched your search
@@ -40,7 +40,7 @@ namespace InnertubeService
|
|||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
|
|
||||||
playerRequest = Innertube.CreatePlayerRequest(videoId, ctt, visitorData)
|
playerRequest = Innertube.CreatePlayerRequest(videoId, ctt, visitorData, Innertube.ClientType.IOS)
|
||||||
playerRequest.Cancellation(cancellation)
|
playerRequest.Cancellation(cancellation)
|
||||||
if raw
|
if raw
|
||||||
playerRequest.LogCurlCommand()
|
playerRequest.LogCurlCommand()
|
||||||
@@ -316,24 +316,73 @@ namespace InnertubeService
|
|||||||
return Innertube.ParseResponseDataForFeeds(json)
|
return Innertube.ParseResponseDataForFeeds(json)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function AuthMarkVideoWatched(videoId as string, options = invalid as object) as object
|
function AuthMarkVideoWatched(videoId as string, options as object) as boolean
|
||||||
' cancellation = invalid
|
cancellation = invalid
|
||||||
' accessToken = invalid
|
accessToken = options.accessToken
|
||||||
|
|
||||||
' if options <> invalid
|
if options.DoesExist("cancellation")
|
||||||
' if options.DoesExist("cancellation")
|
cancellation = options.cancellation
|
||||||
' cancellation = options.cancellation
|
end if
|
||||||
' end if
|
|
||||||
' if options.DoesExist("accessToken")
|
|
||||||
' accessToken = options.accessToken
|
|
||||||
' end if
|
|
||||||
' end if
|
|
||||||
|
|
||||||
' TODO:P1 : Implement this
|
playerRequest = Innertube.CreatePlayerRequest(videoId, "", "", Innertube.ClientType.Tv)
|
||||||
LogInfo(`Marking video as watched: ${videoId} - not implemented`)
|
playerRequest.Cancellation(cancellation)
|
||||||
|
playerRequest.Header("Authorization", "Bearer " + accessToken)
|
||||||
|
|
||||||
|
playerResponse = playerRequest.Await()
|
||||||
|
if not playerResponse.IsSuccess()
|
||||||
|
LogError("Error marking video as watched:", playerResponse.ErrorMessage())
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
|
||||||
|
if CancellationUtils.IsCancelled(cancellation)
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
|
||||||
|
json = playerResponse.Json()
|
||||||
|
videostatsPlaybackUrl = ObjectUtils.Dig(json, ["playbackTracking", "videostatsPlaybackUrl", "baseUrl"])
|
||||||
|
if StringUtils.IsNullOrEmpty(videostatsPlaybackUrl)
|
||||||
|
LogError("No videostatsPlaybackUrl found in response")
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
|
||||||
|
videostatsPlaybackUrl = videostatsPlaybackUrl.replace("https://s.youtube.com", "https://www.youtube.com")
|
||||||
|
queryParams = UrlUtils.ParseQueryComponents(videostatsPlaybackUrl)
|
||||||
|
queryParams["c"] = "TVHTML5"
|
||||||
|
queryParams["cbrver"] = INNERTUBE_TV_CLIENT_VERSION
|
||||||
|
queryParams["cver"] = INNERTUBE_TV_CLIENT_VERSION
|
||||||
|
queryParams["cpn"] = InnertubeService.CreateClientPlaybackNonce()
|
||||||
|
queryParams["fmt"] = "251"
|
||||||
|
queryParams["rtn"] = "0"
|
||||||
|
queryParams["rt"] = "0"
|
||||||
|
queryParams["ver"] = "2"
|
||||||
|
videostatsPlaybackUrl = UrlUtils.SetQueryParams(videostatsPlaybackUrl, queryParams)
|
||||||
|
|
||||||
|
trackingRequest = HttpClient.Get(videostatsPlaybackUrl)
|
||||||
|
trackingRequest.Header("Authorization", "Bearer " + accessToken)
|
||||||
|
|
||||||
|
trackingResponse = trackingRequest.Await()
|
||||||
|
if not trackingResponse.IsSuccess()
|
||||||
|
LogError("Error marking video as watched:", trackingResponse.ErrorMessage())
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
|
||||||
|
LogDebug("Marked video as watched:", videoId)
|
||||||
return true
|
return true
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function CreateClientPlaybackNonce() as string
|
||||||
|
length = 16
|
||||||
|
result = []
|
||||||
|
|
||||||
|
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||||
|
alphabetLen = alphabet.len()
|
||||||
|
for i = 1 to length
|
||||||
|
result.push(alphabet.mid(Rnd(alphabetLen - 1), 1))
|
||||||
|
end for
|
||||||
|
|
||||||
|
return result.join("")
|
||||||
|
end function
|
||||||
|
|
||||||
function GetChannel(channelId as string, options = invalid as object) as object
|
function GetChannel(channelId as string, options = invalid as object) as object
|
||||||
continuation = ""
|
continuation = ""
|
||||||
params = ""
|
params = ""
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import "pkg:/source/utils/Types.bs"
|
|||||||
|
|
||||||
namespace Innertube
|
namespace Innertube
|
||||||
|
|
||||||
function CreatePlayerRequest(videoId as string, ctt as string, visitorData as string) as object
|
function CreatePlayerRequest(videoId as string, ctt as string, visitorData as string, client as Innertube.ClientType) as object
|
||||||
deviceInfo = CreateObject("roDeviceInfo")
|
deviceInfo = CreateObject("roDeviceInfo")
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
"videoId": videoId
|
"videoId": videoId
|
||||||
"context": Innertube.CreateContext(Innertube.ClientType.IOS, deviceInfo, ctt, visitorData)
|
"context": Innertube.CreateContext(client, deviceInfo, ctt, visitorData)
|
||||||
"playbackContext": {
|
"playbackContext": {
|
||||||
"contentPlaybackContext": {
|
"contentPlaybackContext": {
|
||||||
"vis": 0
|
"vis": 0
|
||||||
@@ -36,7 +36,7 @@ namespace Innertube
|
|||||||
"accept": "*/*"
|
"accept": "*/*"
|
||||||
"accept-language": "*"
|
"accept-language": "*"
|
||||||
}
|
}
|
||||||
headers.Append(Innertube.CreateHeaders(Innertube.ClientType.IOS))
|
headers.Append(Innertube.CreateHeaders(client))
|
||||||
request.Headers(headers)
|
request.Headers(headers)
|
||||||
|
|
||||||
return request
|
return request
|
||||||
@@ -92,6 +92,7 @@ namespace Innertube
|
|||||||
end if
|
end if
|
||||||
|
|
||||||
lengthSeconds = videoDetails["lengthSeconds"].ToInt()
|
lengthSeconds = videoDetails["lengthSeconds"].ToInt()
|
||||||
|
|
||||||
videoInfo = {
|
videoInfo = {
|
||||||
"type": "video"
|
"type": "video"
|
||||||
"title": videoDetails["title"]
|
"title": videoDetails["title"]
|
||||||
|
|||||||
Reference in new issue
Block a user