Watching progress (#609)
* Watching progress * watch time endpoint * Lint fix * Changelog * options mandatory * tweak * tweak --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
1 parent
158788b42e
commit
8b123b18f5
14 files changed
+273
-95
No files matched your search
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Watch progress for YouTube accounts: Progress is saved as you watch. Progress bar is shown on video thumbnails (only on user feeds, such as recommendations, subscriptions, and watch history)
|
||||||
|
- Known bug: Watch progress doesn't update for all videos.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- A few issues related to Playlet backend feeds and caching
|
- A few issues related to Playlet backend feeds and caching
|
||||||
|
|||||||
@@ -23,5 +23,6 @@
|
|||||||
<field id="videoId" type="string" />
|
<field id="videoId" type="string" />
|
||||||
<field id="viewCountText" type="string" />
|
<field id="viewCountText" type="string" />
|
||||||
<field id="lines" type="stringarray" />
|
<field id="lines" type="stringarray" />
|
||||||
|
<field id="percentDurationWatched" type="float" />
|
||||||
</interface>
|
</interface>
|
||||||
</component>
|
</component>
|
||||||
@@ -326,7 +326,7 @@ namespace InnertubeService
|
|||||||
return result
|
return result
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function AuthMarkVideoWatched(videoId as string, options as object) as boolean
|
function AuthGetPlaybackTrackingUrls(videoId as string, options as object) as object
|
||||||
cancellation = invalid
|
cancellation = invalid
|
||||||
accessToken = options.accessToken
|
accessToken = options.accessToken
|
||||||
|
|
||||||
@@ -340,43 +340,95 @@ namespace InnertubeService
|
|||||||
|
|
||||||
playerResponse = playerRequest.Await()
|
playerResponse = playerRequest.Await()
|
||||||
if not playerResponse.IsSuccess()
|
if not playerResponse.IsSuccess()
|
||||||
LogError("Error marking video as watched:", playerResponse.ErrorMessage())
|
return {
|
||||||
return false
|
error: playerResponse.ErrorMessage()
|
||||||
end if
|
}
|
||||||
|
|
||||||
if CancellationUtils.IsCancelled(cancellation)
|
|
||||||
return false
|
|
||||||
end if
|
end if
|
||||||
|
|
||||||
json = playerResponse.Json()
|
json = playerResponse.Json()
|
||||||
|
|
||||||
videostatsPlaybackUrl = ObjectUtils.Dig(json, ["playbackTracking", "videostatsPlaybackUrl", "baseUrl"])
|
videostatsPlaybackUrl = ObjectUtils.Dig(json, ["playbackTracking", "videostatsPlaybackUrl", "baseUrl"])
|
||||||
if StringUtils.IsNullOrEmpty(videostatsPlaybackUrl)
|
videostatsWatchtimeUrl = ObjectUtils.Dig(json, ["playbackTracking", "videostatsWatchtimeUrl", "baseUrl"])
|
||||||
LogError("No videostatsPlaybackUrl found in response")
|
|
||||||
return false
|
return {
|
||||||
|
videostatsPlaybackUrl: videostatsPlaybackUrl
|
||||||
|
videostatsWatchtimeUrl: videostatsWatchtimeUrl
|
||||||
|
}
|
||||||
|
end function
|
||||||
|
|
||||||
|
function AuthMarkVideoWatched(videostatsPlaybackUrl as string, options as object) as boolean
|
||||||
|
cancellation = invalid
|
||||||
|
accessToken = options.accessToken
|
||||||
|
|
||||||
|
if options.DoesExist("cancellation")
|
||||||
|
cancellation = options.cancellation
|
||||||
end if
|
end if
|
||||||
|
|
||||||
videostatsPlaybackUrl = videostatsPlaybackUrl.replace("https://s.youtube.com", "https://www.youtube.com")
|
videostatsPlaybackUrl = videostatsPlaybackUrl.replace("https://s.", "https://www.")
|
||||||
queryParams = UrlUtils.ParseQueryComponents(videostatsPlaybackUrl)
|
queryParams = UrlUtils.ParseQueryComponents(videostatsPlaybackUrl)
|
||||||
queryParams["c"] = "TVHTML5"
|
queryParams["c"] = "TVHTML5"
|
||||||
queryParams["cbrver"] = INNERTUBE_TV_CLIENT_VERSION
|
queryParams["cbrver"] = INNERTUBE_TV_CLIENT_VERSION
|
||||||
queryParams["cver"] = 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"
|
queryParams["ver"] = "2"
|
||||||
|
queryParams["cpn"] = InnertubeService.CreateClientPlaybackNonce()
|
||||||
|
queryParams["cmt"] = 0
|
||||||
|
queryParams["final"] = "1"
|
||||||
videostatsPlaybackUrl = UrlUtils.SetQueryParams(videostatsPlaybackUrl, queryParams)
|
videostatsPlaybackUrl = UrlUtils.SetQueryParams(videostatsPlaybackUrl, queryParams)
|
||||||
|
|
||||||
trackingRequest = HttpClient.Get(videostatsPlaybackUrl)
|
request = HttpClient.Get(videostatsPlaybackUrl)
|
||||||
trackingRequest.Header("Authorization", "Bearer " + accessToken)
|
request.Cancellation(cancellation)
|
||||||
|
request.NoCache()
|
||||||
|
request.Headers(Innertube.CreateHeaders(Innertube.ClientType.Tv))
|
||||||
|
request.Header("Authorization", "Bearer " + accessToken)
|
||||||
|
|
||||||
trackingResponse = trackingRequest.Await()
|
response = request.Await()
|
||||||
if not trackingResponse.IsSuccess()
|
if not response.IsSuccess()
|
||||||
LogError("Error marking video as watched:", trackingResponse.ErrorMessage())
|
LogError("Error marking video as watched:", response.ErrorMessage())
|
||||||
return false
|
return false
|
||||||
end if
|
end if
|
||||||
|
|
||||||
LogDebug("Marked video as watched:", videoId)
|
LogDebug("Marked video as watched")
|
||||||
|
return true
|
||||||
|
end function
|
||||||
|
|
||||||
|
function AuthMarkVideoWatchTime(time as float, videostatsWatchtimeUrl as string, options = invalid as object) as boolean
|
||||||
|
cancellation = invalid
|
||||||
|
accessToken = options.accessToken
|
||||||
|
|
||||||
|
if options <> invalid
|
||||||
|
if options.DoesExist("cancellation")
|
||||||
|
cancellation = options.cancellation
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
|
timeStr = time.ToStr("%.3f")
|
||||||
|
|
||||||
|
videostatsWatchtimeUrl = videostatsWatchtimeUrl.replace("https://s.", "https://www.")
|
||||||
|
queryParams = UrlUtils.ParseQueryComponents(videostatsWatchtimeUrl)
|
||||||
|
queryParams["c"] = "TVHTML5"
|
||||||
|
queryParams["cbrver"] = INNERTUBE_TV_CLIENT_VERSION
|
||||||
|
queryParams["cver"] = INNERTUBE_TV_CLIENT_VERSION
|
||||||
|
queryParams["ver"] = "2"
|
||||||
|
queryParams["cpn"] = InnertubeService.CreateClientPlaybackNonce()
|
||||||
|
queryParams["cmt"] = 0
|
||||||
|
queryParams["final"] = "1"
|
||||||
|
queryParams["st"] = timeStr
|
||||||
|
queryParams["et"] = timeStr
|
||||||
|
videostatsWatchtimeUrl = UrlUtils.SetQueryParams(videostatsWatchtimeUrl, queryParams)
|
||||||
|
|
||||||
|
request = HttpClient.Get(videostatsWatchtimeUrl)
|
||||||
|
request.Cancellation(cancellation)
|
||||||
|
request.NoCache()
|
||||||
|
request.Headers(Innertube.CreateHeaders(Innertube.ClientType.Tv))
|
||||||
|
request.Header("Authorization", "Bearer " + accessToken)
|
||||||
|
|
||||||
|
response = request.Await()
|
||||||
|
if not response.IsSuccess()
|
||||||
|
LogError("Error marking video watch time:", response.ErrorMessage())
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
|
||||||
|
LogDebug("Marked video watch time:", timeStr)
|
||||||
return true
|
return true
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|||||||
@@ -970,6 +970,7 @@ namespace Innertube
|
|||||||
lengthText = ""
|
lengthText = ""
|
||||||
isUpcoming = false
|
isUpcoming = false
|
||||||
liveNow = false
|
liveNow = false
|
||||||
|
percentDurationWatched = 0
|
||||||
thumbnailOverlays = ObjectUtils.Dig(nodeData, ["header", "tileHeaderRenderer", "thumbnailOverlays"])
|
thumbnailOverlays = ObjectUtils.Dig(nodeData, ["header", "tileHeaderRenderer", "thumbnailOverlays"])
|
||||||
if IsArray(thumbnailOverlays)
|
if IsArray(thumbnailOverlays)
|
||||||
for each overlay in thumbnailOverlays
|
for each overlay in thumbnailOverlays
|
||||||
@@ -977,6 +978,10 @@ namespace Innertube
|
|||||||
if maybeLengthText <> ""
|
if maybeLengthText <> ""
|
||||||
lengthText = maybeLengthText
|
lengthText = maybeLengthText
|
||||||
end if
|
end if
|
||||||
|
maybePercentDurationWatched = ObjectUtils.Dig(overlay, ["thumbnailOverlayResumePlaybackRenderer", "percentDurationWatched"])
|
||||||
|
if maybePercentDurationWatched <> invalid
|
||||||
|
percentDurationWatched = maybePercentDurationWatched
|
||||||
|
end if
|
||||||
liveNow = liveNow or (ValidString(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "style"])) = "LIVE")
|
liveNow = liveNow or (ValidString(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "style"])) = "LIVE")
|
||||||
isUpcoming = isUpcoming or (ValidString(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "style"])) = "UPCOMING")
|
isUpcoming = isUpcoming or (ValidString(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "style"])) = "UPCOMING")
|
||||||
end for
|
end for
|
||||||
@@ -1005,6 +1010,7 @@ namespace Innertube
|
|||||||
"liveNow": liveNow
|
"liveNow": liveNow
|
||||||
"isUpcoming": isUpcoming
|
"isUpcoming": isUpcoming
|
||||||
"lines": renderedLines
|
"lines": renderedLines
|
||||||
|
"percentDurationWatched": percentDurationWatched
|
||||||
}
|
}
|
||||||
|
|
||||||
PushFeedItem(video, context)
|
PushFeedItem(video, context)
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ namespace Invidious
|
|||||||
return instance
|
return instance
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function MarkVideoWatched(videoId as dynamic) as void
|
function MarkVideoWatched(videoId as dynamic, cancellation = invalid as object) as void
|
||||||
if StringUtils.IsNullOrEmpty(videoId)
|
if StringUtils.IsNullOrEmpty(videoId)
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
@@ -98,6 +98,7 @@ namespace Invidious
|
|||||||
url = `${authToken.instance}${Invidious.HISTORY_ENDPOINT}/${videoId}`
|
url = `${authToken.instance}${Invidious.HISTORY_ENDPOINT}/${videoId}`
|
||||||
request = HttpClient.Post(url, "")
|
request = HttpClient.Post(url, "")
|
||||||
request.Headers(m.GetAuthenticationHeaders(authToken.token))
|
request.Headers(m.GetAuthenticationHeaders(authToken.token))
|
||||||
|
request.Cancellation(cancellation)
|
||||||
request.Await()
|
request.Await()
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ namespace InvidiousContent
|
|||||||
node.viewCountText = VideoGetViewCountText(item)
|
node.viewCountText = VideoGetViewCountText(item)
|
||||||
SetIfExists(node, "index", item, "index")
|
SetIfExists(node, "index", item, "index")
|
||||||
SetIfExists(node, "lines", item, "lines")
|
SetIfExists(node, "lines", item, "lines")
|
||||||
|
SetIfExists(node, "percentDurationWatched", item, "percentDurationWatched")
|
||||||
|
|
||||||
return node
|
return node
|
||||||
end function
|
end function
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import "pkg:/source/utils/Locale.bs"
|
import "pkg:/source/utils/Locale.bs"
|
||||||
|
import "pkg:/source/utils/MathUtils.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"
|
||||||
import "pkg:/source/utils/Types.bs"
|
import "pkg:/source/utils/Types.bs"
|
||||||
@@ -8,6 +9,7 @@ function Init()
|
|||||||
m.durationLabel = m.top.FindNode("durationLabel")
|
m.durationLabel = m.top.FindNode("durationLabel")
|
||||||
m.smallestSystemFont = m.top.FindNode("smallestSystemFont")
|
m.smallestSystemFont = m.top.FindNode("smallestSystemFont")
|
||||||
m.smallestBoldSystemFont = m.top.FindNode("smallestBoldSystemFont")
|
m.smallestBoldSystemFont = m.top.FindNode("smallestBoldSystemFont")
|
||||||
|
m.progressRect = m.top.FindNode("progressRect")
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnContentSet() as void
|
function OnContentSet() as void
|
||||||
@@ -53,6 +55,8 @@ function OnContentSet() as void
|
|||||||
|
|
||||||
m.top.thumbnailUri = content.thumbnail
|
m.top.thumbnailUri = content.thumbnail
|
||||||
|
|
||||||
|
m.top.percentDurationWatched = content.percentDurationWatched
|
||||||
|
|
||||||
if not StringUtils.IsNullOrEmpty(content.lengthText)
|
if not StringUtils.IsNullOrEmpty(content.lengthText)
|
||||||
SetDurationLabel(content.lengthText, "#161616FF", 0.8, m.smallestSystemFont)
|
SetDurationLabel(content.lengthText, "#161616FF", 0.8, m.smallestSystemFont)
|
||||||
m.top.durationRectVisible = true
|
m.top.durationRectVisible = true
|
||||||
@@ -90,3 +94,11 @@ function SetDurationLabel(text as string, bgColor as string, bgOpacity as float,
|
|||||||
rect.opacity = bgOpacity
|
rect.opacity = bgOpacity
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function OnPercentDurationWatched() as void
|
||||||
|
if m.progressRect = invalid
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
percent = MathUtils.Clamp(m.top.percentDurationWatched, 0, 100) / 100.0
|
||||||
|
m.progressRect.scale = [percent, 1]
|
||||||
|
end function
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
<field id="durationRectVisible" type="boolean" alias="durationRect.visible" />
|
<field id="durationRectVisible" type="boolean" alias="durationRect.visible" />
|
||||||
<field id="duration" type="string" alias="durationLabel.text" />
|
<field id="duration" type="string" alias="durationLabel.text" />
|
||||||
<field id="thumbnailUri" type="string" alias="thumbnail.uri" />
|
<field id="thumbnailUri" type="string" alias="thumbnail.uri" />
|
||||||
|
<field id="percentDurationWatched" type="float" onChange="OnPercentDurationWatched" />
|
||||||
</interface>
|
</interface>
|
||||||
<children>
|
<children>
|
||||||
<Font id="smallestSystemFont" uri="font:SystemFontFile" size="18" />
|
<Font id="smallestSystemFont" uri="font:SystemFontFile" size="18" />
|
||||||
@@ -36,6 +37,14 @@
|
|||||||
font="font:SmallestSystemFont"
|
font="font:SmallestSystemFont"
|
||||||
translation="[8, 0]" />
|
translation="[8, 0]" />
|
||||||
</Rectangle>
|
</Rectangle>
|
||||||
|
<Rectangle
|
||||||
|
id="progressRect"
|
||||||
|
width="350"
|
||||||
|
height="5"
|
||||||
|
color="#FF0000"
|
||||||
|
translation="[0, 192]"
|
||||||
|
scale="[0, 1]">
|
||||||
|
</Rectangle>
|
||||||
</Poster>
|
</Poster>
|
||||||
<Label
|
<Label
|
||||||
id="titleLabel"
|
id="titleLabel"
|
||||||
|
|||||||
@@ -1,12 +1,74 @@
|
|||||||
|
import "pkg:/components/Services/Innertube/InnertubeService.bs"
|
||||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||||
|
import "pkg:/source/utils/MessagePortUtils.bs"
|
||||||
|
|
||||||
@asynctask
|
@asynctask
|
||||||
function MarkVideoWatchedTask(input as object) as object
|
function MarkVideoWatchedTask(input as object) as object
|
||||||
videoId = input.videoId
|
videoId = input.videoId
|
||||||
invidiousNode = input.invidious
|
invidiousNode = input.invidious
|
||||||
|
authToken = input.authToken
|
||||||
|
profileType = input.profileType
|
||||||
|
cancellation = m.top.cancellation
|
||||||
|
|
||||||
service = new Invidious.InvidiousService(invidiousNode)
|
if profileType = "invidious"
|
||||||
service.MarkVideoWatched(videoId)
|
service = new Invidious.InvidiousService(invidiousNode)
|
||||||
|
service.MarkVideoWatched(videoId, cancellation)
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
|
||||||
|
if profileType <> "youtube"
|
||||||
|
LogError("MarkVideoWatchedTask: Unsupported profile type:", profileType)
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
|
||||||
|
playbackTrackingUrls = InnertubeService.AuthGetPlaybackTrackingUrls(videoId, {
|
||||||
|
accessToken: authToken.token
|
||||||
|
cancellation: cancellation
|
||||||
|
})
|
||||||
|
|
||||||
|
if playbackTrackingUrls.error <> invalid
|
||||||
|
LogError("MarkVideoWatchedTask: Failed to get playback tracking URLs:", playbackTrackingUrls.error)
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
|
||||||
|
if StringUtils.IsNullOrEmpty(playbackTrackingUrls.videostatsPlaybackUrl)
|
||||||
|
LogError("MarkVideoWatchedTask: videostatsPlaybackUrl is empty")
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
|
||||||
|
markedAsWatched = InnertubeService.AuthMarkVideoWatched(playbackTrackingUrls.videostatsPlaybackUrl, {
|
||||||
|
accessToken: authToken.token
|
||||||
|
cancellation: cancellation
|
||||||
|
})
|
||||||
|
if not markedAsWatched
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
|
||||||
|
if StringUtils.IsNullOrEmpty(playbackTrackingUrls.videostatsWatchtimeUrl)
|
||||||
|
LogError("MarkVideoWatchedTask: videostatsWatchtimeUrl is empty")
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
|
||||||
|
if CancellationUtils.IsCancelled(cancellation)
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
|
||||||
|
port = CreateObject("roMessagePort")
|
||||||
|
MessagePortUtils.ObserveFieldScopedExSafe(m.top, "watchTime", port)
|
||||||
|
CancellationUtils.ObserveCancellationScoped(cancellation, port)
|
||||||
|
while true
|
||||||
|
message = wait(60000, port)
|
||||||
|
if CancellationUtils.IsCancellationEvent(cancellation, message)
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
if message = invalid
|
||||||
|
continue while
|
||||||
|
end if
|
||||||
|
watchTime = message.getData()
|
||||||
|
InnertubeService.AuthMarkVideoWatchTime(watchTime, playbackTrackingUrls.videostatsWatchtimeUrl, {
|
||||||
|
accessToken: authToken.token
|
||||||
|
cancellation: cancellation
|
||||||
|
})
|
||||||
|
end while
|
||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
@@ -140,7 +140,6 @@ namespace SponsorBlock
|
|||||||
m.top.trickPlayBar.filledBarBlendColor = "#FF000080"
|
m.top.trickPlayBar.filledBarBlendColor = "#FF000080"
|
||||||
end if
|
end if
|
||||||
|
|
||||||
m.top.UnobserveFieldScoped("position")
|
|
||||||
m.top.ObserveFieldScoped("position", FuncName(OnPositionChangeSkipSponsorBlockSections))
|
m.top.ObserveFieldScoped("position", FuncName(OnPositionChangeSkipSponsorBlockSections))
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ function Init()
|
|||||||
m.fullScreenHintTimer.ObserveField("fire", FuncName(OnFullScreenHintTimer))
|
m.fullScreenHintTimer.ObserveField("fire", FuncName(OnFullScreenHintTimer))
|
||||||
m.trickplayUITimer = m.top.findNode("trickplayUITimer")
|
m.trickplayUITimer = m.top.findNode("trickplayUITimer")
|
||||||
m.trickplayUITimer.ObserveField("fire", FuncName(OnTrickplayUITimer))
|
m.trickplayUITimer.ObserveField("fire", FuncName(OnTrickplayUITimer))
|
||||||
|
m.top.notificationInterval = 1
|
||||||
|
|
||||||
' videoPlayingSuccess indicates if we started playing a video successfully
|
' videoPlayingSuccess indicates if we started playing a video successfully
|
||||||
' We use it to detect if we should try another link for a video, or if another error
|
' We use it to detect if we should try another link for a video, or if another error
|
||||||
@@ -126,6 +127,8 @@ function PlayWithContent(contentNode as object)
|
|||||||
end if
|
end if
|
||||||
if ValidInt(contentNode.timestamp) <> -1
|
if ValidInt(contentNode.timestamp) <> -1
|
||||||
videoContentNode.AddFields({ timestamp: contentNode.timestamp })
|
videoContentNode.AddFields({ timestamp: contentNode.timestamp })
|
||||||
|
else if contentNode.percentDurationWatched > 0 and contentNode.percentDurationWatched < 100
|
||||||
|
videoContentNode.AddFields({ percentDurationWatched: contentNode.percentDurationWatched })
|
||||||
end if
|
end if
|
||||||
if not StringUtils.IsNullOrEmpty(contentNode.title)
|
if not StringUtils.IsNullOrEmpty(contentNode.title)
|
||||||
videoContentNode.title = contentNode.title
|
videoContentNode.title = contentNode.title
|
||||||
@@ -144,8 +147,6 @@ function StartVideoContentTask(videoContentNode as object)
|
|||||||
m.videoContentTask.cancel = true
|
m.videoContentTask.cancel = true
|
||||||
end if
|
end if
|
||||||
|
|
||||||
MarkVideoWatched(videoContentNode.videoId)
|
|
||||||
|
|
||||||
m.top.content = videoContentNode
|
m.top.content = videoContentNode
|
||||||
|
|
||||||
m.videoContentTask = AsyncTask.Start(Tasks.VideoContentTask, {
|
m.videoContentTask = AsyncTask.Start(Tasks.VideoContentTask, {
|
||||||
@@ -194,22 +195,25 @@ function OnVideoContentTaskResults(output as object) as void
|
|||||||
SponsorBlock.FetchSponsorBlock(content.metadata)
|
SponsorBlock.FetchSponsorBlock(content.metadata)
|
||||||
|
|
||||||
timestamp = content.timestamp
|
timestamp = content.timestamp
|
||||||
|
percentDurationWatched = content.percentDurationWatched
|
||||||
hasTimestamp = IsInt(timestamp)
|
hasTimestamp = IsInt(timestamp)
|
||||||
|
hasPercentDurationWatched = IsFloat(percentDurationWatched)
|
||||||
|
|
||||||
if IsLiveVideo() and not hasTimestamp
|
if IsLiveVideo() and not hasTimestamp and not hasPercentDurationWatched
|
||||||
duration = m.top.duration
|
' If live, seek to end of stream
|
||||||
if duration > 0
|
m.seekToPercent = 100.0
|
||||||
SeekToEndOfStream()
|
SeekToPercentOfDuration()
|
||||||
else
|
else
|
||||||
m.top.ObserveField("duration", FuncName(SeekToEndOfStream))
|
if hasTimestamp and timestamp > 0
|
||||||
|
m.top.seek = content.timestamp
|
||||||
|
else if hasPercentDurationWatched
|
||||||
|
m.seekToPercent = percentDurationWatched
|
||||||
|
SeekToPercentOfDuration()
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
|
|
||||||
PlayAfterPreviousPlayerHasStopped()
|
PlayAfterPreviousPlayerHasStopped()
|
||||||
|
MarkVideoWatched(content.videoId)
|
||||||
if hasTimestamp and timestamp > 0
|
|
||||||
m.top.seek = content.timestamp
|
|
||||||
end if
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function PlayAfterPreviousPlayerHasStopped() as void
|
function PlayAfterPreviousPlayerHasStopped() as void
|
||||||
@@ -272,12 +276,48 @@ function MarkVideoWatched(videoId as dynamic) as void
|
|||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if m.top.invidious.authToken <> invalid
|
invidious = m.top.invidious
|
||||||
AsyncTask.Start(Tasks.MarkVideoWatchedTask, {
|
authToken = invidious.authToken
|
||||||
videoId: videoId
|
if authToken = invalid
|
||||||
invidious: m.top.invidious
|
return
|
||||||
})
|
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
if m.markVideoWatchedTask <> invalid
|
||||||
|
m.markVideoWatchedTask.cancel = true
|
||||||
|
end if
|
||||||
|
|
||||||
|
profileType = authToken.profileNode.type
|
||||||
|
m.markVideoWatchedTask = AsyncTask.Create(Tasks.MarkVideoWatchedTask, {
|
||||||
|
videoId: videoId
|
||||||
|
invidious: invidious
|
||||||
|
authToken: authToken
|
||||||
|
profileType: profileType
|
||||||
|
})
|
||||||
|
m.markVideoWatchedTask.addField("watchTime", "float", false)
|
||||||
|
m.markVideoWatchedTask.control = "RUN"
|
||||||
|
|
||||||
|
if profileType <> "youtube"
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
' Progress reported to Innertube. It is the position in seconds,
|
||||||
|
' with 20 second steps.
|
||||||
|
m.watchTimeMarker = -1
|
||||||
|
m.top.ObserveFieldScoped("position", FuncName(OnPositionChangeMarkWatchTime))
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnPositionChangeMarkWatchTime() as void
|
||||||
|
if m.markVideoWatchedTask = invalid
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
currentPosition = m.top.position
|
||||||
|
currentWatchTimeMarker = m.watchTimeMarker
|
||||||
|
m.watchTimeMarker = (currentPosition \ 20) * 20
|
||||||
|
if currentWatchTimeMarker = currentPosition
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
m.markVideoWatchedTask.watchTime = m.watchTimeMarker
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnClose()
|
function OnClose()
|
||||||
@@ -285,6 +325,10 @@ function OnClose()
|
|||||||
|
|
||||||
m.top.previousPlayer = invalid
|
m.top.previousPlayer = invalid
|
||||||
|
|
||||||
|
if m.markVideoWatchedTask <> invalid
|
||||||
|
m.markVideoWatchedTask.cancel = true
|
||||||
|
m.markVideoWatchedTask = invalid
|
||||||
|
end if
|
||||||
if m.videoContentTask <> invalid
|
if m.videoContentTask <> invalid
|
||||||
m.videoContentTask.cancel = true
|
m.videoContentTask.cancel = true
|
||||||
m.videoContentTask = invalid
|
m.videoContentTask = invalid
|
||||||
@@ -408,13 +452,43 @@ function OnVideoPlayerStateChange() as void
|
|||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function SeekToEndOfStream()
|
function SeekToEndOfStream() as void
|
||||||
m.top.UnobserveField("duration")
|
m.top.UnobserveField("duration")
|
||||||
duration = m.top.duration
|
duration = m.top.duration
|
||||||
' If the stream is less than 30 seconds, it's not worth seeking to the end
|
' If the stream is less than 30 seconds, it's not worth seeking
|
||||||
if duration > 30
|
if duration < 30
|
||||||
LogInfo("Seeking to end of live stream", duration)
|
return
|
||||||
m.top.seek = duration
|
end if
|
||||||
|
|
||||||
|
LogInfo("Seeking to end of live stream", duration)
|
||||||
|
m.top.seek = duration
|
||||||
|
end function
|
||||||
|
|
||||||
|
function SeekToPercentOfDuration() as void
|
||||||
|
m.top.UnobserveField("duration")
|
||||||
|
|
||||||
|
seekToPercent = m.seekToPercent
|
||||||
|
if seekToPercent = invalid
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
m.seekToPercent = invalid
|
||||||
|
|
||||||
|
duration = m.top.duration
|
||||||
|
if duration = 0
|
||||||
|
' If the duration is not available, wait for it to be set
|
||||||
|
m.top.ObserveField("duration", FuncName(SeekToPercentOfDuration))
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
' If the stream is less than 30 seconds, it's not worth seeking
|
||||||
|
if duration < 30
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
seek = (MathUtils.Clamp(seekToPercent, 0, 100) / 100.0) * duration
|
||||||
|
if seek > 0
|
||||||
|
LogInfo("Seeking to percent duration watched", seek)
|
||||||
|
m.top.seek = seek
|
||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|||||||
+1
-46
@@ -213,49 +213,6 @@ namespace Http
|
|||||||
return true
|
return true
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function AuthMarkVideoWatched(context as object) as boolean
|
|
||||||
request = context.request
|
|
||||||
response = context.response
|
|
||||||
route = request.route
|
|
||||||
|
|
||||||
accessToken = request.headers["authorization"]
|
|
||||||
if StringUtils.IsNullOrEmpty(accessToken) or not accessToken.StartsWith("Bearer ")
|
|
||||||
response.Json({
|
|
||||||
"error": "Missing or invalid 'Authorization' header"
|
|
||||||
})
|
|
||||||
response.http_code = 403
|
|
||||||
return true
|
|
||||||
end if
|
|
||||||
|
|
||||||
videoId = route.Mid("/playlet-invidious-backend/api/v1/auth/history/".Len())
|
|
||||||
if videoId.InStr("?") > 0
|
|
||||||
videoId = videoId.Left(videoId.InStr("?"))
|
|
||||||
end if
|
|
||||||
|
|
||||||
if StringUtils.IsNullOrEmpty(videoId)
|
|
||||||
response.Json({
|
|
||||||
"error": "Missing 'videoId' path parameter"
|
|
||||||
})
|
|
||||||
response.http_code = 400
|
|
||||||
return true
|
|
||||||
end if
|
|
||||||
|
|
||||||
options = {
|
|
||||||
"accessToken": accessToken.Mid("Bearer ".Len())
|
|
||||||
}
|
|
||||||
|
|
||||||
if not InnertubeService.AuthMarkVideoWatched(videoId, options)
|
|
||||||
response.Json({
|
|
||||||
"error": "Failed to mark video as watched"
|
|
||||||
})
|
|
||||||
response.http_code = 500
|
|
||||||
return true
|
|
||||||
end if
|
|
||||||
|
|
||||||
response.Default(204, "OK")
|
|
||||||
return true
|
|
||||||
end function
|
|
||||||
|
|
||||||
@get("/playlet-invidious-backend/api/v1/stats")
|
@get("/playlet-invidious-backend/api/v1/stats")
|
||||||
function GetStats(context as object) as boolean
|
function GetStats(context as object) as boolean
|
||||||
response = context.response
|
response = context.response
|
||||||
@@ -562,9 +519,7 @@ namespace Http
|
|||||||
request = context.request
|
request = context.request
|
||||||
route = request.route
|
route = request.route
|
||||||
|
|
||||||
if route.StartsWith("/playlet-invidious-backend/api/v1/auth/history/")
|
if route.StartsWith("/playlet-invidious-backend/api/v1/auth/subscriptions/")
|
||||||
return m.AuthMarkVideoWatched(context)
|
|
||||||
else if route.StartsWith("/playlet-invidious-backend/api/v1/auth/subscriptions/")
|
|
||||||
return m.SubscribeToChannel(context)
|
return m.SubscribeToChannel(context)
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace MessagePortUtils
|
namespace MessagePortUtils
|
||||||
|
|
||||||
function ObserveFieldScopedExSafe(node as dynamic, field as string, port as dynamic)
|
function ObserveFieldScopedExSafe(node as dynamic, field as string, port as dynamic) as void
|
||||||
' ObserveFieldScopedEx was added in 12.0
|
' ObserveFieldScopedEx was added in 12.0
|
||||||
if FindMemberFunction(node, "ObserveFieldScopedEx") <> invalid
|
if FindMemberFunction(node, "ObserveFieldScopedEx") <> invalid
|
||||||
' bs:disable-next-line NO_OBSERVE_FIELD_SCOPED_EX
|
' bs:disable-next-line NO_OBSERVE_FIELD_SCOPED_EX
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ import { CompilerPlugin, Program, SourceObj } from "brighterscript";
|
|||||||
|
|
||||||
const types = [
|
const types = [
|
||||||
{ name: 'Bool', interface: 'ifBoolean', type: 'boolean', defaultValue: 'false' },
|
{ name: 'Bool', interface: 'ifBoolean', type: 'boolean', defaultValue: 'false' },
|
||||||
{ name: 'Int', interface: 'ifInt', type: 'integer', defaultValue: '0' },
|
{ name: 'Int', interface: 'ifInt', type: 'integer', defaultValue: '0%' },
|
||||||
|
{ name: 'Float', interface: 'ifFloat', type: 'float', defaultValue: '0!' },
|
||||||
{ name: 'Double', interface: 'ifDouble', type: 'double', defaultValue: '0#' },
|
{ name: 'Double', interface: 'ifDouble', type: 'double', defaultValue: '0#' },
|
||||||
{ name: 'String', interface: 'ifString', type: 'string', defaultValue: '""' },
|
{ name: 'String', interface: 'ifString', type: 'string', defaultValue: '""' },
|
||||||
{ name: 'Array', interface: 'ifArray', type: 'object', defaultValue: '[]' },
|
{ name: 'Array', interface: 'ifArray', type: 'object', defaultValue: '[]' },
|
||||||
|
|||||||
Reference in new issue
Block a user