Refactor and fix player (#19)
* Refactor and fix player * Rename functions, fix video loading indicator * Hide loading indicator on exit
This commit is contained in:
1 parent
2d1490f925
commit
68a8d61eb0
14 files changed
+388
-329
No files matched your search
@@ -6,6 +6,7 @@ function Init()
|
|||||||
m.top.ObserveField("rowItemSelected", "OnHomeGridScreenVideoSelected")
|
m.top.ObserveField("rowItemSelected", "OnHomeGridScreenVideoSelected")
|
||||||
m.top.ObserveField("focus", "OnFocusChange")
|
m.top.ObserveField("focus", "OnFocusChange")
|
||||||
m.top.ObserveField("playvideo", "OnPlayVideoCommand")
|
m.top.ObserveField("playvideo", "OnPlayVideoCommand")
|
||||||
|
m.top.ObserveField("refresh", "OnRefresh")
|
||||||
|
|
||||||
m.top.focus = true
|
m.top.focus = true
|
||||||
|
|
||||||
@@ -18,6 +19,10 @@ function OnFocusChange()
|
|||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function OnRefresh()
|
||||||
|
InitContent()
|
||||||
|
end function
|
||||||
|
|
||||||
function InitContent()
|
function InitContent()
|
||||||
m.sortedContent = []
|
m.sortedContent = []
|
||||||
contentNode = CreateObject("roSGNode", "ContentNode")
|
contentNode = CreateObject("roSGNode", "ContentNode")
|
||||||
@@ -106,23 +111,12 @@ function OnHomeGridScreenVideoSelected(event as object) as void
|
|||||||
|
|
||||||
videoId = itemContent.videoId
|
videoId = itemContent.videoId
|
||||||
|
|
||||||
CloseVideo()
|
PlayVideo(videoId, m.top)
|
||||||
ShowVideoScreen(videoId, m.top)
|
|
||||||
end function
|
|
||||||
|
|
||||||
function CloseVideo()
|
|
||||||
if m.videoPlayer <> invalid
|
|
||||||
m.videoPlayer.control = "stop"
|
|
||||||
m.videoPlayer.visible = false
|
|
||||||
m.videoPlayer.getParent().removeChild(m.videoPlayer)
|
|
||||||
m.videoPlayer = invalid
|
|
||||||
end if
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnPlayVideoCommand()
|
function OnPlayVideoCommand()
|
||||||
videoId = m.top.playvideo
|
videoId = m.top.playvideo
|
||||||
CloseVideo()
|
PlayVideo(videoId)
|
||||||
ShowVideoScreen(videoId, m.top)
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
<field id="escape" type="string" alwaysNotify="true" />
|
<field id="escape" type="string" alwaysNotify="true" />
|
||||||
<field id="focus" type="boolean" alwaysNotify="true" />
|
<field id="focus" type="boolean" alwaysNotify="true" />
|
||||||
<field id="playvideo" type="string" alwaysNotify="true" />
|
<field id="playvideo" type="string" alwaysNotify="true" />
|
||||||
|
<field id="refresh" type="boolean" alwaysNotify="true" />
|
||||||
</interface>
|
</interface>
|
||||||
<children>
|
<children>
|
||||||
<RowList
|
<RowList
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<BusySpinner
|
<BusySpinner
|
||||||
id="busySpinner"
|
id="busySpinner"
|
||||||
inheritParentOpacity="false"
|
inheritParentOpacity="false"
|
||||||
spinInterval="0.8" />
|
spinInterval="1" />
|
||||||
</Rectangle>
|
</Rectangle>
|
||||||
</children>
|
</children>
|
||||||
</component>
|
</component>
|
||||||
+10
-31
@@ -1,4 +1,5 @@
|
|||||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
||||||
|
import "pkg:/components/VideoPlayer/Video.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
log.initializeLogManager(["log_PrintTransport"], 2)
|
log.initializeLogManager(["log_PrintTransport"], 2)
|
||||||
@@ -6,9 +7,13 @@ function Init()
|
|||||||
m.top.backgroundColor = "0x242424FF"
|
m.top.backgroundColor = "0x242424FF"
|
||||||
m.top.backgroundURI = ""
|
m.top.backgroundURI = ""
|
||||||
|
|
||||||
loadingIndicator = m.top.findNode("LoadingIndicator")
|
m.loadingIndicator = m.top.findNode("LoadingIndicator")
|
||||||
m.global.addFields({ loadingIndicator: loadingIndicator })
|
m.videoContainer = m.top.findNode("VideoContainer")
|
||||||
m.global.loadingIndicator.visible = true
|
m.global.addFields({
|
||||||
|
loadingIndicator: m.loadingIndicator,
|
||||||
|
videoContainer: m.videoContainer
|
||||||
|
})
|
||||||
|
m.loadingIndicator.visible = true
|
||||||
|
|
||||||
m.homeGridScreen = m.top.findNode("HomeGridScreen")
|
m.homeGridScreen = m.top.findNode("HomeGridScreen")
|
||||||
m.homeGridScreen.ObserveField("escape", "OnHomeGridScreenEscape")
|
m.homeGridScreen.ObserveField("escape", "OnHomeGridScreenEscape")
|
||||||
@@ -76,38 +81,12 @@ function OnNavIndexChange() as void
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function OnWebServerLogin()
|
function OnWebServerLogin()
|
||||||
' TODO: refresh same component instead of creating a new one
|
m.homeGridScreen.refresh = true
|
||||||
m.global.loadingIndicator.visible = true
|
|
||||||
homeIndex = GetIndexOfChild(m.top, m.homeGridScreen.id)
|
|
||||||
newHomeGridScreen = CreateObject("roSGNode", "HomeGridScreen")
|
|
||||||
m.top.replaceChild(newHomeGridScreen, homeIndex)
|
|
||||||
m.homeGridScreen = newHomeGridScreen
|
|
||||||
m.homeGridScreen.id = "HomeGridScreen"
|
|
||||||
m.homeGridScreen.ObserveField("escape", "OnHomeGridScreenEscape")
|
|
||||||
|
|
||||||
' Selecting home
|
|
||||||
m.navBar.focusIndex = -1
|
|
||||||
m.homeGridScreen.focus = true
|
|
||||||
|
|
||||||
m.searchScreen.visible = false
|
|
||||||
m.homeGridScreen.visible = true
|
|
||||||
m.settingsScreen.visible = false
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnWebServerCommand()
|
function OnWebServerCommand()
|
||||||
if m.serverTask.command.StartsWith("play:")
|
if m.serverTask.command.StartsWith("play:")
|
||||||
' Selecting home
|
PlayVideo(m.serverTask.command.Mid(5))
|
||||||
m.navBar.focusIndex = -1
|
|
||||||
m.homeGridScreen.focus = true
|
|
||||||
|
|
||||||
m.searchScreen.visible = false
|
|
||||||
m.homeGridScreen.visible = true
|
|
||||||
m.settingsScreen.visible = false
|
|
||||||
' Trigger play video from home
|
|
||||||
' TODO: allow returning to current screen, instead of home
|
|
||||||
' BUG: if current video is playing in search screen, new video does not play
|
|
||||||
' TODO: Owner of video player needs to be independant
|
|
||||||
m.homeGridScreen.playvideo = m.serverTask.command.Mid(5)
|
|
||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
<HomeGridScreen id="HomeGridScreen" />
|
<HomeGridScreen id="HomeGridScreen" />
|
||||||
<SettingsScreen id="SettingsScreen" visible="false" />
|
<SettingsScreen id="SettingsScreen" visible="false" />
|
||||||
<NavBar id="NavBar" />
|
<NavBar id="NavBar" />
|
||||||
|
<VideoContainer id="VideoContainer" />
|
||||||
<LoadingIndicator id="LoadingIndicator" />
|
<LoadingIndicator id="LoadingIndicator" />
|
||||||
</children>
|
</children>
|
||||||
</component>
|
</component>
|
||||||
@@ -141,7 +141,7 @@ function OnSearchVideoSelected(event as object)
|
|||||||
itemContent = rowContent.GetChild(selectedRowItem)
|
itemContent = rowContent.GetChild(selectedRowItem)
|
||||||
|
|
||||||
videoId = itemContent.videoId
|
videoId = itemContent.videoId
|
||||||
ShowVideoScreen(videoId, m.top)
|
PlayVideo(videoId, m.top)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
import "pkg:/source/services/SponsorBlock.bs"
|
import "pkg:/source/services/SponsorBlock.bs"
|
||||||
|
|
||||||
function Init()
|
|
||||||
m.top.functionName = "TaskMain"
|
|
||||||
end function
|
|
||||||
|
|
||||||
function TaskMain()
|
function TaskMain()
|
||||||
input = m.top.getField("input")
|
input = m.top.getField("input")
|
||||||
videoId = input.videoId
|
videoId = input.videoId
|
||||||
|
|||||||
@@ -1,212 +1,35 @@
|
|||||||
import "pkg:/source/services/Invidious.bs"
|
import "pkg:/source/services/Invidious.bs"
|
||||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||||
|
import "pkg:/source/roku_modules/rokupromise/Promise.brs"
|
||||||
|
|
||||||
function ShowVideoScreen(videoId as string, sender as object)
|
function PlayVideo(videoId as string, sender = invalid as object)
|
||||||
m.videoPlayer = CreateObject("roSGNode", "VideoPlayer")
|
CloseVideo(false)
|
||||||
m.videoPlayer.sender = sender
|
videoContainer = GetVideoContainer()
|
||||||
m.videoPlayer.addFields({
|
if sender <> invalid
|
||||||
videoPlayingSuccess: false,
|
videoContainer.sender = sender
|
||||||
ignoreNextFinishedState: false,
|
end if
|
||||||
videoId: videoId
|
videoContainer.videoPlayer = videoContainer.createChild("VideoPlayer")
|
||||||
})
|
videoContainer.videoPlayer.videoId = videoId
|
||||||
|
videoContainer.videoPlayer.SetFocus(true)
|
||||||
m.videoPlayer.getScene().AppendChild(m.videoPlayer)
|
|
||||||
|
|
||||||
m.videoPlayer.trickPlayBar.filledBarBlendColor = "0xFF0000FF"
|
|
||||||
m.videoPlayer.bufferingBar.filledBarBlendColor = "0xFF0000FF"
|
|
||||||
m.videoPlayer.retrievingBar.filledBarBlendColor = "0xFF0000FF"
|
|
||||||
|
|
||||||
m.videoPlayer.visible = true
|
|
||||||
m.videoPlayer.SetFocus(true)
|
|
||||||
|
|
||||||
m.videoPlayer.ObserveField("state", "OnVideoPlayerStateChange")
|
|
||||||
|
|
||||||
StartVideoDetailsTask(videoId)
|
|
||||||
StartSponsorBlockTask(videoId)
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnVideoPlayerStateChange() as void
|
function CloseVideo(setFocus = true as boolean)
|
||||||
state = m.videoPlayer.state
|
videoContainer = GetVideoContainer()
|
||||||
|
if videoContainer.videoPlayer <> invalid
|
||||||
' If we successfully played the video, then any error that comes later is not due to rate limiting.
|
videoContainer.videoPlayer.control = "stop"
|
||||||
' This is to reduce false positives, as we do not want retry another link if the first link is working fine.
|
videoContainer.RemoveChild(videoContainer.videoPlayer)
|
||||||
if state = "playing"
|
videoContainer.videoPlayer = invalid
|
||||||
m.videoPlayer.videoPlayingSuccess = true
|
|
||||||
|
|
||||||
if m.videoPlayer.visible = false and m.videoPlayer.embedded = true
|
|
||||||
m.videoPlayer.visible = true
|
|
||||||
end if
|
end if
|
||||||
end if
|
if setFocus and videoContainer.sender <> invalid
|
||||||
|
if videoContainer.sender.hasField("focus")
|
||||||
if state = "error"
|
videoContainer.sender.focus = true
|
||||||
' A hack to see if we could use the proxy here
|
|
||||||
if m.videoPlayingSuccess <> true
|
|
||||||
errorInfo = m.videoPlayer.errorInfo
|
|
||||||
' http for stream format, mediaerror for DASH
|
|
||||||
if errorInfo.category = "http" or errorInfo.category = "mediaerror"
|
|
||||||
url = m.videoPlayer.content.url
|
|
||||||
if url.InStr("local=true") = -1
|
|
||||||
print(`Video ${url} failed to play. Trying a proxy (local=true)`)
|
|
||||||
if url.InStr("?") = -1
|
|
||||||
url += "?local=true"
|
|
||||||
else
|
else
|
||||||
url += "&local=true"
|
videoContainer.sender.SetFocus(true)
|
||||||
end if
|
|
||||||
m.videoPlayer.content.url = url
|
|
||||||
' This video errored, and is about to finish, so don't close the video yet
|
|
||||||
' TODO: perhaps creating a second player is better?
|
|
||||||
m.videoPlayer.ignoreNextFinishedState = true
|
|
||||||
m.videoPlayer.control = "play"
|
|
||||||
return
|
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
end if
|
m.global.loadingIndicator.visible = false
|
||||||
end if
|
|
||||||
|
|
||||||
if state = "finished" and m.videoPlayer.ignoreNextFinishedState = true
|
|
||||||
m.videoPlayer.ignoreNextFinishedState = false
|
|
||||||
return
|
|
||||||
end if
|
|
||||||
|
|
||||||
if state = "error" or state = "finished"
|
|
||||||
CloseVideoPlayer()
|
|
||||||
end if
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function CloseVideoPlayer()
|
function GetVideoContainer() as object
|
||||||
sender = m.videoPlayer.sender
|
return m.global.videoContainer
|
||||||
m.videoPlayer.control = "stop"
|
|
||||||
m.videoPlayer.visible = false
|
|
||||||
m.videoPlayer.getParent().RemoveChild(m.videoPlayer)
|
|
||||||
m.videoPlayer = invalid
|
|
||||||
sender.focus = true
|
|
||||||
end function
|
|
||||||
|
|
||||||
function StartVideoDetailsTask(videoId as string)
|
|
||||||
createTaskPromise("VideoDetailsTask", {
|
|
||||||
input: {
|
|
||||||
videoId: videoId
|
|
||||||
}
|
|
||||||
}).then(function(task as object) as void
|
|
||||||
if m.videoPlayer.control = "stop"
|
|
||||||
return
|
|
||||||
end if
|
|
||||||
videoId = task.output.videoId
|
|
||||||
metadata = task.output.metadata
|
|
||||||
if metadata <> invalid
|
|
||||||
contentNode = CreateObject("roSGNode", "ContentNode")
|
|
||||||
contentNode.addFields({
|
|
||||||
videoId: videoId,
|
|
||||||
metadata: metadata
|
|
||||||
})
|
|
||||||
|
|
||||||
if metadata.hlsUrl <> invalid
|
|
||||||
contentNode.url = metadata.hlsUrl
|
|
||||||
else if metadata.dashUrl <> invalid
|
|
||||||
#if DASH_THUMBNAILS
|
|
||||||
' Redirect to our server so we can inject thumbnails (storyboards) into the DASH manifest
|
|
||||||
contentNode.url = `http://${GetLocalIpAddress()}:8888/dash?v=${videoId}`
|
|
||||||
#else
|
|
||||||
contentNode.url = metadata.dashUrl
|
|
||||||
#end if
|
|
||||||
|
|
||||||
else
|
|
||||||
stream = metadata.formatStreams[metadata.formatStreams.Count() - 1]
|
|
||||||
itag = stream.itag
|
|
||||||
' Use an url relative to the host, so we can proxy(local=true) in case it fails
|
|
||||||
contentNode.url = Invidious.GetVideoUrl(videoId, itag, false)
|
|
||||||
end if
|
|
||||||
|
|
||||||
contentNode.title = metadata.title
|
|
||||||
contentNode.secondaryTitle = metadata.author
|
|
||||||
SetCaptions(metadata, m.videoPlayer, contentNode)
|
|
||||||
m.videoPlayer.content = contentNode
|
|
||||||
m.videoPlayer.control = "play"
|
|
||||||
else
|
|
||||||
ErrorMessage(`Failed to load video ${videoId}`, "Video load fail")
|
|
||||||
CloseVideoPlayer()
|
|
||||||
end if
|
|
||||||
end function)
|
|
||||||
end function
|
|
||||||
|
|
||||||
function StartSponsorBlockTask(videoId as string)
|
|
||||||
createTaskPromise("SponsorBlockTask", {
|
|
||||||
input: {
|
|
||||||
videoId: videoId
|
|
||||||
}
|
|
||||||
}).then(function(task as object)
|
|
||||||
skipSegments = task.output.skipSegments
|
|
||||||
barPath = task.output.barPath
|
|
||||||
if skipSegments <> invalid
|
|
||||||
m.videoPlayer.addFields({ skipSegments: skipSegments })
|
|
||||||
m.videoPlayer.seekMode = "accurate"
|
|
||||||
if barPath <> invalid
|
|
||||||
m.videoPlayer.trickPlayBar.trackImageUri = barPath
|
|
||||||
m.videoPlayer.trickPlayBar.filledBarBlendColor = "0xFF000080"
|
|
||||||
end if
|
|
||||||
|
|
||||||
m.videoPlayer.ObserveField("position", "OnPositionChangeSkipSponsorBlockSections")
|
|
||||||
end if
|
|
||||||
end function)
|
|
||||||
end function
|
|
||||||
|
|
||||||
function SetCaptions(metadata as object, videoPlayer as object, contentNode as object) as void
|
|
||||||
' TODO: check if we have caption settings ON
|
|
||||||
' TODO: read favorate language from system settings
|
|
||||||
' TODO: populate list of caption tracks
|
|
||||||
if metadata.captions.Count() = 0
|
|
||||||
return
|
|
||||||
end if
|
|
||||||
videoPlayer.globalCaptionMode = "ON"
|
|
||||||
contentNode.ClosedCaptions = True
|
|
||||||
selectedCaption = metadata.captions[0]
|
|
||||||
|
|
||||||
' Use favorite caption langauage, or the first one
|
|
||||||
for each caption in metadata.captions
|
|
||||||
if caption.language_code = "en"
|
|
||||||
selectedCaption = caption
|
|
||||||
exit for
|
|
||||||
end if
|
|
||||||
end for
|
|
||||||
|
|
||||||
contentNode.SubtitleConfig = {
|
|
||||||
ShowSubtitle: 1,
|
|
||||||
TrackName: InvidiousSettings.GetSelectedInstance() + selectedCaption.url
|
|
||||||
}
|
|
||||||
end function
|
|
||||||
|
|
||||||
function OnPositionChangeSkipSponsorBlockSections() as void
|
|
||||||
shouldMute = false
|
|
||||||
muteCategory = ""
|
|
||||||
segments = m.videoPlayer.skipSegments
|
|
||||||
for each segment in segments
|
|
||||||
' TODO: handle other action types
|
|
||||||
if segment["actionType"] = "skip"
|
|
||||||
segmentRange = segment["segment"]
|
|
||||||
segmentStart = segmentRange[0]
|
|
||||||
segmentEnd = segmentRange[1]
|
|
||||||
currentPosition = m.videoPlayer.position
|
|
||||||
if (segmentStart < currentPosition) and ((segmentEnd - 1) > currentPosition)
|
|
||||||
' TODO: if segmentEnd is at the end of the video, close video
|
|
||||||
m.videoPlayer.seek = segmentEnd
|
|
||||||
print("Skiping section:" + segment["category"])
|
|
||||||
return
|
|
||||||
end if
|
|
||||||
end if
|
|
||||||
if segment["actionType"] = "mute"
|
|
||||||
segmentRange = segment["segment"]
|
|
||||||
segmentStart = segmentRange[0]
|
|
||||||
segmentEnd = segmentRange[1]
|
|
||||||
currentPosition = m.videoPlayer.position
|
|
||||||
if (segmentStart < currentPosition) and (segmentEnd > currentPosition)
|
|
||||||
shouldMute = true
|
|
||||||
muteCategory = segment["category"]
|
|
||||||
exit for
|
|
||||||
end if
|
|
||||||
end if
|
|
||||||
end for
|
|
||||||
if m.videoPlayer.mute <> shouldMute
|
|
||||||
print(`Muting section: ${muteCategory} - ${shouldMute}`)
|
|
||||||
m.videoPlayer.mute = shouldMute
|
|
||||||
end if
|
|
||||||
end function
|
end function
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<component name="VideoContainer" extends="Group">
|
||||||
|
<interface>
|
||||||
|
<field id="videoPlayer" type="node" />
|
||||||
|
<field id="sender" type="node" />
|
||||||
|
</interface>
|
||||||
|
</component>
|
||||||
@@ -1,82 +1,27 @@
|
|||||||
import "pkg:/source/utils/TimeUtils.bs"
|
import "pkg:/source/utils/TimeUtils.bs"
|
||||||
import "pkg:/source/services/SponsorBlock.bs"
|
import "pkg:/source/services/SponsorBlock.bs"
|
||||||
|
import "pkg:/components/VideoPlayer/Video.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
SetChapterLabel()
|
SetupSponsorBlock()
|
||||||
m.timeLabel = FindTimeLabel()
|
m.videoDetailsTask = m.top.findNode("VideoDetailsTask")
|
||||||
m.top.trickPlayBar.observeField("visible", "OnTrickPlayBarVisible")
|
m.busySpinner = FindChildNodeOfType(m.top, "BusySpinner")
|
||||||
m.chapterLabelTimer = m.top.findNode("chapterLabelTimer")
|
m.busySpinnerLabel = FindChildNodeOfType(m.busySpinner, "Label")
|
||||||
m.chapterLabelTimer.observeField("fire", "OnChapterLabelTimer")
|
' TODO: show spinner while fetching video details
|
||||||
end function
|
SetupBusySpinner()
|
||||||
|
m.global.loadingIndicator.visible = true
|
||||||
|
|
||||||
' This is a hack to access the position of the trickplay
|
m.videoPlayingSuccess = false
|
||||||
function FindTimeLabel() as object
|
m.ignoreNextFinishedState = false
|
||||||
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()
|
m.top.trickPlayBar.filledBarBlendColor = "0xFF0000FF"
|
||||||
if m.top.trickPlayBar.visible
|
m.top.bufferingBar.filledBarBlendColor = "0xFF0000FF"
|
||||||
m.top.chapter = ""
|
m.top.retrievingBar.filledBarBlendColor = "0xFF0000FF"
|
||||||
m.chapterLabelTimer.control = "start"
|
|
||||||
else
|
|
||||||
m.chapterLabelTimer.control = "stop"
|
|
||||||
end if
|
|
||||||
end function
|
|
||||||
|
|
||||||
function OnChapterLabelTimer() as void
|
m.top.observeField("control", "OnControlChange")
|
||||||
if m.timeLabel = invalid or m.top.skipSegments = invalid
|
m.top.observeField("videoId", "StartVideoDetailsTask")
|
||||||
return
|
|
||||||
end if
|
|
||||||
|
|
||||||
if m.sponsorBlockLastTime = m.timeLabel.text
|
m.top.ObserveField("state", "OnVideoPlayerStateChange")
|
||||||
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.top.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 SetChapterLabel()
|
|
||||||
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
|
end function
|
||||||
|
|
||||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||||
@@ -90,10 +35,146 @@ function OnkeyEvent(key as string, press as boolean) as boolean
|
|||||||
return false
|
return false
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function CloseVideo()
|
function OnControlChange()
|
||||||
sender = m.top.sender
|
if m.top.control = "stop"
|
||||||
m.top.control = "stop"
|
m.sponsorBlockTask.control = "stop"
|
||||||
m.top.visible = false
|
m.videoDetailsTask.control = "stop"
|
||||||
m.top.getParent().removeChild(m.videoPlayer)
|
end if
|
||||||
sender.focus = true
|
end function
|
||||||
|
|
||||||
|
function StartVideoDetailsTask()
|
||||||
|
m.videoDetailsTask.input = { videoId: m.top.videoId }
|
||||||
|
m.videoDetailsTask.observeField("output", "OnVideoDetailsTaskResults")
|
||||||
|
m.videoDetailsTask.control = "run"
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnVideoDetailsTaskResults() as void
|
||||||
|
task = m.videoDetailsTask
|
||||||
|
videoId = task.output.videoId
|
||||||
|
metadata = task.output.metadata
|
||||||
|
if videoId <> m.top.videoId
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
if metadata = invalid
|
||||||
|
m.global.loadingIndicator.visible = false
|
||||||
|
ErrorMessage(`Failed to load video information for ${videoId}`, "Video load fail")
|
||||||
|
CloseVideo()
|
||||||
|
end if
|
||||||
|
|
||||||
|
contentNode = CreateObject("roSGNode", "ContentNode")
|
||||||
|
contentNode.addFields({ metadata: metadata })
|
||||||
|
|
||||||
|
if metadata.hlsUrl <> invalid
|
||||||
|
contentNode.url = metadata.hlsUrl
|
||||||
|
else if metadata.dashUrl <> invalid
|
||||||
|
#if DASH_THUMBNAILS
|
||||||
|
' Redirect to our server so we can inject thumbnails (storyboards) into the DASH manifest
|
||||||
|
contentNode.url = `http://${GetLocalIpAddress()}:8888/dash?v=${videoId}`
|
||||||
|
#else
|
||||||
|
contentNode.url = metadata.dashUrl
|
||||||
|
#end if
|
||||||
|
|
||||||
|
else
|
||||||
|
stream = metadata.formatStreams[metadata.formatStreams.Count() - 1]
|
||||||
|
itag = stream.itag
|
||||||
|
' Use an url relative to the host, so we can proxy(local=true) in case it fails
|
||||||
|
contentNode.url = Invidious.GetVideoUrl(videoId, itag, false)
|
||||||
|
end if
|
||||||
|
|
||||||
|
contentNode.title = metadata.title
|
||||||
|
contentNode.secondaryTitle = metadata.author
|
||||||
|
SetCaptions(metadata, m.top, contentNode)
|
||||||
|
m.global.loadingIndicator.visible = false
|
||||||
|
m.top.content = contentNode
|
||||||
|
m.top.control = "play"
|
||||||
|
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()
|
||||||
|
m.busySpinner.poster.width = 150
|
||||||
|
m.busySpinner.poster.height = 150
|
||||||
|
m.busySpinner.poster.uri = "pkg:/images/spinner.png"
|
||||||
|
m.busySpinner.observeField("translation", "OnSpinnerMoved")
|
||||||
|
m.busySpinnerLabel.width = 150
|
||||||
|
m.busySpinnerLabel.height = 150
|
||||||
|
m.busySpinnerLabel.translation = [0, 0]
|
||||||
|
m.busySpinnerLabel.observeField("translation", "OnSpinnerLabelMoved")
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnSpinnerMoved()
|
||||||
|
currentTranslation = m.busySpinner.translation
|
||||||
|
parentRect = m.top.boundingRect()
|
||||||
|
centerx = (parentRect.width - m.busySpinner.poster.width) / 2
|
||||||
|
centery = (parentRect.height - m.busySpinner.poster.height) / 2
|
||||||
|
|
||||||
|
if currentTranslation[0] <> centerx or currentTranslation[1] <> centery
|
||||||
|
m.busySpinner.translation = [centerx, centery]
|
||||||
|
end if
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnSpinnerLabelMoved()
|
||||||
|
currentTranslation = m.busySpinnerLabel.translation
|
||||||
|
if currentTranslation[0] <> 0 or currentTranslation[1] <> 0
|
||||||
|
m.busySpinnerLabel.translation = [0, 0]
|
||||||
|
end if
|
||||||
|
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"
|
||||||
|
m.videoPlayingSuccess = true
|
||||||
|
end if
|
||||||
|
|
||||||
|
if state = "error"
|
||||||
|
' A hack to see if we could use the proxy here
|
||||||
|
if m.videoPlayingSuccess <> true
|
||||||
|
errorInfo = m.top.errorInfo
|
||||||
|
' http for stream format, mediaerror for DASH
|
||||||
|
if errorInfo.category = "http" or errorInfo.category = "mediaerror"
|
||||||
|
url = m.top.content.url
|
||||||
|
if url.InStr("local=true") = -1
|
||||||
|
print(`Video ${url} failed to play. Trying a proxy (local=true)`)
|
||||||
|
if url.InStr("?") = -1
|
||||||
|
url += "?local=true"
|
||||||
|
else
|
||||||
|
url += "&local=true"
|
||||||
|
end if
|
||||||
|
m.top.content.url = url
|
||||||
|
' This video errored, and is about to finish, so don't close the video yet
|
||||||
|
' TODO: perhaps creating a second player is better?
|
||||||
|
m.ignoreNextFinishedState = true
|
||||||
|
m.top.control = "play"
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
|
if state = "finished" and m.ignoreNextFinishedState = true
|
||||||
|
m.ignoreNextFinishedState = false
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
if state = "error" or state = "finished"
|
||||||
|
CloseVideo()
|
||||||
|
end if
|
||||||
end function
|
end function
|
||||||
@@ -1,11 +1,20 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<component name="VideoPlayer" extends="Video">
|
<component name="VideoPlayer" extends="Video">
|
||||||
|
<script type="text/brightscript" uri="VideoPlayerSponsorBlock.bs" />
|
||||||
|
<script type="text/brightscript" uri="VideoPlayerCaptions.bs" />
|
||||||
<interface>
|
<interface>
|
||||||
<field id="sender" type="node" />
|
|
||||||
<field id="chapter" type="string" alias="chapterLabel.text" />
|
<field id="chapter" type="string" alias="chapterLabel.text" />
|
||||||
|
<field id="videoId" type="string" />
|
||||||
</interface>
|
</interface>
|
||||||
<children>
|
<children>
|
||||||
|
<SponsorBlockTask
|
||||||
|
functionName="TaskMain"
|
||||||
|
id="SponsorBlockTask" />
|
||||||
|
<VideoDetailsTask
|
||||||
|
functionName="TaskMain"
|
||||||
|
id="VideoDetailsTask" />
|
||||||
|
|
||||||
<Label
|
<Label
|
||||||
id="chapterLabel"
|
id="chapterLabel"
|
||||||
width="350"
|
width="350"
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
function SetCaptions(metadata as object, videoPlayer as object, contentNode as object) as void
|
||||||
|
' TODO: check if we have caption settings ON
|
||||||
|
' TODO: read favorate language from system settings
|
||||||
|
' TODO: populate list of caption tracks
|
||||||
|
if metadata.captions.Count() = 0
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
videoPlayer.globalCaptionMode = "ON"
|
||||||
|
contentNode.ClosedCaptions = True
|
||||||
|
selectedCaption = metadata.captions[0]
|
||||||
|
|
||||||
|
' Use favorite caption langauage, or the first one
|
||||||
|
for each caption in metadata.captions
|
||||||
|
if caption.language_code = "en"
|
||||||
|
selectedCaption = caption
|
||||||
|
exit for
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
|
||||||
|
contentNode.SubtitleConfig = {
|
||||||
|
ShowSubtitle: 1,
|
||||||
|
TrackName: InvidiousSettings.GetSelectedInstance() + selectedCaption.url
|
||||||
|
}
|
||||||
|
end function
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
function SetupSponsorBlock()
|
||||||
|
PositionChapterLabel()
|
||||||
|
m.timeLabel = FindTimeLabel()
|
||||||
|
m.top.trickPlayBar.observeField("visible", "OnTrickPlayBarVisible")
|
||||||
|
m.chapterLabelTimer = m.top.findNode("chapterLabelTimer")
|
||||||
|
m.chapterLabelTimer.observeField("fire", "OnChapterLabelTimer")
|
||||||
|
m.sponsorBlockTask = m.top.findNode("SponsorBlockTask")
|
||||||
|
m.top.observeField("videoId", "StartSponsorBlockTask")
|
||||||
|
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()
|
||||||
|
m.sponsorBlockTask.input = { videoId: m.top.videoId }
|
||||||
|
m.sponsorBlockTask.observeField("output", "OnSponsorBlockTaskResults")
|
||||||
|
m.sponsorBlockTask.control = "run"
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnSponsorBlockTaskResults()
|
||||||
|
task = m.sponsorBlockTask
|
||||||
|
skipSegments = task.output.skipSegments
|
||||||
|
barPath = task.output.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
|
||||||
|
shouldMute = false
|
||||||
|
muteCategory = ""
|
||||||
|
segments = m.skipSegments
|
||||||
|
if segments = invalid
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
for each segment in segments
|
||||||
|
' TODO: handle other action types
|
||||||
|
if segment["actionType"] = "skip"
|
||||||
|
segmentRange = segment["segment"]
|
||||||
|
segmentStart = segmentRange[0]
|
||||||
|
segmentEnd = segmentRange[1]
|
||||||
|
currentPosition = m.top.position
|
||||||
|
if (segmentStart < currentPosition) and ((segmentEnd - 1) > currentPosition)
|
||||||
|
' TODO: if segmentEnd is at the end of the video, close video
|
||||||
|
m.top.seek = segmentEnd
|
||||||
|
print("Skiping section:" + segment["category"])
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
|
if segment["actionType"] = "mute"
|
||||||
|
segmentRange = segment["segment"]
|
||||||
|
segmentStart = segmentRange[0]
|
||||||
|
segmentEnd = segmentRange[1]
|
||||||
|
currentPosition = m.top.position
|
||||||
|
if (segmentStart < currentPosition) and (segmentEnd > currentPosition)
|
||||||
|
shouldMute = true
|
||||||
|
muteCategory = segment["category"]
|
||||||
|
exit for
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
|
||||||
|
if m.top.mute <> shouldMute
|
||||||
|
print(`Muting section: ${muteCategory} - ${shouldMute}`)
|
||||||
|
m.top.mute = shouldMute
|
||||||
|
end if
|
||||||
|
end function
|
||||||
@@ -22,7 +22,7 @@ namespace Http
|
|||||||
dashUrl = `${instance}/api/manifest/dash/id/${v}`
|
dashUrl = `${instance}/api/manifest/dash/id/${v}`
|
||||||
|
|
||||||
if metadata = invalid and local = invalid
|
if metadata = invalid and local = invalid
|
||||||
m.Redirect(dashUrl, 302)
|
response.Redirect(dashUrl, 302)
|
||||||
return true
|
return true
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user