Fix for watch progress

This commit is contained in:
Brahim Hadriche committed 2026-03-10 21:07:36 -04:00
1 parent 58fe601b25
commit 7227d4e26b
5 files changed
+44 -19

No files matched your search

@@ -11,6 +11,7 @@ function ExecuteJob() as void
authToken = input.authToken
profileType = input.profileType
playbackTrackingUrls = input.playbackTrackingUrls
cpn = input.cpn
cancellation = JobGetCancellation()
@@ -43,9 +44,14 @@ function ExecuteJob() as void
return
end if
if StringUtils.IsNullOrEmpty(cpn)
cpn = InnertubeService.CreateClientPlaybackNonce()
end if
markedAsWatched = InnertubeService.AuthMarkVideoWatched(playbackTrackingUrls.videostatsPlaybackUrl, {
accessToken: authToken.token
onBehalfOfUser: authToken.activeIdentifyToken
cpn: cpn
cancellation: cancellation
})
if not markedAsWatched
@@ -68,6 +74,7 @@ function ExecuteJob() as void
MessagePortUtils.ObserveFieldScopedExSafe(callbackNode, "watchTime", port)
CancellationUtils.ObserveCancellationScoped(cancellation, port)
successiveFailures = 0
lastReportedTime = 0.0
while true
message = wait(60000, port)
if CancellationUtils.IsCancellationEvent(cancellation, message)
@@ -90,16 +97,27 @@ function ExecuteJob() as void
end while
watchTime = message.getData()
success = InnertubeService.AuthMarkVideoWatchTime(watchTime, playbackTrackingUrls.videostatsWatchtimeUrl, {
' On seek-back, clamp st to not exceed et - I don't know if we really need to
if lastReportedTime > watchTime
lastReportedTime = watchTime - 20
if lastReportedTime < 0
lastReportedTime = 0
end if
end if
success = InnertubeService.AuthMarkVideoWatchTime(lastReportedTime, watchTime, playbackTrackingUrls.videostatsWatchtimeUrl, {
accessToken: authToken.token
onBehalfOfUser: authToken.activeIdentifyToken
cpn: cpn
' TODO:P1 if we pass cancellation here, http client will remove scoped
' observer, which is stored on the current node.
' This requires an extra observer node to be independent.
cmt: lastReportedTime
cancellation: invalid
})
if success
successiveFailures = 0
lastReportedTime = watchTime
else
successiveFailures += 1
end if
@@ -226,7 +226,7 @@ function OnVideoContentJobDone(event as object) as void
SeekToInitialPosition(content)
PlayAfterPreviousPlayerHasStopped()
MarkVideoWatched(content.videoId, metadata.playbackTrackingUrls)
MarkVideoWatched(content.videoId, metadata.playbackTrackingUrls, metadata.cpn)
end function
function SeekToInitialPosition(content as object) as void
@@ -345,7 +345,7 @@ function OnVideoContentJobErrorDialogResponse(event as object)
Lounge.SendOnStateChange()
end function
function MarkVideoWatched(videoId as dynamic, playbackTrackingUrls as dynamic) as void
function MarkVideoWatched(videoId as dynamic, playbackTrackingUrls as dynamic, cpn as dynamic) as void
if StringUtils.IsNullOrEmpty(videoId)
return
end if
@@ -368,6 +368,7 @@ function MarkVideoWatched(videoId as dynamic, playbackTrackingUrls as dynamic) a
authToken: authToken
profileType: profileType
playbackTrackingUrls: playbackTrackingUrls
cpn: cpn
}
m.markVideoWatchedJob = JobSystem.CreateCallback()