Fresh start (#110)
* Fresh start * Create an xml include plugin (#111) * Restructure and add testing (#114) * rooibos setup * Restructure and add testing * docs * Restore manifestpipi * Description in tools * A bit of docs * Auto bind feature (#115) * Auto bind feature * Fix children merge * bs plugin fix * Feature/app controller (#120) * Initial layout * Restructuring and plugin work * A couple of tweaks in binding stuff * tweaks * basic stack * Add basic app controller * Support json5/yaml in playlet config files (#123) * Support json5 in playlet config files * Add yaml to the mix * Delete old lib project * plugin fix * plugin tweak * verbose logging * Revert "verbose logging" This reverts commit 25867f4226703d83102519a0d48d1cc46a9876de. * One idea to fix the include plugin * Fix instability in plugins * Feature/navbar (#126) * Navbar * typo * comment * Single content node, and tests * Remove unused field * tweaks * update dependencies command * tweak formatting * Add web app screen * Set id in created screens * Search screen * Tests * Show playlists and channels in search results * Move screen stuff to app controller * Home screen (wip) * Add preferences node * README.md copyedits (#130) * README.md: Fix typos * README.md: Standardize capitalization and punctuation * Update docs/README.md --------- Co-authored-by: Brahim Hadriche <brahim.hadriche@gmail.com> * Web server: round 1 (#131) * web server object * Logging * Web server round 1 * Lint fix * Small tweaks --------- Co-authored-by: github-action linter <githubaction@githubaction.com> * Logging to file * Leftover * Add logs file to web server * Fix for timeout * Disable keepalive connection * add openapi spec file * Lint fix * add prefs version in api * Add ecp api definition * Lint fix * Settings rework (#135) * Settings rework * Standard OnFocusChange event * Video player stuff (#136) * Video player stuff * Restructure things so that focus is better handled * Lint fix --------- Co-authored-by: github-action linter <githubaction@githubaction.com> * Exit dialog * A bunch of changes * New http client * Set TODO priorities * picture in picture * mark video watched * Video player stuff mostly there * update spec file * Sponsorblock * FuncName * SponsorBlock notifications * Lint fix * misc * remove basic auth feature flag (until we start using it) * Play queue part 1 * type fix * handle unicode in request body * SponsorBlock chapter label * modal base * remove a hack * Invidious settings * web server reduce timeout * Test for captions * Lint fix * remove rpc stuff * small change * Solve focus management * a couple of fixes * Remove a bunch of todos * feed error handling wip * Lint fix * navigation in instance settings * home screen pagination support * Refactor feed to support pagination on search page * cell loading animation * Tweak caching * delete test screen * playlist support part 1 * Basic playlist view * Restore playlist/channel handler * Refactor some content node stuff, and add an auth popup dialog * A bad implementation of a playqueue * Lint fix * playlist cast fix * Feature/web app catch up (#139) * playlist cast fix * Move things around * support playlists in web app * update api * Bump deps * Downgrade todo --------- Co-authored-by: Bryce Harrington <bryce@bryceharrington.org> Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
349 files changed
+12784
-7660
No files matched your search
@@ -1,11 +1,12 @@
|
||||
import "pkg:/source/services/Invidious.bs"
|
||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||
|
||||
@asynctask
|
||||
function MarkVideoWatchedTask(input as object) as object
|
||||
videoId = input.videoId
|
||||
invidiousNode = input.invidious
|
||||
|
||||
success = Invidious.MarkVideoWatched(videoId)
|
||||
return {
|
||||
success: success
|
||||
}
|
||||
service = new Invidious.InvidiousService(invidiousNode)
|
||||
service.MarkVideoWatched(videoId)
|
||||
|
||||
return invalid
|
||||
end function
|
||||
@@ -0,0 +1,165 @@
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/components/Services/SponsorBlock/SponsorBlockTask.bs"
|
||||
import "pkg:/components/Services/SponsorBlock/SponsorBlockSegmentViewedTask.bs"
|
||||
import "pkg:/components/Services/SponsorBlock/Notifications/SponsorBlockNotificationUtils.bs"
|
||||
|
||||
namespace SponsorBlock
|
||||
|
||||
function SetupSponsorBlock() as void
|
||||
if not m.preferences["sponsorblock.enabled"]
|
||||
return
|
||||
end if
|
||||
|
||||
m.sponsorBlockService = new SponsorBlock.SponsorBlockService()
|
||||
|
||||
PositionChapterLabel()
|
||||
m.top.trickPlayBar.observeField("visible", FuncName(OnTrickPlayBarVisible))
|
||||
m.chapterLabelTimer = m.top.findNode("chapterLabelTimer")
|
||||
m.chapterLabelTimer.observeField("fire", FuncName(OnChapterLabelTimer))
|
||||
m._sponsorBlockLastTime = 0.0#
|
||||
|
||||
' TODO:P1 more precision on when notifications should be visible
|
||||
' Should notifcations be visible when the video is not fullscreen?
|
||||
SponsorBlock.SetVisible(m.notifications, m.container.fullscreen)
|
||||
end function
|
||||
|
||||
function PositionChapterLabel()
|
||||
m.chapterLabel = m.top.findNode("chapterLabel")
|
||||
' We move the chapter label under m.top.trickPlayBar
|
||||
' We could move it to m.top.pivotNode, but that is only available on Roku OS 11.5+
|
||||
m.chapterLabel.reparent(m.top.trickPlayBar, false)
|
||||
trickPlayBarWidth = m.top.trickPlayBar.boundingRect().width
|
||||
m.chapterLabel.translation = [trickPlayBarWidth / 4 - m.chapterLabel.width / 2, 25]
|
||||
end function
|
||||
|
||||
function OnTrickPlayBarVisible()
|
||||
if m.top.trickPlayBar.visible
|
||||
m.top.chapter = ""
|
||||
m.chapterLabelTimer.control = "start"
|
||||
else
|
||||
m.chapterLabelTimer.control = "stop"
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnChapterLabelTimer() as void
|
||||
if m.skipSegments = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
' trickPlayPosition is not documented on Roku website, this is why we're checking
|
||||
if not IsDouble(m.top.trickPlayPosition)
|
||||
return
|
||||
end if
|
||||
|
||||
if m._sponsorBlockLastTime = m.top.trickPlayPosition
|
||||
return
|
||||
end if
|
||||
|
||||
m._sponsorBlockLastTime = m.top.trickPlayPosition
|
||||
|
||||
UpdateSponsorBlockChapter(m._sponsorBlockLastTime)
|
||||
end function
|
||||
|
||||
function UpdateSponsorBlockChapter(time as double) as void
|
||||
segments = m.skipSegments
|
||||
for each segment in segments
|
||||
segmentRange = segment["segment"]
|
||||
segmentStart = segmentRange[0]
|
||||
segmentEnd = segmentRange[1]
|
||||
|
||||
if (segmentStart <= time) and (segmentEnd >= time)
|
||||
m.top.chapter = m.sponsorBlockService.SegmentTitle(segment["category"])
|
||||
return
|
||||
end if
|
||||
end for
|
||||
m.top.chapter = ""
|
||||
end function
|
||||
|
||||
function FetchSponsorBlock(metadata as object) as void
|
||||
if not m.preferences["sponsorblock.enabled"]
|
||||
return
|
||||
end if
|
||||
|
||||
if m.sponsorBlockTask <> invalid
|
||||
m.sponsorBlockTask.cancel = true
|
||||
end if
|
||||
|
||||
m.sponsorBlockTask = StartAsyncTask(SponsorBlockTask, { metadata: metadata }, OnSponsorBlockTaskResults)
|
||||
end function
|
||||
|
||||
function OnSponsorBlockTaskResults(output as object) as void
|
||||
m.sponsorBlockTask = invalid
|
||||
if output.cancelled
|
||||
return
|
||||
end if
|
||||
|
||||
if not output.success
|
||||
error = ErrorUtils.Format(output.error)
|
||||
m.log.error(error)
|
||||
return
|
||||
end if
|
||||
|
||||
skipSegments = output.result.skipSegments
|
||||
if skipSegments = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
m.skipSegments = skipSegments
|
||||
m.top.seekMode = "accurate"
|
||||
|
||||
barPath = output.result.barPath
|
||||
if barPath <> invalid
|
||||
m.top.trickPlayBar.trackImageUri = barPath
|
||||
m.top.trickPlayBar.filledBarBlendColor = "0xFF000080"
|
||||
end if
|
||||
|
||||
m.top.UnobserveFieldScoped("position")
|
||||
m.top.ObserveFieldScoped("position", FuncName(OnPositionChangeSkipSponsorBlockSections))
|
||||
end function
|
||||
|
||||
function OnPositionChangeSkipSponsorBlockSections() as void
|
||||
segments = m.skipSegments
|
||||
if segments = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
for each segment in segments
|
||||
segmentRange = segment["segment"]
|
||||
segmentStart = segmentRange[0]
|
||||
segmentEnd = segmentRange[1]
|
||||
currentPosition = m.top.position
|
||||
if (segmentStart < currentPosition) and ((segmentEnd - 1) > currentPosition)
|
||||
action = GetActionForSegment(segment)
|
||||
if m.preferences["sponsorblock.show_notifications"] = true
|
||||
SponsorBlock.ShowNotifcation(m.notifications, segment, action)
|
||||
end if
|
||||
|
||||
if action = "AutoSkip"
|
||||
m.top.seek = segmentEnd
|
||||
m.log.info("Skipping section:", segment["category"])
|
||||
SendSkippedSectionEvent(segment.UUID)
|
||||
return
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
end function
|
||||
|
||||
function GetActionForSegment(segment as object) as dynamic
|
||||
category = segment["category"]
|
||||
if category = "sponsor"
|
||||
return "AutoSkip"
|
||||
else if category = "poi_highlight"
|
||||
return "ManualSkip"
|
||||
else if category = "exclusive_access"
|
||||
return "ShowOverlay"
|
||||
else if category = "chapter"
|
||||
return "ShowOverlay"
|
||||
end if
|
||||
return ""
|
||||
end function
|
||||
|
||||
function SendSkippedSectionEvent(segmentId as string)
|
||||
StartAsyncTask(SponsorBlockSegmentViewedTask, { segmentId: segmentId })
|
||||
end function
|
||||
|
||||
end namespace
|
||||
@@ -1,21 +0,0 @@
|
||||
import "pkg:/source/services/SponsorBlock.bs"
|
||||
|
||||
@asynctask
|
||||
function SponsorBlockTask(input as object) as object
|
||||
videoId = input.videoId
|
||||
lengthSeconds = input.metadata.lengthSeconds
|
||||
|
||||
skipSegments = SponsorBlock.GetSkipSegmentsForVideo(videoId)
|
||||
barPath = invalid
|
||||
|
||||
if skipSegments <> invalid
|
||||
barPath = `tmp:/sponsorblock_bar_${videoId}.png`
|
||||
SponsorBlock.GenerateProgressBarBackground(skipSegments, lengthSeconds, barPath)
|
||||
end if
|
||||
|
||||
return {
|
||||
videoId: videoId,
|
||||
skipSegments: skipSegments,
|
||||
barPath: barPath
|
||||
}
|
||||
end function
|
||||
@@ -1,9 +0,0 @@
|
||||
import "pkg:/source/services/SponsorBlock.bs"
|
||||
|
||||
@asynctask
|
||||
function SponsorBlockTrackingTask(input as object)
|
||||
input = m.top.getField("input")
|
||||
segmentId = input.segmentId
|
||||
|
||||
SponsorBlock.PostSegmentViewed(segmentId)
|
||||
end function
|
||||
@@ -1,97 +0,0 @@
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/source/services/Invidious.bs"
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
import "pkg:/components/SponsorBlockNotification/SponsorBlockNotificationManager.bs"
|
||||
import "pkg:/components/VideoPlayer/MarkVideoWatchedTask.bs"
|
||||
|
||||
function PlayVideo(videoId as string, args = invalid as object)
|
||||
sender = args?.sender
|
||||
metadata = args?.metadata
|
||||
timestamp = args?.timestamp
|
||||
|
||||
if metadata <> invalid and GetInterface(metadata, "ifSGNodeField") <> invalid
|
||||
metadata = args.metadata.getFields()
|
||||
end if
|
||||
|
||||
if timestamp = invalid
|
||||
timestamp = 0
|
||||
end if
|
||||
|
||||
width = 1280
|
||||
height = 720
|
||||
translation = [0.0, 0.0]
|
||||
videoContainer = GetVideoContainer()
|
||||
if videoContainer.videoPlayer <> invalid
|
||||
width = videoContainer.videoPlayer.width
|
||||
height = videoContainer.videoPlayer.height
|
||||
translation = videoContainer.videoPlayer.translation
|
||||
end if
|
||||
previousSender = videoContainer.sender
|
||||
CloseVideo(false)
|
||||
if sender <> invalid
|
||||
videoContainer.sender = sender
|
||||
else
|
||||
videoContainer.sender = previousSender
|
||||
end if
|
||||
videoContainer.videoPlayer = videoContainer.createChild("VideoPlayer")
|
||||
videoContainer.insertChild(videoContainer.videoPlayer, 0)
|
||||
videoContainer.videoPlayer.id = "VideoPlayer"
|
||||
videoContainer.videoPlayer.metadata = metadata
|
||||
videoContainer.videoPlayer.timestamp = timestamp
|
||||
videoContainer.videoPlayer.videoId = videoId
|
||||
videoContainer.videoPlayer.width = width
|
||||
videoContainer.videoPlayer.height = height
|
||||
videoContainer.videoPlayer.translation = translation
|
||||
|
||||
if videoContainer.fullscreen
|
||||
videoContainer.videoPlayer.SetFocus(true)
|
||||
end if
|
||||
|
||||
StartAsyncTask(MarkVideoWatchedTask, { videoId: videoId })
|
||||
end function
|
||||
|
||||
function CloseVideo(setFocus = true as boolean)
|
||||
videoContainer = GetVideoContainer()
|
||||
if videoContainer.videoPlayer <> invalid
|
||||
videoContainer.videoPlayer.control = "stop"
|
||||
videoContainer.RemoveChild(videoContainer.videoPlayer)
|
||||
videoContainer.videoPlayer = invalid
|
||||
end if
|
||||
if setFocus and videoContainer.sender <> invalid
|
||||
if videoContainer.sender.hasField("focus")
|
||||
videoContainer.sender.focus = true
|
||||
else
|
||||
videoContainer.sender.SetFocus(true)
|
||||
end if
|
||||
end if
|
||||
videoContainer.sender = invalid
|
||||
SponsorBlockNotifcationSetVisible(false)
|
||||
end function
|
||||
|
||||
function ToggleVideoPictureInPicture(sender = invalid as object) as boolean
|
||||
videoContainer = GetVideoContainer()
|
||||
if videoContainer.videoPlayer = invalid
|
||||
return false
|
||||
end if
|
||||
videoContainer.fullscreen = not videoContainer.fullscreen
|
||||
if sender <> invalid
|
||||
videoContainer.sender = sender
|
||||
end if
|
||||
if videoContainer.fullscreen
|
||||
videoContainer.videoPlayer.SetFocus(true)
|
||||
else
|
||||
if videoContainer.sender <> invalid
|
||||
if videoContainer.sender.hasField("focus")
|
||||
videoContainer.sender.focus = true
|
||||
else
|
||||
videoContainer.sender.SetFocus(true)
|
||||
end if
|
||||
end if
|
||||
videoContainer.sender = invalid
|
||||
end if
|
||||
return true
|
||||
end function
|
||||
|
||||
function GetVideoContainer() as object
|
||||
return m.global.videoContainer
|
||||
end function
|
||||
@@ -1,6 +1,9 @@
|
||||
import "pkg:/source/utils/RingBuffer.bs"
|
||||
|
||||
function Init()
|
||||
' We keep in memory the last videos we watched, to avoid a loop
|
||||
' Sometimes recommended videos point to each other, and we're stuck watching
|
||||
' The same 2 videos over and over again
|
||||
m.watchedVideos = new RingBuffer(100)
|
||||
end function
|
||||
|
||||
@@ -14,7 +17,6 @@ function watchedVideosAdd(videoId as string)
|
||||
end if
|
||||
end function
|
||||
|
||||
' watchedVideosClear needs at least one arg https://github.com/rokucommunity/brighterscript/blob/master/docs/callfunc-operator.md#callfunc-evaluation-with-no-arguments
|
||||
function watchedVideosClear(unused as dynamic)
|
||||
m.watchedVideos = new RingBuffer(100)
|
||||
end function
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
<component name="VideoContainer" extends="Group">
|
||||
<interface>
|
||||
<field id="videoPlayer" type="node" />
|
||||
<field id="sender" type="node" />
|
||||
<field id="fullscreen" type="boolean" value="true" />
|
||||
<function name="watchedVideosContain" />
|
||||
<function name="watchedVideosAdd" />
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||
|
||||
@asynctask
|
||||
function VideoContentTask(input as object) as object
|
||||
contentNode = input.content
|
||||
invidiousNode = input.invidious
|
||||
preferencesNode = input.preferences
|
||||
|
||||
if m.top.cancel
|
||||
return invalid
|
||||
end if
|
||||
|
||||
if StringUtils.IsNullOrEmpty(contentNode.videoId)
|
||||
throw "Can't load video information: videoId is missing"
|
||||
end if
|
||||
|
||||
service = new Invidious.InvidiousService(invidiousNode)
|
||||
|
||||
response = service.GetVideoMetadata(contentNode.videoId, m.top.cancellation)
|
||||
|
||||
if m.top.cancel
|
||||
return invalid
|
||||
end if
|
||||
|
||||
metadata = response.Json()
|
||||
|
||||
if not response.IsSuccess() or metadata = invalid
|
||||
return {
|
||||
success: false,
|
||||
error: response.ErrorMessage()
|
||||
}
|
||||
end if
|
||||
|
||||
contentNode.title = metadata.title
|
||||
contentNode.secondaryTitle = metadata.author
|
||||
|
||||
streamUrls = CreateStreamUrls(metadata, service, preferencesNode)
|
||||
contentNode.url = streamUrls[0]
|
||||
|
||||
SetCaptions(metadata, service, contentNode)
|
||||
|
||||
contentNode.addFields({
|
||||
metadata: metadata,
|
||||
' StreamUrls is taken
|
||||
playletStreamUrls: streamUrls,
|
||||
playletStreamUrlIndex: 0
|
||||
})
|
||||
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
end function
|
||||
|
||||
function CreateStreamUrls(metadata as object, service as Invidious.InvidiousService, preferences as object) as object
|
||||
instance = service.GetInstance()
|
||||
proxyVideos = preferences["invidious.proxy_videos"]
|
||||
|
||||
streamUrls = []
|
||||
|
||||
if metadata.hlsUrl <> invalid
|
||||
AddHlsUrls(streamUrls, metadata, proxyVideos)
|
||||
else
|
||||
preferredQuality = preferences["playback.preferred_quality"]
|
||||
|
||||
if preferredQuality = "720p"
|
||||
AddStreamUrls(streamUrls, metadata, service, proxyVideos)
|
||||
AddDashUrls(streamUrls, metadata, proxyVideos)
|
||||
else
|
||||
AddDashUrls(streamUrls, metadata, proxyVideos)
|
||||
AddStreamUrls(streamUrls, metadata, service, proxyVideos)
|
||||
end if
|
||||
end if
|
||||
|
||||
AddInstanceToUrlIfNeeded(streamUrls, instance)
|
||||
|
||||
return streamUrls
|
||||
end function
|
||||
|
||||
function AddHlsUrls(streamUrls as object, metadata as object, proxyVideos as string)
|
||||
hlsUrl = metadata.hlsUrl
|
||||
hlsUrlLocal = AddLocalFlag(hlsUrl)
|
||||
|
||||
AddUrls(streamUrls, hlsUrl, hlsUrlLocal, proxyVideos)
|
||||
end function
|
||||
|
||||
function AddDashUrls(streamUrls as object, metadata as object, proxyVideos as string) as void
|
||||
if metadata.dashUrl = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
dashUrl = metadata.dashUrl
|
||||
dashUrlLocal = AddLocalFlag(dashUrl)
|
||||
|
||||
AddUrls(streamUrls, dashUrl, dashUrlLocal, proxyVideos)
|
||||
end function
|
||||
|
||||
function AddStreamUrls(streamUrls as object, metadata as object, service as Invidious.InvidiousService, proxyVideos as string) as void
|
||||
if metadata.formatStreams = invalid or metadata.formatStreams.Count() = 0
|
||||
return
|
||||
end if
|
||||
|
||||
url = service.GetVideoStreamUrl(metadata.videoId)
|
||||
localUrl = AddLocalFlag(url)
|
||||
|
||||
AddUrls(streamUrls, url, localUrl, proxyVideos)
|
||||
end function
|
||||
|
||||
function AddLocalFlag(url as string) as string
|
||||
if url.InStr("?") = -1
|
||||
return url + "?local=true"
|
||||
else
|
||||
return url + "&local=true"
|
||||
end if
|
||||
end function
|
||||
|
||||
function AddUrls(streamUrls as object, url as string, localUrl as string, proxyVideos as string)
|
||||
if proxyVideos = "if_needed"
|
||||
streamUrls.push(url)
|
||||
streamUrls.push(localUrl)
|
||||
else if proxyVideos = "never"
|
||||
streamUrls.push(url)
|
||||
else if proxyVideos = "always"
|
||||
streamUrls.push(localUrl)
|
||||
else
|
||||
streamUrls.push(url)
|
||||
streamUrls.push(localUrl)
|
||||
end if
|
||||
end function
|
||||
|
||||
function AddInstanceToUrlIfNeeded(streamUrls as object, instance as string)
|
||||
for i = 0 to streamUrls.Count() - 1
|
||||
url = streamUrls[i]
|
||||
if url.StartsWith("/")
|
||||
streamUrls[i] = instance + url
|
||||
end if
|
||||
end for
|
||||
end function
|
||||
|
||||
' TODO:P2
|
||||
' Captions are rate limited https://github.com/iv-org/invidious/issues/2567
|
||||
' It's possible to loop through a list of backup instances hoping to find working subtitles.
|
||||
' Caveat: searching for a working caption could cause a delay in the video player start.
|
||||
function SetCaptions(metadata as object, service as object, contentNode as object) as void
|
||||
if metadata.captions.Count() = 0
|
||||
return
|
||||
end if
|
||||
' TODO:P2 we don't need to read and parse this every time
|
||||
isoLanguageList = ParseJson(ReadAsciiFile("libpkg:/config/ISO-639-1-to-ISO-639-2T.json5"))
|
||||
instance = service.GetInstance()
|
||||
|
||||
subtitleTracks = []
|
||||
|
||||
for each caption in metadata.captions
|
||||
subtitleTracks.Push({
|
||||
Description: caption.label,
|
||||
Language: isoLanguageList[caption.language_code] ?? caption.language_code,
|
||||
TrackName: instance + caption.url
|
||||
})
|
||||
end for
|
||||
|
||||
contentNode.ClosedCaptions = True
|
||||
contentNode.SubtitleTracks = subtitleTracks
|
||||
end function
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import "pkg:/source/services/Invidious.bs"
|
||||
|
||||
@asynctask
|
||||
function VideoDetailsTask(input as object) as object
|
||||
videoId = input.videoId
|
||||
|
||||
metadata = Invidious.GetVideoMetadata(videoId)
|
||||
|
||||
return {
|
||||
videoId: videoId,
|
||||
metadata: metadata
|
||||
}
|
||||
end function
|
||||
@@ -1,322 +1,178 @@
|
||||
import "pkg:/source/utils/TimeUtils.bs"
|
||||
import "pkg:/source/services/SponsorBlock.bs"
|
||||
import "pkg:/components/VideoPlayer/Video.bs"
|
||||
import "pkg:/components/VideoPlayer/VideoDetailsTask.bs"
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/components/VideoPlayer/VideoContentTask.bs"
|
||||
import "pkg:/components/VideoPlayer/VideoPlayerStyle.bs"
|
||||
import "pkg:/source/utils/Logging.bs"
|
||||
import "pkg:/components/VideoPlayer/VideoUtils.bs"
|
||||
import "pkg:/components/VideoPlayer/MarkVideoWatchedTask.bs"
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
import "pkg:/source/utils/ErrorUtils.bs"
|
||||
import "pkg:/components/VideoPlayer/SponsorBlock.bs"
|
||||
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
||||
|
||||
function Init()
|
||||
m.videoContainer = GetVideoContainer()
|
||||
|
||||
SetupSponsorBlock()
|
||||
m.log = new log.Logger("VideoPlayer")
|
||||
SetPlayerStyle()
|
||||
SetupAnimation()
|
||||
SetupBusySpinner()
|
||||
|
||||
m.top.trickPlayBar.filledBarBlendColor = "0xFF0000FF"
|
||||
m.top.bufferingBar.filledBarBlendColor = "0xFF0000FF"
|
||||
m.top.retrievingBar.filledBarBlendColor = "0xFF0000FF"
|
||||
|
||||
m.top.enableUI = m.videoContainer.fullscreen
|
||||
m.videoContainer.observeFieldScoped("fullscreen", "OnFullScreenChange")
|
||||
|
||||
' 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
|
||||
' occurred (such as a next work error)
|
||||
m.videoPlayingSuccess = false
|
||||
' ignoreNextFinishedState indicates if we should ignore the next finished state
|
||||
' This is used to prevent the video from playing the next video when we are
|
||||
' still trying to find a working stream url
|
||||
m.ignoreNextFinishedState = false
|
||||
|
||||
m.top.observeField("control", "OnControlChange")
|
||||
m.top.observeField("videoId", "StartVideoDetailsTask")
|
||||
|
||||
m.top.ObserveField("state", "OnVideoPlayerStateChange")
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
if press = false
|
||||
return false
|
||||
function OnNodeReady()
|
||||
rect = m.container.fullscreen ? m.top.maxRect : m.top.minRect
|
||||
|
||||
m.top.width = rect.width
|
||||
m.top.height = rect.height
|
||||
m.top.translation = [rect.x, rect.y]
|
||||
|
||||
' TODO:P2 show a loading spinner if video is loading minimized
|
||||
m.top.enableUI = m.container.fullscreen
|
||||
|
||||
m.container.observeFieldScoped("fullscreen", FuncName(OnFullScreenChange))
|
||||
m.top.ObserveField("state", FuncName(OnVideoPlayerStateChange))
|
||||
m.top.observeField("control", FuncName(OnControlChange))
|
||||
|
||||
SponsorBlock.SetupSponsorBlock()
|
||||
end function
|
||||
|
||||
function PlayWithContent(contentNode as object)
|
||||
videoContentNode = CreateObject("roSGNode", "ContentNode")
|
||||
|
||||
if not StringUtils.IsNullOrEmpty(contentNode.videoId)
|
||||
videoContentNode.AddFields({ videoId: contentNode.videoId })
|
||||
end if
|
||||
' Unfortunately, a Video node cannot capture the "options" key (because, Roku...)
|
||||
' https://community.roku.com/t5/Roku-Developer-Program/Bug-in-10-0-1-Options-key-is-not-being-consumed-by-onKeyEvent-when-Video-node-is-in-focus/m-p/709200/highlight/true#M49312
|
||||
' Because of that, the button "down" is used to shrink the video for picture in picture mode
|
||||
if key = "down"
|
||||
if ToggleVideoPictureInPicture()
|
||||
return true
|
||||
if IsInt(contentNode.timestamp)
|
||||
videoContentNode.AddFields({ timestamp: contentNode.timestamp })
|
||||
end if
|
||||
if not StringUtils.IsNullOrEmpty(contentNode.title)
|
||||
videoContentNode.title = contentNode.title
|
||||
end if
|
||||
if not StringUtils.IsNullOrEmpty(contentNode.author)
|
||||
videoContentNode.secondaryTitle = contentNode.author
|
||||
end if
|
||||
|
||||
StartVideoContentTask(videoContentNode)
|
||||
end function
|
||||
|
||||
function StartVideoContentTask(videoContentNode as object)
|
||||
if m.videoContentTask <> invalid
|
||||
m.videoContentTask.cancel = true
|
||||
end if
|
||||
|
||||
MarkVideoWatched(videoContentNode.videoId)
|
||||
|
||||
m.top.content = videoContentNode
|
||||
|
||||
m.videoContentTask = StartAsyncTask(VideoContentTask, {
|
||||
content: videoContentNode,
|
||||
invidious: m.top.invidious,
|
||||
preferences: m.top.preferences
|
||||
}, OnVideoContentTaskResults)
|
||||
end function
|
||||
|
||||
function OnVideoContentTaskResults(output as object) as void
|
||||
m.videoContentTask = invalid
|
||||
if output.cancelled
|
||||
return
|
||||
end if
|
||||
|
||||
if not output.success or not output.result.success
|
||||
' output.error for unhandled exception
|
||||
error = output.error
|
||||
if error = invalid
|
||||
' output.result.error for network errors
|
||||
error = output.result.error
|
||||
end if
|
||||
error = ErrorUtils.Format(error)
|
||||
m.log.error(error)
|
||||
videoId = output.task.input.content.videoId
|
||||
message = `Failed to load video information for ${videoId}\n${error}`
|
||||
DialogUtils.ShowDialog(message, "Video load fail", true)
|
||||
' TODO:P1 play next video in the queue after showing the error dialog
|
||||
VideoUtils.CloseVideo()
|
||||
return
|
||||
end if
|
||||
if key = "back"
|
||||
m.videoContainer@.watchedVideosClear()
|
||||
CloseVideo()
|
||||
return true
|
||||
|
||||
SponsorBlock.FetchSponsorBlock(m.top.content.metadata)
|
||||
|
||||
m.top.control = "play"
|
||||
if ValidInt(m.top.content.timestamp) > 0
|
||||
m.top.seek = m.top.content.timestamp
|
||||
end if
|
||||
return false
|
||||
end function
|
||||
|
||||
function MarkVideoWatched(videoId as string)
|
||||
if m.top.invidious.authToken <> invalid
|
||||
StartAsyncTask(MarkVideoWatchedTask, {
|
||||
videoId: videoId,
|
||||
invidious: m.top.invidious
|
||||
})
|
||||
end if
|
||||
end function
|
||||
|
||||
function Close(unused as dynamic)
|
||||
m.top.control = "stop"
|
||||
m.top.content = invalid
|
||||
parent = m.top.getParent()
|
||||
if parent <> invalid
|
||||
parent.RemoveChild(m.top)
|
||||
end if
|
||||
SponsorBlock.RemoveNotifcation(m.notifications)
|
||||
end function
|
||||
|
||||
function OnControlChange()
|
||||
if m.top.control = "stop"
|
||||
if m.videoDetailsTask <> invalid
|
||||
m.videoDetailsTask.control = "stop"
|
||||
if m.videoContentTask <> invalid
|
||||
m.videoContentTask.cancel = true
|
||||
m.videoContentTask = invalid
|
||||
end if
|
||||
if m.sponsorBlockTask <> invalid
|
||||
m.sponsorBlockTask.control = "stop"
|
||||
m.sponsorBlockTask.cancel = true
|
||||
m.sponsorBlockTask = invalid
|
||||
end if
|
||||
end if
|
||||
end function
|
||||
|
||||
function SetMetadata() as void
|
||||
if m.top.metadata = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
metadata = m.top.metadata
|
||||
contentNode = CreateObject("roSGNode", "ContentNode")
|
||||
contentNode.addFields({ metadata: metadata })
|
||||
|
||||
contentNode.title = metadata.title
|
||||
contentNode.secondaryTitle = metadata.author
|
||||
|
||||
m.top.content = contentNode
|
||||
end function
|
||||
|
||||
function StartVideoDetailsTask()
|
||||
if m.videoDetailsTask <> invalid
|
||||
m.videoDetailsTask.control = "stop"
|
||||
end if
|
||||
|
||||
SetMetadata()
|
||||
m.videoDetailsTask = StartAsyncTask(VideoDetailsTask, { videoId: m.top.videoId }, OnVideoDetailsTaskResults)
|
||||
end function
|
||||
|
||||
function OnVideoDetailsTaskResults(output as object) as void
|
||||
videoId = output.result.videoId
|
||||
metadata = output.result.metadata
|
||||
if videoId <> m.top.videoId
|
||||
return
|
||||
end if
|
||||
if (not metadata.success) or (metadata.data = invalid)
|
||||
m.busySpinner.visible = false
|
||||
m.busySpinner.control = "stop"
|
||||
message = `Failed to load video information for ${videoId}`
|
||||
message += `\nStatus Code: ${metadata.statusCode}`
|
||||
if isstr(metadata.data)
|
||||
message += `\nError: ${metadata.data}`
|
||||
else if isAssocArray(metadata.data)
|
||||
message += `\nError: ${FormatJson(metadata.data)}`
|
||||
end if
|
||||
if isstr(metadata.failureReason)
|
||||
message += `\nError: ${metadata.failureReason}`
|
||||
end if
|
||||
ShowDialog(message, "Video load fail")
|
||||
CloseVideo()
|
||||
return
|
||||
end if
|
||||
|
||||
metadata = metadata.data
|
||||
|
||||
playletStreamUrls = []
|
||||
|
||||
if metadata.hlsUrl <> invalid
|
||||
hlsUrl = metadata.hlsUrl
|
||||
playletStreamUrls.push(hlsUrl)
|
||||
|
||||
if hlsUrl.InStr("?") = -1
|
||||
hlsUrlLocal = hlsUrl + "?local=true"
|
||||
else
|
||||
hlsUrlLocal = hlsUrl + "&local=true"
|
||||
end if
|
||||
playletStreamUrls.push(hlsUrlLocal)
|
||||
else
|
||||
settings = FindAndGetPreferenceValues(["playback.preferred_quality", "invidious.proxy_videos"])
|
||||
if settings = invalid
|
||||
settings = {
|
||||
"playback.preferred_quality": "auto",
|
||||
"invidious.proxy_videos": "if_needed"
|
||||
}
|
||||
end if
|
||||
|
||||
if settings["playback.preferred_quality"] = "720p"
|
||||
AddStreamUrls(playletStreamUrls, metadata, settings)
|
||||
AddDashUrls(playletStreamUrls, metadata, settings)
|
||||
else
|
||||
AddDashUrls(playletStreamUrls, metadata, settings)
|
||||
AddStreamUrls(playletStreamUrls, metadata, settings)
|
||||
end if
|
||||
end if
|
||||
|
||||
metadata.playletStreamUrls = playletStreamUrls
|
||||
metadata.playletStreamUrlIndex = 0
|
||||
|
||||
contentNode = CreateObject("roSGNode", "ContentNode")
|
||||
contentNode.addFields({ metadata: metadata })
|
||||
|
||||
contentNode.title = metadata.title
|
||||
contentNode.secondaryTitle = metadata.author
|
||||
SetCaptions(metadata, m.top, contentNode)
|
||||
contentNode.url = metadata.playletStreamUrls[metadata.playletStreamUrlIndex]
|
||||
m.busySpinner.visible = false
|
||||
m.busySpinner.control = "stop"
|
||||
m.top.content = contentNode
|
||||
m.top.control = "play"
|
||||
|
||||
m.videoContainer@.watchedVideosAdd(videoId)
|
||||
|
||||
StartSponsorBlockTask()
|
||||
end function
|
||||
|
||||
function AddDashUrls(playletStreamUrls as object, metadata as object, settings as object) as void
|
||||
if metadata.dashUrl = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
#if DASH_THUMBNAILS
|
||||
' Redirect to our server so we can inject thumbnails (storyboards) into the DASH manifest
|
||||
dashUrl = `http://${GetLocalIpAddress()}:8888/dash?v=${videoId}`
|
||||
#else
|
||||
dashUrl = metadata.dashUrl
|
||||
#end if
|
||||
|
||||
if dashUrl.InStr("?") = -1
|
||||
dashUrlLocal = dashUrl + "?local=true"
|
||||
else
|
||||
dashUrlLocal = dashUrl + "&local=true"
|
||||
end if
|
||||
|
||||
proxyVideos = settings["invidious.proxy_videos"]
|
||||
if proxyVideos = "if_needed"
|
||||
playletStreamUrls.push(dashUrl)
|
||||
playletStreamUrls.push(dashUrlLocal)
|
||||
else if proxyVideos = "never"
|
||||
playletStreamUrls.push(dashUrl)
|
||||
else if proxyVideos = "always"
|
||||
playletStreamUrls.push(dashUrlLocal)
|
||||
else
|
||||
playletStreamUrls.push(dashUrl)
|
||||
playletStreamUrls.push(dashUrlLocal)
|
||||
end if
|
||||
end function
|
||||
|
||||
function AddStreamUrls(playletStreamUrls as object, metadata as object, settings as object) as void
|
||||
if metadata.formatStreams = invalid or metadata.formatStreams.Count() = 0
|
||||
return
|
||||
end if
|
||||
|
||||
proxyVideos = settings["invidious.proxy_videos"]
|
||||
if proxyVideos = "if_needed"
|
||||
playletStreamUrls.push(Invidious.GetVideoStreamUrl(metadata.videoId, false))
|
||||
playletStreamUrls.push(Invidious.GetVideoStreamUrl(metadata.videoId, true))
|
||||
else if proxyVideos = "never"
|
||||
playletStreamUrls.push(Invidious.GetVideoStreamUrl(metadata.videoId, false))
|
||||
else if proxyVideos = "always"
|
||||
playletStreamUrls.push(Invidious.GetVideoStreamUrl(metadata.videoId, true))
|
||||
else
|
||||
playletStreamUrls.push(Invidious.GetVideoStreamUrl(metadata.videoId, false))
|
||||
playletStreamUrls.push(Invidious.GetVideoStreamUrl(metadata.videoId, true))
|
||||
end if
|
||||
end function
|
||||
|
||||
function FindChildNodeOfType(node as object, nodeType as string) as object
|
||||
if node.subtype() = nodeType
|
||||
return node
|
||||
end if
|
||||
|
||||
childCount = node.getChildCount()
|
||||
children = node.getChildren(childCount, 0)
|
||||
for i = 0 to childCount - 1
|
||||
child = FindChildNodeOfType(children[i], nodeType)
|
||||
if child <> invalid
|
||||
return child
|
||||
end if
|
||||
end for
|
||||
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function SetupBusySpinner()
|
||||
' busySpinner is our spinner, shown when loading the video details (like links, title, etc)
|
||||
m.busySpinner = m.top.findNode("BusySpinner")
|
||||
' Once the Content is ready, the rokuBusySpinner shows up, which is loading the video feed
|
||||
m.rokuBusySpinner = FindChildNodeOfType(m.top, "BusySpinner")
|
||||
' The label that shows the buffering percentage
|
||||
m.rokuBusySpinnerLabel = FindChildNodeOfType(m.rokuBusySpinner, "Label")
|
||||
|
||||
m.rokuBusySpinner.poster.width = 150
|
||||
m.rokuBusySpinner.poster.height = 150
|
||||
m.rokuBusySpinner.poster.uri = "pkg:/images/spinner.png"
|
||||
m.rokuBusySpinner.observeField("translation", "OnRokuSpinnerMoved")
|
||||
m.top.observeField("width", "OnRokuSpinnerMoved")
|
||||
m.top.observeField("height", "OnRokuSpinnerMoved")
|
||||
m.top.observeField("translation", "OnRokuSpinnerMoved")
|
||||
|
||||
m.rokuBusySpinnerLabel.width = 150
|
||||
m.rokuBusySpinnerLabel.height = 150
|
||||
m.rokuBusySpinnerLabel.translation = [0, 0]
|
||||
m.rokuBusySpinnerLabel.observeField("translation", "OnRokuSpinnerLabelMoved")
|
||||
m.top.observeField("width", "OnRokuSpinnerLabelMoved")
|
||||
m.top.observeField("height", "OnRokuSpinnerLabelMoved")
|
||||
m.top.observeField("translation", "OnRokuSpinnerLabelMoved")
|
||||
|
||||
m.busySpinner.poster.width = 150
|
||||
m.busySpinner.poster.height = 150
|
||||
m.busySpinner.poster.uri = "pkg:/images/spinner.png"
|
||||
m.top.observeField("width", "PositionSpinner")
|
||||
m.top.observeField("height", "PositionSpinner")
|
||||
m.top.observeField("translation", "PositionSpinner")
|
||||
|
||||
PositionSpinner()
|
||||
|
||||
m.busySpinner.visible = true
|
||||
m.busySpinner.control = "start"
|
||||
end function
|
||||
|
||||
function OnRokuSpinnerMoved()
|
||||
currentTranslation = m.rokuBusySpinner.translation
|
||||
parentRect = m.top.boundingRect()
|
||||
centerx = (parentRect.width - m.rokuBusySpinner.poster.width) / 2
|
||||
centery = (parentRect.height - m.rokuBusySpinner.poster.height) / 2
|
||||
|
||||
if currentTranslation[0] <> centerx or currentTranslation[1] <> centery
|
||||
m.rokuBusySpinner.translation = [centerx, centery]
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnRokuSpinnerLabelMoved()
|
||||
currentTranslation = m.rokuBusySpinnerLabel.translation
|
||||
if currentTranslation[0] <> 0 or currentTranslation[1] <> 0
|
||||
m.rokuBusySpinnerLabel.translation = [0, 0]
|
||||
end if
|
||||
end function
|
||||
|
||||
function PositionSpinner()
|
||||
centerx = (m.top.width - m.busySpinner.poster.width) / 2
|
||||
centery = (m.top.height - m.busySpinner.poster.height) / 2
|
||||
m.busySpinner.translation = [centerx, centery]
|
||||
end function
|
||||
|
||||
function OnVideoPlayerStateChange() as void
|
||||
state = m.top.state
|
||||
|
||||
' If we successfully played the video, then any error that comes later is not due to a 403 (FORBIDDEN).
|
||||
' This is to reduce false positives, as we do not want retry another link if the first link is working fine.
|
||||
if state = "playing" and not m.videoPlayingSuccess
|
||||
m.log.info(`Now playing video ${m.top.content.url}`)
|
||||
m.videoPlayingSuccess = true
|
||||
if m.top.timestamp <> 0
|
||||
m.top.seek = m.top.timestamp
|
||||
end if
|
||||
end if
|
||||
|
||||
if state = "error"
|
||||
' A hack to see if we could use the proxy here
|
||||
errorInfo = m.top.errorInfo
|
||||
m.log.error(`Error playing video ${m.top.content.videoId}`, errorInfo)
|
||||
if m.videoPlayingSuccess <> true
|
||||
errorInfo = m.top.errorInfo
|
||||
' http for stream format, mediaerror for DASH
|
||||
if errorInfo.category = "http" or errorInfo.category = "mediaerror"
|
||||
currentUrl = m.top.content.url
|
||||
metadata = m.top.content.metadata
|
||||
metadata.playletStreamUrlIndex++
|
||||
m.top.content.metadata = metadata
|
||||
if m.top.content.metadata.playletStreamUrlIndex < m.top.content.metadata.playletStreamUrls.Count()
|
||||
nextUrl = m.top.content.metadata.playletStreamUrls[m.top.content.metadata.playletStreamUrlIndex]
|
||||
print(`Stream ${currentUrl} failed to play. Trying next stream ${nextUrl}`)
|
||||
playletStreamUrls = m.top.content.playletStreamUrls
|
||||
playletStreamUrlIndex = m.top.content.playletStreamUrlIndex
|
||||
playletStreamUrlIndex++
|
||||
m.top.content.playletStreamUrlIndex = playletStreamUrlIndex
|
||||
if playletStreamUrlIndex < playletStreamUrls.Count()
|
||||
nextUrl = playletStreamUrls[playletStreamUrlIndex]
|
||||
m.log.error(`Stream ${currentUrl} failed to play. Trying next stream ${nextUrl}`)
|
||||
|
||||
m.top.content.url = nextUrl
|
||||
' This video errored, and is about to finish, so don't close the video yet
|
||||
' TODO: perhaps creating a second player is better?
|
||||
' That's why we should ignore the next "finished" event
|
||||
m.ignoreNextFinishedState = true
|
||||
m.top.control = "play"
|
||||
|
||||
if ValidInt(m.top.content.timestamp) > 0
|
||||
m.top.seek = m.top.content.timestamp
|
||||
end if
|
||||
return
|
||||
end if
|
||||
end if
|
||||
@@ -330,9 +186,9 @@ function OnVideoPlayerStateChange() as void
|
||||
|
||||
if state = "finished"
|
||||
metadata = m.top.content?.metadata
|
||||
|
||||
if not PlayNextRecommendedVideo(metadata?.recommendedVideos)
|
||||
CloseVideo()
|
||||
if not PlayNext(metadata?.recommendedVideos)
|
||||
m.container@.watchedVideosClear(invalid)
|
||||
VideoUtils.CloseVideo()
|
||||
end if
|
||||
end if
|
||||
|
||||
@@ -346,14 +202,22 @@ function OnVideoPlayerStateChange() as void
|
||||
for each info in errorInfo
|
||||
messageLines.push(`${info}: ${errorInfo[info]}`)
|
||||
end for
|
||||
ShowDialog(messageLines, `Error playing video ${m.top.videoId}`, true)
|
||||
CloseVideo()
|
||||
DialogUtils.ShowDialog(messageLines, `Error playing video ${m.top.content.videoId}`, true)
|
||||
' TODO:P1 play next video in the queue after showing the error dialog
|
||||
VideoUtils.CloseVideo()
|
||||
end if
|
||||
end function
|
||||
|
||||
function PlayNext(recommendedVideos as object) as boolean
|
||||
if m.playQueue@.PlayNextItem(invalid)
|
||||
return true
|
||||
end if
|
||||
|
||||
return PlayNextRecommendedVideo(recommendedVideos)
|
||||
end function
|
||||
|
||||
function PlayNextRecommendedVideo(recommendedVideos as object) as boolean
|
||||
settings = FindAndGetPreferenceValues(["playback.autoplay"])
|
||||
if settings = invalid or settings["playback.autoplay"] <> true
|
||||
if m.preferences["playback.autoplay"] <> true
|
||||
return false
|
||||
end if
|
||||
|
||||
@@ -366,8 +230,10 @@ function PlayNextRecommendedVideo(recommendedVideos as object) as boolean
|
||||
if videoId = invalid
|
||||
continue for
|
||||
end if
|
||||
if not m.videoContainer@.watchedVideosContain(videoId)
|
||||
PlayVideo(videoId, { metadata: metadata })
|
||||
if not m.container@.watchedVideosContain(videoId)
|
||||
m.log.info(`Playing next recommended video (${videoId})`)
|
||||
node = InvidiousContent.ToVideoContentNode(invalid, metadata, invalid)
|
||||
VideoUtils.PlayVideo(node)
|
||||
return true
|
||||
end if
|
||||
end for
|
||||
@@ -375,24 +241,52 @@ function PlayNextRecommendedVideo(recommendedVideos as object) as boolean
|
||||
return false
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
if press = false
|
||||
return false
|
||||
end if
|
||||
' Unfortunately, a Video node cannot capture the "options" key (because, Roku...)
|
||||
' https://community.roku.com/t5/Roku-Developer-Program/Bug-in-10-0-1-Options-key-is-not-being-consumed-by-onKeyEvent-when-Video-node-is-in-focus/m-p/709200/highlight/true#M49312
|
||||
' Because of that, the button "down" is used to shrink the video for picture in picture mode
|
||||
if key = "down"
|
||||
if VideoUtils.ToggleVideoPictureInPicture()
|
||||
return true
|
||||
end if
|
||||
end if
|
||||
|
||||
if key = "back"
|
||||
m.container@.watchedVideosClear(invalid)
|
||||
VideoUtils.CloseVideo()
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end function
|
||||
|
||||
function SetupAnimation()
|
||||
m.widthAnimation = m.top.findNode("widthAnimation")
|
||||
m.widthAnimationInterpolator = m.top.findNode("widthAnimationInterpolator")
|
||||
m.heightAnimation = m.top.findNode("heightAnimation")
|
||||
m.heightAnimationInterpolator = m.top.findNode("heightAnimationInterpolator")
|
||||
m.translationAnimation = m.top.findNode("translationAnimation")
|
||||
m.translationAnimationInterpolator = m.top.findNode("translationAnimationInterpolator")
|
||||
m.minimizeAnimation = m.top.findNode("minimizeAnimation")
|
||||
m.widthInterpolator = m.top.findNode("widthInterpolator")
|
||||
m.heightInterpolator = m.top.findNode("heightInterpolator")
|
||||
m.translationInterpolator = m.top.findNode("translationInterpolator")
|
||||
|
||||
minRect = m.top.minRect
|
||||
maxRect = m.top.maxRect
|
||||
|
||||
m.widthInterpolator.keyValue = [maxRect.width, (maxRect.width + minRect.width) / 2, minRect.width]
|
||||
m.heightInterpolator.keyValue = [maxRect.height, (maxRect.height + minRect.height) / 2, minRect.height]
|
||||
maxTranslation = [maxRect.x, maxRect.y]
|
||||
minTranslation = [minRect.x, minRect.y]
|
||||
midTranslation = [(maxRect.x + minRect.x) / 2, (maxRect.y + minRect.y) / 2]
|
||||
m.translationInterpolator.keyValue = [maxTranslation, midTranslation, minTranslation]
|
||||
end function
|
||||
|
||||
function OnFullScreenChange()
|
||||
m.widthAnimationInterpolator.reverse = m.videoContainer.fullscreen
|
||||
m.heightAnimationInterpolator.reverse = m.videoContainer.fullscreen
|
||||
m.translationAnimationInterpolator.reverse = m.videoContainer.fullscreen
|
||||
m.widthInterpolator.reverse = m.container.fullscreen
|
||||
m.heightInterpolator.reverse = m.container.fullscreen
|
||||
m.translationInterpolator.reverse = m.container.fullscreen
|
||||
|
||||
m.widthAnimation.control = "start"
|
||||
m.heightAnimation.control = "start"
|
||||
m.translationAnimation.control = "start"
|
||||
m.minimizeAnimation.control = "start"
|
||||
|
||||
m.top.enableUI = m.videoContainer.fullscreen
|
||||
SponsorBlockNotifcationSetVisible(m.videoContainer.fullscreen)
|
||||
m.top.enableUI = m.container.fullscreen
|
||||
|
||||
SponsorBlock.SetVisible(m.notifications, m.container.fullscreen)
|
||||
end function
|
||||
@@ -1,13 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="VideoPlayer" extends="Video">
|
||||
<script type="text/brightscript" uri="VideoPlayerSponsorBlock.bs" />
|
||||
<script type="text/brightscript" uri="VideoPlayerCaptions.bs" />
|
||||
<component name="VideoPlayer" extends="Video" includes="AutoBind">
|
||||
<interface>
|
||||
<field id="appController" type="node" bind="/AppController" />
|
||||
<field id="container" type="node" bind=".." />
|
||||
<field id="notifications" type="node" bind="../../Notifications" />
|
||||
<field id="playQueue" type="node" bind="../../PlayQueue" />
|
||||
<field id="preferences" type="node" bind="../../Preferences" />
|
||||
<field id="invidious" type="node" bind="../../Invidious" />
|
||||
<field id="minRect" type="rect2D" value="[834,460,426,240]" />
|
||||
<field id="maxRect" type="rect2D" value="[0,0,1280,720]" />
|
||||
<field id="chapter" type="string" alias="chapterLabel.text" />
|
||||
<field id="videoId" type="string" />
|
||||
<field id="metadata" type="assocarray" />
|
||||
<field id="timestamp" type="integer" />
|
||||
<function name="PlayWithContent" />
|
||||
<function name="Close" />
|
||||
</interface>
|
||||
<children>
|
||||
<Label
|
||||
@@ -23,35 +28,20 @@
|
||||
repeat="true"
|
||||
duration="0.25"
|
||||
/>
|
||||
<BusySpinner
|
||||
id="busySpinner"
|
||||
spinInterval="1" />
|
||||
<Animation id="widthAnimation"
|
||||
<Animation id="minimizeAnimation"
|
||||
duration="0.3"
|
||||
optional="true">
|
||||
<FloatFieldInterpolator
|
||||
id="widthAnimationInterpolator"
|
||||
id="widthInterpolator"
|
||||
key="[0.0, 0.5, 1.0]"
|
||||
keyValue="[ 1280.0, 853.0, 426.0 ]"
|
||||
fieldToInterp="VideoPlayer.width" />
|
||||
</Animation>
|
||||
<Animation id="heightAnimation"
|
||||
duration="0.3"
|
||||
optional="true">
|
||||
<FloatFieldInterpolator
|
||||
id="heightAnimationInterpolator"
|
||||
id="heightInterpolator"
|
||||
key="[0.0, 0.5, 1.0]"
|
||||
keyValue="[ 720.0, 480.0, 240.0 ]"
|
||||
fieldToInterp="VideoPlayer.height" />
|
||||
</Animation>
|
||||
<Animation
|
||||
id="translationAnimation"
|
||||
duration="0.3"
|
||||
optional="true">
|
||||
<Vector2DFieldInterpolator
|
||||
id="translationAnimationInterpolator"
|
||||
id="translationInterpolator"
|
||||
key="[0.0, 0.5, 1.0]"
|
||||
keyValue="[ [0.0, 0.0], [417.0, 230.0], [834.0, 460.0] ]"
|
||||
fieldToInterp="VideoPlayer.translation" />
|
||||
</Animation>
|
||||
</children>
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
import "pkg:/components/VideoPlayer/VideoPlayerCaptionsTask.bs"
|
||||
|
||||
function SetCaptions(metadata as object, videoPlayer as object, contentNode as object) as void
|
||||
if metadata.captions.Count() = 0
|
||||
return
|
||||
end if
|
||||
isoLanguageList = ParseJson(ReadAsciiFile("libpkg:/config/ISO-639-1-to-ISO-639-2T.json"))
|
||||
instance = InvidiousSettings.GetCurrentInstance()
|
||||
|
||||
subtitleTracks = []
|
||||
|
||||
for each caption in metadata.captions
|
||||
subtitleTracks.Push({
|
||||
Description: caption.label,
|
||||
Language: isoLanguageList[caption.language_code] ?? caption.language_code,
|
||||
TrackName: instance + caption.url
|
||||
})
|
||||
end for
|
||||
contentNode.ClosedCaptions = True
|
||||
contentNode.SubtitleTracks = subtitleTracks
|
||||
|
||||
' Captions are rate limited https://github.com/iv-org/invidious/issues/2567
|
||||
' We loop through a list of backup instances hoping to find working subtitles.
|
||||
' Searching for a working caption could cause a delay in the video player start.
|
||||
' This is why it is behind a feature flag.
|
||||
#if CAPTION_INSTANCE_SEARCH
|
||||
StartAsyncTask(VideoPlayerCaptionsTask, {
|
||||
videoId: metadata.videoId,
|
||||
instance: instance,
|
||||
subtitleTracks: subtitleTracks
|
||||
}, OnVideoPlayerCaptionsTaskResults)
|
||||
#end if
|
||||
end function
|
||||
|
||||
function OnVideoPlayerCaptionsTaskResults(output as object) as void
|
||||
changed = output.result.changed
|
||||
if not changed
|
||||
return
|
||||
end if
|
||||
|
||||
videoId = output.result.videoId
|
||||
if m.top.videoId <> videoId
|
||||
return
|
||||
end if
|
||||
|
||||
state = m.top.state
|
||||
contentNode = m.top.content
|
||||
contentNode.Update({
|
||||
SubtitleTracks: output.result.subtitleTracks
|
||||
})
|
||||
if state = "buffering" or state = "playing"
|
||||
m.top.control = "play"
|
||||
end if
|
||||
end function
|
||||
@@ -1,62 +0,0 @@
|
||||
import "pkg:/source/roku_modules/rokurequests/Requests.brs"
|
||||
import "pkg:/source/services/InvidiousSettings.bs"
|
||||
|
||||
@asynctask
|
||||
function VideoPlayerCaptionsTask(input as object) as object
|
||||
originalInstance = input.instance
|
||||
subtitleTracks = input.subtitleTracks
|
||||
if subtitleTracks.Count() = 0
|
||||
return {
|
||||
changed: false
|
||||
}
|
||||
end if
|
||||
|
||||
track = subtitleTracks[0]
|
||||
url = track.TrackName
|
||||
|
||||
if IsValidSubtitleTrack(url)
|
||||
return {
|
||||
changed: false
|
||||
}
|
||||
end if
|
||||
|
||||
failedInstances = {}
|
||||
failedInstances[originalInstance] = true
|
||||
|
||||
instances = InvidiousSettings.GetBackupInstances()
|
||||
for each instance in instances
|
||||
if failedInstances[instance] = true
|
||||
continue for
|
||||
end if
|
||||
|
||||
instanceUrl = url.Replace(originalInstance, instance)
|
||||
if IsValidSubtitleTrack(instanceUrl)
|
||||
for i = 0 to subtitleTracks.Count() - 1
|
||||
subtitleTracks[i].TrackName = subtitleTracks[i].TrackName.Replace(originalInstance, instance)
|
||||
end for
|
||||
|
||||
return {
|
||||
changed: true,
|
||||
videoId: input.videoId,
|
||||
subtitleTracks: subtitleTracks
|
||||
}
|
||||
else
|
||||
failedInstances[instance] = true
|
||||
end if
|
||||
|
||||
end for
|
||||
|
||||
return {
|
||||
changed: false
|
||||
}
|
||||
end function
|
||||
|
||||
function IsValidSubtitleTrack(url as string) as boolean
|
||||
response = Requests().get(url, { parseJson: false })
|
||||
' A popular instance will return a valid format
|
||||
' WEBVTT
|
||||
' Kind: captions
|
||||
' Language: en
|
||||
' But won't include any caption items
|
||||
return response.ok and response.text.StartsWith("WEBVTT") and response.text.len() > 50
|
||||
end function
|
||||
@@ -1,178 +0,0 @@
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/components/VideoPlayer/SponsorBlockTask.bs"
|
||||
import "pkg:/components/VideoPlayer/SponsorBlockTrackingTask.bs"
|
||||
import "pkg:/components/SponsorBlockNotification/SponsorBlockNotificationManager.bs"
|
||||
import "pkg:/components/SettingsScreen/Settings.bs"
|
||||
|
||||
function SetupSponsorBlock() as void
|
||||
LoadSponsorBlockSettings()
|
||||
if not m.sponsorBlockEnabled = true
|
||||
return
|
||||
end if
|
||||
|
||||
PositionChapterLabel()
|
||||
|
||||
SponsorBlockNotifcationSetVisible(m.videoContainer.fullscreen)
|
||||
|
||||
m.timeLabel = FindTimeLabel()
|
||||
m.top.trickPlayBar.observeField("visible", "OnTrickPlayBarVisible")
|
||||
m.chapterLabelTimer = m.top.findNode("chapterLabelTimer")
|
||||
m.chapterLabelTimer.observeField("fire", "OnChapterLabelTimer")
|
||||
end function
|
||||
|
||||
function LoadSponsorBlockSettings() as void
|
||||
settings = FindAndGetPreferenceValues(["sponsorblock.enabled", "sponsorblock.show_notifications"])
|
||||
if settings = invalid
|
||||
m.sponsorBlockEnabled = false
|
||||
m.sponsorBlockShowNotifications = false
|
||||
return
|
||||
end if
|
||||
|
||||
m.sponsorBlockEnabled = settings["sponsorblock.enabled"]
|
||||
m.sponsorBlockShowNotifications = settings["sponsorblock.show_notifications"]
|
||||
end function
|
||||
|
||||
function PositionChapterLabel()
|
||||
m.chapterLabel = m.top.findNode("chapterLabel")
|
||||
m.chapterLabel.reparent(m.top.trickPlayBar, false)
|
||||
trickPlayBarWidth = m.top.trickPlayBar.boundingRect().width
|
||||
#if DASH_THUMBNAILS
|
||||
yPos = 25
|
||||
#else
|
||||
yPos = 55
|
||||
#end if
|
||||
m.chapterLabel.translation = [trickPlayBarWidth / 2 - m.chapterLabel.width / 2, yPos]
|
||||
end function
|
||||
|
||||
' This is a hack to access the position of the trickplay
|
||||
function FindTimeLabel() as object
|
||||
children = m.top.trickPlayBar.getChildren(m.top.trickPlayBar.getChildCount(), 0)
|
||||
label = invalid
|
||||
for each child in children
|
||||
' It's very unfortunate to have to find a label with 0:00 text,
|
||||
' and that's on the left side of the screen. This might need completely custom trickPlayBar
|
||||
if child.isSubtype("Label") and child.text = "0:00"
|
||||
if label = invalid
|
||||
label = child
|
||||
else
|
||||
if child.translation[0] < label.translation[0]
|
||||
label = child
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
return label
|
||||
end function
|
||||
|
||||
function OnTrickPlayBarVisible()
|
||||
if m.top.trickPlayBar.visible
|
||||
m.top.chapter = ""
|
||||
m.chapterLabelTimer.control = "start"
|
||||
else
|
||||
m.chapterLabelTimer.control = "stop"
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnChapterLabelTimer() as void
|
||||
if m.timeLabel = invalid or m.skipSegments = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
if m.sponsorBlockLastTime = m.timeLabel.text
|
||||
return
|
||||
end if
|
||||
m.sponsorBlockLastTime = m.timeLabel.text
|
||||
|
||||
time = TimeUtils.ParseTime(m.timeLabel.text)
|
||||
UpdateSponsorBlockChapter(time)
|
||||
end function
|
||||
|
||||
function UpdateSponsorBlockChapter(time as integer) as void
|
||||
segments = m.skipSegments
|
||||
for each segment in segments
|
||||
segmentRange = segment["segment"]
|
||||
segmentStart = segmentRange[0]
|
||||
segmentEnd = segmentRange[1]
|
||||
|
||||
if (segmentStart <= time) and (segmentEnd >= time)
|
||||
m.top.chapter = SponsorBlock.SegmentTitle(segment["category"])
|
||||
return
|
||||
end if
|
||||
end for
|
||||
m.top.chapter = ""
|
||||
end function
|
||||
|
||||
function StartSponsorBlockTask() as void
|
||||
if not m.sponsorBlockEnabled = true
|
||||
return
|
||||
end if
|
||||
|
||||
if m.sponsorBlockTask <> invalid
|
||||
m.sponsorBlockTask.control = "stop"
|
||||
end if
|
||||
|
||||
m.sponsorBlockTask = StartAsyncTask(SponsorBlockTask, {
|
||||
videoId: m.top.videoId,
|
||||
metadata: m.top.content.metadata
|
||||
}, OnSponsorBlockTaskResults)
|
||||
end function
|
||||
|
||||
function OnSponsorBlockTaskResults(output as object)
|
||||
skipSegments = output.result.skipSegments
|
||||
barPath = output.result.barPath
|
||||
if skipSegments <> invalid
|
||||
m.skipSegments = skipSegments
|
||||
m.top.seekMode = "accurate"
|
||||
if barPath <> invalid
|
||||
m.top.trickPlayBar.trackImageUri = barPath
|
||||
m.top.trickPlayBar.filledBarBlendColor = "0xFF000080"
|
||||
end if
|
||||
|
||||
m.top.ObserveField("position", "OnPositionChangeSkipSponsorBlockSections")
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnPositionChangeSkipSponsorBlockSections() as void
|
||||
segments = m.skipSegments
|
||||
if segments = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
for each segment in segments
|
||||
segmentRange = segment["segment"]
|
||||
segmentStart = segmentRange[0]
|
||||
segmentEnd = segmentRange[1]
|
||||
currentPosition = m.top.position
|
||||
if (segmentStart < currentPosition) and ((segmentEnd - 1) > currentPosition)
|
||||
action = GetActionForSegment(segment)
|
||||
if m.sponsorBlockShowNotifications = true
|
||||
ShowSponsorBlockNotifcation(segment, action)
|
||||
end if
|
||||
|
||||
if action = "AutoSkip"
|
||||
m.top.seek = segmentEnd
|
||||
print("Skipping section:" + segment["category"])
|
||||
SendSkippedSectionEvent(segment.UUID)
|
||||
return
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
end function
|
||||
|
||||
function GetActionForSegment(segment as object) as dynamic
|
||||
category = segment["category"]
|
||||
if category = "sponsor"
|
||||
return "AutoSkip"
|
||||
else if category = "poi_highlight"
|
||||
return "ManualSkip"
|
||||
else if category = "exclusive_access"
|
||||
return "ShowOverlay"
|
||||
else if category = "chapter"
|
||||
return "ShowOverlay"
|
||||
end if
|
||||
return ""
|
||||
end function
|
||||
|
||||
function SendSkippedSectionEvent(segmentId as string)
|
||||
StartAsyncTask(SponsorBlockTrackingTask, { segmentId: segmentId })
|
||||
end function
|
||||
@@ -0,0 +1,28 @@
|
||||
function SetPlayerStyle()
|
||||
m.top.trickPlayBar.filledBarBlendColor = "0xFF0000FF"
|
||||
m.top.bufferingBar.filledBarBlendColor = "0xFF0000FF"
|
||||
m.top.retrievingBar.filledBarBlendColor = "0xFF0000FF"
|
||||
|
||||
' Find the BusySpinner built into the Video node
|
||||
busySpinner = FindChildNodeOfType(m.top, "BusySpinner")
|
||||
if busySpinner <> invalid
|
||||
busySpinner.poster.blendColor = "0xFF0000FF"
|
||||
end if
|
||||
end function
|
||||
|
||||
function FindChildNodeOfType(node as object, nodeType as string) as object
|
||||
if node.subtype() = nodeType
|
||||
return node
|
||||
end if
|
||||
|
||||
childCount = node.getChildCount()
|
||||
children = node.getChildren(childCount, 0)
|
||||
for i = 0 to childCount - 1
|
||||
child = FindChildNodeOfType(children[i], nodeType)
|
||||
if child <> invalid
|
||||
return child
|
||||
end if
|
||||
end for
|
||||
|
||||
return invalid
|
||||
end function
|
||||
@@ -0,0 +1,86 @@
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
|
||||
namespace VideoUtils
|
||||
function PlayVideo(contentNode as object) as void
|
||||
CloseVideo(false)
|
||||
|
||||
container = GetVideoContainer()
|
||||
videoPlayer = container.createChild("videoPlayer")
|
||||
videoPlayer.id = "VideoPlayer"
|
||||
videoPlayer@.BindNode(invalid)
|
||||
|
||||
videoPlayer@.PlayWithContent(contentNode)
|
||||
|
||||
if container.fullscreen
|
||||
NodeSetFocus(videoPlayer, true)
|
||||
|
||||
dialog = m.top.getScene().dialog
|
||||
if dialog <> invalid
|
||||
dialog.close = true
|
||||
end if
|
||||
end if
|
||||
end function
|
||||
|
||||
function CloseVideo(setFocus = true as boolean) as void
|
||||
videoPlayer = GetVideoPlayer()
|
||||
if videoPlayer = invalid
|
||||
return
|
||||
end if
|
||||
videoPlayer@.Close(invalid)
|
||||
|
||||
if setFocus
|
||||
videoPlayer.appController@.FocusTopScreen(invalid)
|
||||
end if
|
||||
end function
|
||||
|
||||
function GetVideoPlayer() as object
|
||||
container = GetVideoContainer()
|
||||
if container = invalid or container.getChildCount() = 0
|
||||
return invalid
|
||||
end if
|
||||
return container.getChild(0)
|
||||
end function
|
||||
|
||||
function GetVideoContainer() as object
|
||||
return m.top.getScene().findNode("VideoContainer")
|
||||
end function
|
||||
|
||||
function ToggleVideoPictureInPicture() as boolean
|
||||
videoPlayer = GetVideoPlayer()
|
||||
if videoPlayer = invalid
|
||||
return false
|
||||
end if
|
||||
videoContainer = GetVideoContainer()
|
||||
videoContainer.fullscreen = not videoContainer.fullscreen
|
||||
if videoContainer.fullscreen
|
||||
NodeSetFocus(videoPlayer, true)
|
||||
else
|
||||
videoPlayer.appController@.FocusTopScreen(invalid)
|
||||
end if
|
||||
return true
|
||||
end function
|
||||
|
||||
function IsVideoPlayerOpen() as boolean
|
||||
return GetVideoPlayer() <> invalid
|
||||
end function
|
||||
|
||||
function PauseVideo() as void
|
||||
player = GetVideoPlayer()
|
||||
if player = invalid
|
||||
return
|
||||
end if
|
||||
player.control = "pause"
|
||||
end function
|
||||
|
||||
function ResumeVideo() as void
|
||||
player = GetVideoPlayer()
|
||||
if player = invalid
|
||||
return
|
||||
end if
|
||||
player.control = "resume"
|
||||
end function
|
||||
|
||||
end namespace
|
||||
|
||||
|
||||
Reference in new issue
Block a user