Cast using Youtube app (DIAL/LoungeAPI) (#276)
* Dial+Lounge API PoC * format * Fix for chrome * comments * Rate limit and logger stuff * rename route * remove invalid routes * remove device image * Simplify device description * command test * Lint fix * register pairing code * tv code UI * Lint fix * Avoid creating lots of objects * dpad command * small refactor * tweak * validation * timer * fix * Revert "timer" This reverts commit e349565910882408898c9bddda55dadaa9d743de. * Commands * setVolume command * lounge service timer * Some state messages * Lint fix * player state sync * voice handler * Adjustments, and add a TODO list * Lint fix * comment * play at timestamp * Remote screen UI * UI adjustment * Small refactor * Refactor long polling * Add TODO * Manage logging a bit better to avoid spam in DIAL server * cache dial file * logging * comment * Join lounge lazily * long poller tweak * ui tweak * set shouldQuit field * remote connect notification * Lint fix * Randomize device id, new device on start * Lint fix * Lounge disconnect on start * Speed up lounge by not blocking on sent messages * add version to lounge data saved * dial server fix rendezvous * todo * no message * Display network name * playlist changes * Lint fix * tweak params * tweak * player state * comments * Refactor Video Queue (#295) * Refactor Video Queue * Video queue and playlists * Web app casting * queue playlist notification * VideoQueueView work * restore properties * changes * queue notification and previous/next state * Lint fix * very basic error handling * Update changelog and privacy policy --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
1 parent
ec9178d687
commit
7d1ba07286
85 files changed
+3666
-938
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
' TODO:P2 a lot of shared logic with the SponsorBlock notification, should be refactored into a common notification
|
||||
function Init()
|
||||
m.translationAnimation = m.top.findNode("translationAnimation")
|
||||
m.translationAnimationInterpolator = m.top.findNode("translationAnimationInterpolator")
|
||||
m.animationTimer = m.top.findNode("animationTimer")
|
||||
|
||||
m.top.translation = [1280, 20]
|
||||
m.translationAnimation.observeField("state", FuncName(OnAnimationState))
|
||||
m.animationTimer.observeField("fire", FuncName(OnAnimationTimer))
|
||||
end function
|
||||
|
||||
function OnContentSet() as void
|
||||
content = m.top.content
|
||||
if content = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
if not StringUtils.IsNullOrEmpty(content.thumbnail)
|
||||
m.top.thumbnail = content.thumbnail
|
||||
else
|
||||
m.top.thumbnail = "pkg:/images/thumbnail-missing.jpg"
|
||||
end if
|
||||
|
||||
m.top.line1 = content.title
|
||||
end function
|
||||
|
||||
function OnShow()
|
||||
AnimateIn()
|
||||
end function
|
||||
|
||||
function OnAnimationTimer()
|
||||
AnimateOut()
|
||||
end function
|
||||
|
||||
function AnimateIn()
|
||||
m.translationAnimation.unobserveField("state")
|
||||
m.animationTimer.control = "stop"
|
||||
m.animationTimer.control = "start"
|
||||
m.translationAnimation.observeField("state", FuncName(OnAnimationState))
|
||||
|
||||
Animate(false)
|
||||
end function
|
||||
|
||||
function AnimateOut()
|
||||
Animate(true)
|
||||
end function
|
||||
|
||||
function Animate(reverse as boolean) as void
|
||||
' We are already animating in the requested direction
|
||||
if m.translationAnimationInterpolator.reverse = reverse and m.translationAnimation.control <> "none"
|
||||
return
|
||||
end if
|
||||
|
||||
m.translationAnimationInterpolator.reverse = reverse
|
||||
m.translationAnimation.control = "start"
|
||||
end function
|
||||
|
||||
function OnAnimationState()
|
||||
if m.translationAnimation.state = "stopped" and m.translationAnimationInterpolator.reverse = true
|
||||
m.top.getParent().removeChild(m.top)
|
||||
end if
|
||||
end function
|
||||
@@ -0,0 +1,66 @@
|
||||
<component name="VideoQueueNotification" extends="Group">
|
||||
<interface>
|
||||
<field id="content" type="node" onChange="OnContentSet" />
|
||||
<field id="thumbnail" type="uri" alias="thumbnailPoster.uri" />
|
||||
<field id="line1" type="string" alias="line1Label.text" />
|
||||
<field id="hintVisible" type="boolean" alias="hintLabel.visible" />
|
||||
<field id="show" type="boolean" alwaysNotify="true" onChange="OnShow" />
|
||||
</interface>
|
||||
<children>
|
||||
<Poster
|
||||
width="500"
|
||||
height="144"
|
||||
opacity="0.9"
|
||||
uri="pkg:/images/white.9.png">
|
||||
|
||||
<Poster
|
||||
id="thumbnailPoster"
|
||||
loadDisplayMode="scaleToZoom"
|
||||
width="170"
|
||||
height="106"
|
||||
failedBitmapUri="pkg:/images/thumbnail-missing.jpg"
|
||||
translation="[10,10]">
|
||||
</Poster>
|
||||
|
||||
<LayoutGroup
|
||||
itemSpacings="[10]"
|
||||
translation="[190,10]">
|
||||
<Label
|
||||
width="300"
|
||||
font="font:SmallestBoldSystemFont"
|
||||
horizAlign="center"
|
||||
color="0x262626ff"
|
||||
text="Added to queue">
|
||||
<Font role="font" uri="font:BoldSystemFontFile" size="22" />
|
||||
</Label>
|
||||
<Label
|
||||
id="line1Label"
|
||||
width="300"
|
||||
font="font:SmallestSystemFont"
|
||||
maxLines="3"
|
||||
color="0x262626ff"
|
||||
wrap="true" />
|
||||
</LayoutGroup>
|
||||
<Label
|
||||
id="hintLabel"
|
||||
width="480"
|
||||
font="font:SmallestSystemFont"
|
||||
color="0x262626ff"
|
||||
text="Press and hold Options (*) to open the queue"
|
||||
translation="[10,120]" />
|
||||
</Poster>
|
||||
<Animation
|
||||
id="translationAnimation"
|
||||
duration="0.3"
|
||||
optional="true">
|
||||
<Vector2DFieldInterpolator
|
||||
id="translationAnimationInterpolator"
|
||||
key="[0.0, 0.5, 1.0]"
|
||||
keyValue="[ [1280.0, 20.0], [1020.0, 20.0], [760.0, 20.0] ]"
|
||||
fieldToInterp="VideoQueueNotification.translation" />
|
||||
</Animation>
|
||||
<Timer
|
||||
id="animationTimer"
|
||||
duration="3" />
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace VideoQueue
|
||||
const NOTIFICATION_NODE_ID = "VideoQueueNotification"
|
||||
|
||||
function ShowNotifcation(notifications as object, contentNode as object, hintVisible as boolean) as void
|
||||
notification = notifications.findNode(NOTIFICATION_NODE_ID)
|
||||
if notification = invalid
|
||||
notification = notifications.createChild("VideoQueueNotification")
|
||||
notification.id = NOTIFICATION_NODE_ID
|
||||
end if
|
||||
notification.content = contentNode
|
||||
notification.hintVisible = hintVisible
|
||||
notification.show = true
|
||||
end function
|
||||
|
||||
function RemoveNotifcation(notifications as object) as void
|
||||
notification = notifications.findNode(NOTIFICATION_NODE_ID)
|
||||
if notification <> invalid
|
||||
notifications.RemoveChild(notification)
|
||||
end if
|
||||
end function
|
||||
|
||||
function SetVisible(notifications as object, visible as boolean)
|
||||
notification = notifications.findNode(NOTIFICATION_NODE_ID)
|
||||
if notification <> invalid
|
||||
notification.visible = visible
|
||||
end if
|
||||
end function
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,338 @@
|
||||
import "pkg:/components/Services/LoungeService/LoungeMessages.bs"
|
||||
import "pkg:/components/VideoFeed/FeedLoadState.bs"
|
||||
import "pkg:/components/VideoQueue/Notifications/VideoQueueNotificationUtils.bs"
|
||||
import "pkg:/source/AsyncTask/AsyncTask.bs"
|
||||
import "pkg:/source/AsyncTask/Tasks.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/Logging.bs"
|
||||
import "pkg:/source/utils/MathUtils.bs"
|
||||
import "VideoQueueFunctions.bs"
|
||||
|
||||
function Init()
|
||||
m.content = m.top.findNode("Content")
|
||||
m.top.content = m.content
|
||||
m.content.addField("index", "integer", false)
|
||||
m.content.index = m.top.index
|
||||
end function
|
||||
|
||||
function OnIndexChange()
|
||||
index = m.top.index
|
||||
m.content.index = index
|
||||
nodes = m.content.getChildren(-1, 0)
|
||||
for each node in nodes
|
||||
node.queueIndex = index
|
||||
end for
|
||||
UpdateHasPreviousNext()
|
||||
end function
|
||||
|
||||
function OnPlay() as void
|
||||
videoNode = m.content.getChild(m.top.index)
|
||||
if videoNode = invalid
|
||||
m.top.nowPlaying = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
player = m.top.player
|
||||
if player <> invalid
|
||||
content = player.content
|
||||
if content <> invalid and content.videoId = videoNode.videoId
|
||||
if player.state = "paused"
|
||||
player.control = "resume"
|
||||
else
|
||||
player.control = "play"
|
||||
end if
|
||||
return
|
||||
end if
|
||||
|
||||
m.top.closePlayer = true
|
||||
end if
|
||||
|
||||
player = CreateVideoPlayer()
|
||||
player@.PlayWithContent(videoNode)
|
||||
m.top.player = player
|
||||
m.top.nowPlaying = videoNode
|
||||
end function
|
||||
|
||||
function OnPause() as void
|
||||
player = m.top.player
|
||||
if player = invalid
|
||||
return
|
||||
end if
|
||||
player.control = "pause"
|
||||
end function
|
||||
|
||||
function OnPrevious() as void
|
||||
if not m.top.hasPrevious
|
||||
return
|
||||
end if
|
||||
|
||||
m.top.closePlayer = true
|
||||
m.top.index -= 1
|
||||
m.top.play = true
|
||||
end function
|
||||
|
||||
function OnNext() as void
|
||||
if not m.top.hasNext
|
||||
return
|
||||
end if
|
||||
|
||||
m.top.closePlayer = true
|
||||
m.top.index += 1
|
||||
m.top.play = true
|
||||
end function
|
||||
|
||||
function OnClosePlayer() as void
|
||||
m.top.nowPlaying = invalid
|
||||
player = m.top.player
|
||||
if player = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
player@.Close()
|
||||
m.top.player = invalid
|
||||
|
||||
m.top.appController@.FocusTopScreen()
|
||||
end function
|
||||
|
||||
function OnPlayVideo() as void
|
||||
videoNode = m.top.playVideo
|
||||
if videoNode = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
m.top.playVideo = invalid
|
||||
|
||||
nodeParent = videoNode.getParent()
|
||||
if not m.content.isSameNode(nodeParent)
|
||||
videoNode = videoNode.clone(false)
|
||||
end if
|
||||
|
||||
queueCount = m.content.getChildCount()
|
||||
index = m.top.index
|
||||
index += 1
|
||||
if index >= queueCount
|
||||
m.content.appendChild(videoNode)
|
||||
index = m.content.getChildCount() - 1
|
||||
else
|
||||
m.content.insertChild(videoNode, index)
|
||||
end if
|
||||
m.top.index = index
|
||||
|
||||
m.top.closePlayer = true
|
||||
m.top.play = true
|
||||
end function
|
||||
|
||||
function OnPlayPlaylist() as void
|
||||
playPlaylist = m.top.playPlaylist
|
||||
if playPlaylist = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
m.top.playPlaylist = invalid
|
||||
|
||||
if m.loadingPlaylist <> invalid
|
||||
m.loadingPlaylist.UnobserveFieldScoped("loadState")
|
||||
m.loadingPlaylist = invalid
|
||||
end if
|
||||
|
||||
playlistNode = playPlaylist.playlistNode
|
||||
playlistIndex = playPlaylist.playlistIndex
|
||||
|
||||
if playlistNode = invalid or playlistIndex < 0
|
||||
return
|
||||
end if
|
||||
|
||||
m.loadingPlaylist = playlistNode
|
||||
m.loadingPlaylistIndex = playlistIndex
|
||||
m.loadingPlaylistOp = "play"
|
||||
|
||||
if playlistNode.loadState = FeedLoadState.Loaded
|
||||
OnPlaylistLoadStateChange()
|
||||
return
|
||||
end if
|
||||
|
||||
playlistNode.ObserveFieldScoped("loadState", FuncName(OnPlaylistLoadStateChange))
|
||||
playlistNode@.LoadPlaylistAll(m.top.invidious)
|
||||
end function
|
||||
|
||||
function OnPlaylistLoadStateChange() as void
|
||||
if m.loadingPlaylist = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
loadState = m.loadingPlaylist.loadState
|
||||
if loadState = FeedLoadState.None or loadState = FeedLoadState.Error
|
||||
m.loadingPlaylist.UnobserveFieldScoped("loadState")
|
||||
m.loadingPlaylist = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
if loadState <> FeedLoadState.Loaded
|
||||
return
|
||||
end if
|
||||
|
||||
playlistNode = m.loadingPlaylist
|
||||
playlistIndex = m.loadingPlaylistIndex
|
||||
playlistOp = m.loadingPlaylistOp
|
||||
|
||||
m.loadingPlaylist.UnobserveFieldScoped("loadState")
|
||||
m.loadingPlaylist = invalid
|
||||
|
||||
videoNodes = playlistNode.getChildren(-1, 0)
|
||||
if videoNodes.Count() = 0
|
||||
return
|
||||
end if
|
||||
|
||||
LogInfo("Adding", videoNodes.Count(), "videos to the queue")
|
||||
|
||||
for i = 0 to videoNodes.Count() - 1
|
||||
videoNodes[i] = videoNodes[i].clone(false)
|
||||
end for
|
||||
|
||||
if playlistOp = "play"
|
||||
queueCount = m.content.getChildCount()
|
||||
index = m.top.index
|
||||
index += 1
|
||||
if index >= queueCount
|
||||
m.content.appendChildren(videoNodes)
|
||||
else
|
||||
m.content.insertChildren(videoNodes, index)
|
||||
end if
|
||||
|
||||
playlistIndex = MathUtils.Clamp(playlistIndex, 0, videoNodes.Count() - 1)
|
||||
index = index + playlistIndex
|
||||
m.top.index = index
|
||||
|
||||
m.top.closePlayer = true
|
||||
m.top.play = true
|
||||
else if playlistOp = "queue"
|
||||
m.content.appendChildren(videoNodes)
|
||||
UpdateHasPreviousNext()
|
||||
|
||||
queueNotifications = m.top.preferences["misc.queue_notifications"]
|
||||
if queueNotifications
|
||||
hintVisible = m.top.player = invalid or not m.top.videoContainer.fullscreen
|
||||
VideoQueue.ShowNotifcation(m.top.notifications, playlistNode, hintVisible)
|
||||
end if
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnClearQueue()
|
||||
queueCount = m.content.getChildCount()
|
||||
if queueCount > 0
|
||||
m.content.removeChildrenIndex(queueCount, 0)
|
||||
end if
|
||||
|
||||
m.top.closePlayer = true
|
||||
m.top.index = -1
|
||||
end function
|
||||
|
||||
function OnAddToQueue() as void
|
||||
videoNodes = m.top.addToQueue
|
||||
if videoNodes = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
m.top.addToQueue = invalid
|
||||
if videoNodes.Count() = 0
|
||||
return
|
||||
end if
|
||||
|
||||
for i = 0 to videoNodes.Count() - 1
|
||||
videoNodes[i] = videoNodes[i].clone(false)
|
||||
end for
|
||||
|
||||
m.content.appendChildren(videoNodes)
|
||||
UpdateHasPreviousNext()
|
||||
|
||||
queueNotifications = m.top.preferences["misc.queue_notifications"]
|
||||
if queueNotifications
|
||||
node = videoNodes[0]
|
||||
hintVisible = m.top.player = invalid or not m.top.videoContainer.fullscreen
|
||||
VideoQueue.ShowNotifcation(m.top.notifications, node, hintVisible)
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnAddToQueuePlaylist() as void
|
||||
playlistNode = m.top.addToQueuePlaylist
|
||||
if playlistNode = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
m.top.addToQueuePlaylist = invalid
|
||||
|
||||
if m.loadingPlaylist <> invalid
|
||||
m.loadingPlaylist.UnobserveFieldScoped("loadState")
|
||||
m.loadingPlaylist = invalid
|
||||
end if
|
||||
|
||||
m.loadingPlaylist = playlistNode
|
||||
m.loadingPlaylistOp = "queue"
|
||||
|
||||
if playlistNode.loadState = FeedLoadState.Loaded
|
||||
OnPlaylistLoadStateChange()
|
||||
return
|
||||
end if
|
||||
|
||||
playlistNode.ObserveFieldScoped("loadState", FuncName(OnPlaylistLoadStateChange))
|
||||
playlistNode@.LoadPlaylistAll(m.top.invidious)
|
||||
end function
|
||||
|
||||
function OnSetQueueAndIndex() as void
|
||||
setQueueAndIndex = m.top.setQueueAndIndex
|
||||
if setQueueAndIndex = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
m.top.setQueueAndIndex = invalid
|
||||
|
||||
videoNodes = setQueueAndIndex.videoNodes
|
||||
index = setQueueAndIndex.index
|
||||
|
||||
queueCount = m.content.getChildCount()
|
||||
if queueCount > 0
|
||||
m.content.removeChildrenIndex(queueCount, 0)
|
||||
end if
|
||||
|
||||
if videoNodes.Count() > 0
|
||||
m.content.appendChildren(videoNodes)
|
||||
end if
|
||||
|
||||
m.top.index = index
|
||||
end function
|
||||
|
||||
function UpdateHasPreviousNext()
|
||||
queueCount = m.content.getChildCount()
|
||||
index = MathUtils.Clamp(m.top.index, 0, queueCount - 1)
|
||||
m.top.hasPrevious = index > 0
|
||||
m.top.hasNext = index < queueCount - 1
|
||||
end function
|
||||
|
||||
function OnHasPrevious()
|
||||
message = LoungeMessages.OnHasPreviousNextChanged(m.top.hasPrevious, m.top.hasNext)
|
||||
m.top.loungeService.outgoingMessages = [message]
|
||||
end function
|
||||
|
||||
function OnHasNext()
|
||||
' TODO:P1 the hasNext currently does not account for autoplay.
|
||||
message = LoungeMessages.OnHasPreviousNextChanged(m.top.hasPrevious, m.top.hasNext)
|
||||
m.top.loungeService.outgoingMessages = [message]
|
||||
end function
|
||||
|
||||
function CreateVideoPlayer() as object
|
||||
container = m.top.videoContainer
|
||||
videoPlayer = container.createChild("VideoPlayer")
|
||||
videoPlayer.id = "VideoPlayer"
|
||||
videoPlayer@.BindNode()
|
||||
|
||||
if container.fullscreen
|
||||
NodeSetFocus(videoPlayer, true)
|
||||
|
||||
dialog = m.top.getScene().dialog
|
||||
if dialog <> invalid
|
||||
dialog.close = true
|
||||
end if
|
||||
end if
|
||||
|
||||
return videoPlayer
|
||||
end function
|
||||
@@ -0,0 +1,41 @@
|
||||
<component name="VideoQueue" extends="Node">
|
||||
<interface>
|
||||
<field id="content" type="node" />
|
||||
<field id="index" type="integer" value="-1" onChange="OnIndexChange" alwaysNotify="true" />
|
||||
|
||||
<field id="hasPrevious" type="boolean" onChange="OnHasPrevious" />
|
||||
<field id="hasNext" type="boolean" onChange="OnHasNext" />
|
||||
|
||||
<field id="play" type="boolean" alwaysNotify="true" onChange="OnPlay" />
|
||||
<field id="pause" type="boolean" alwaysNotify="true" onChange="OnPause" />
|
||||
<field id="previous" type="boolean" alwaysNotify="true" onChange="OnPrevious" />
|
||||
<field id="next" type="boolean" alwaysNotify="true" onChange="OnNext" />
|
||||
<field id="closePlayer" type="boolean" alwaysNotify="true" onChange="OnClosePlayer" />
|
||||
<field id="playVideo" type="node" alwaysNotify="true" onChange="OnPlayVideo" />
|
||||
<field id="playPlaylist" type="assocarray" alwaysNotify="true" onChange="OnPlayPlaylist" />
|
||||
|
||||
<field id="clearQueue" type="boolean" alwaysNotify="true" onChange="OnClearQueue" />
|
||||
<field id="addToQueue" type="array" onChange="OnAddToQueue" />
|
||||
<field id="addToQueuePlaylist" type="node" onChange="OnAddToQueuePlaylist" />
|
||||
<field id="setQueueAndIndex" type="assocarray" onChange="OnSetQueueAndIndex" />
|
||||
|
||||
<field id="player" type="node" />
|
||||
<field id="nowPlaying" type="node" />
|
||||
|
||||
<field id="invidious" type="node" />
|
||||
<field id="notifications" type="node" />
|
||||
<field id="preferences" type="node" />
|
||||
<field id="videoContainer" type="node" />
|
||||
<field id="appController" type="node" />
|
||||
<field id="loungeService" type="node" />
|
||||
|
||||
<!-- Convenience functions to use from context menu -->
|
||||
<function name="FuncPlayVideo" />
|
||||
<function name="FuncPlayPlaylist" />
|
||||
<function name="FuncAddToQueueVideo" />
|
||||
<function name="FuncAddToQueuePlaylist" />
|
||||
</interface>
|
||||
<children>
|
||||
<ContentNode id="Content" />
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,20 @@
|
||||
' Convenience functions to use from context menu
|
||||
|
||||
function FuncPlayVideo(videoNode as object)
|
||||
m.top.playVideo = videoNode
|
||||
end function
|
||||
|
||||
function FuncPlayPlaylist(playlistNode as object, playlistIndex as integer)
|
||||
m.top.playPlaylist = {
|
||||
playlistNode: playlistNode
|
||||
playlistIndex: playlistIndex
|
||||
}
|
||||
end function
|
||||
|
||||
function FuncAddToQueueVideo(videoNode as object)
|
||||
m.top.addToQueue = [videoNode]
|
||||
end function
|
||||
|
||||
function FuncAddToQueuePlaylist(playlistNode as object)
|
||||
m.top.addToQueuePlaylist = playlistNode
|
||||
end function
|
||||
@@ -0,0 +1,162 @@
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
|
||||
namespace VideoQueueUtils
|
||||
|
||||
function GetQueueDto(videoQueue as object) as object
|
||||
items = []
|
||||
nowPlaying = invalid
|
||||
|
||||
queueNodes = videoQueue.content.getChildren(-1, 0)
|
||||
for each node in queueNodes
|
||||
items.push({
|
||||
type: node.type
|
||||
videoId: node.videoId
|
||||
title: node.title
|
||||
author: node._author
|
||||
thumbnail: node.thumbnail
|
||||
})
|
||||
end for
|
||||
|
||||
nowPlayingNode = videoQueue.nowPlaying
|
||||
if nowPlayingNode <> invalid
|
||||
nowPlaying = {
|
||||
type: nowPlayingNode.type
|
||||
videoId: nowPlayingNode.videoId
|
||||
title: nowPlayingNode.title
|
||||
author: nowPlayingNode._author
|
||||
thumbnail: nowPlayingNode.thumbnail
|
||||
}
|
||||
end if
|
||||
|
||||
return {
|
||||
items: items
|
||||
nowPlaying: nowPlaying
|
||||
index: videoQueue.index
|
||||
}
|
||||
end function
|
||||
|
||||
function IsVideoPlayerFullScreen(videoQueue as object) as boolean
|
||||
return videoQueue.videoContainer.fullscreen
|
||||
end function
|
||||
|
||||
function ToggleVideoPictureInPicture(videoQueue as object) as boolean
|
||||
player = videoQueue.player
|
||||
if player = invalid
|
||||
return false
|
||||
end if
|
||||
videoContainer = videoQueue.videoContainer
|
||||
videoContainer.fullscreen = not videoContainer.fullscreen
|
||||
if videoContainer.fullscreen
|
||||
NodeSetFocus(player, true)
|
||||
else
|
||||
videoQueue.appController@.FocusTopScreen()
|
||||
end if
|
||||
return true
|
||||
end function
|
||||
|
||||
function IsVideoPlayerOpen(videoQueue as object) as boolean
|
||||
return videoQueue.player <> invalid
|
||||
end function
|
||||
|
||||
function Play(videoQueue as object) as boolean
|
||||
player = videoQueue.player
|
||||
if player = invalid
|
||||
return false
|
||||
end if
|
||||
videoQueue.play = true
|
||||
return true
|
||||
end function
|
||||
|
||||
function Pause(videoQueue as object) as boolean
|
||||
player = videoQueue.player
|
||||
if player = invalid
|
||||
return false
|
||||
end if
|
||||
videoQueue.pause = true
|
||||
return true
|
||||
end function
|
||||
|
||||
function Resume(videoQueue as object) as boolean
|
||||
player = videoQueue.player
|
||||
if player = invalid
|
||||
return false
|
||||
end if
|
||||
videoQueue.play = true
|
||||
return true
|
||||
end function
|
||||
|
||||
function TogglePause(videoQueue as object) as boolean
|
||||
player = videoQueue.player
|
||||
if player = invalid
|
||||
return false
|
||||
end if
|
||||
if player.state = "playing"
|
||||
player.control = "pause"
|
||||
return true
|
||||
else if player.state = "paused"
|
||||
player.control = "resume"
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end function
|
||||
|
||||
function PlayNext(videoQueue as object, invidiousNode as object, preferences as object) as boolean
|
||||
if videoQueue.hasNext
|
||||
videoQueue.next = true
|
||||
return true
|
||||
end if
|
||||
|
||||
if preferences["playback.autoplay"] <> true
|
||||
return false
|
||||
end if
|
||||
|
||||
player = videoQueue.player
|
||||
if player = invalid
|
||||
return false
|
||||
end if
|
||||
|
||||
content = player.content
|
||||
if content = invalid
|
||||
return false
|
||||
end if
|
||||
|
||||
metadata = content.metadata
|
||||
if metadata = invalid
|
||||
return false
|
||||
end if
|
||||
|
||||
recommendedVideos = metadata.recommendedVideos
|
||||
if recommendedVideos = invalid
|
||||
return false
|
||||
end if
|
||||
|
||||
if recommendedVideos = invalid or recommendedVideos.Count() = 0
|
||||
return false
|
||||
end if
|
||||
|
||||
queueContent = videoQueue.content
|
||||
for each recommendedVideo in recommendedVideos
|
||||
if recommendedVideo = invalid
|
||||
continue for
|
||||
end if
|
||||
videoId = recommendedVideo.videoId
|
||||
if videoId = invalid
|
||||
continue for
|
||||
end if
|
||||
|
||||
existingVideo = queueContent.findNode(videoId)
|
||||
if existingVideo <> invalid
|
||||
continue for
|
||||
end if
|
||||
|
||||
LogInfo(`Playing next recommended video (${videoId})`)
|
||||
instance = invidiousNode@.GetCurrentInstance()
|
||||
node = InvidiousContent.ToVideoContentNode(invalid, recommendedVideo, instance)
|
||||
videoQueue.playVideo = node
|
||||
return true
|
||||
end for
|
||||
|
||||
return false
|
||||
end function
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,154 @@
|
||||
import "pkg:/components/Navigation/Navigation.bs"
|
||||
import "pkg:/source/AsyncTask/AsyncTask.bs"
|
||||
import "pkg:/source/AsyncTask/Tasks.bs"
|
||||
import "pkg:/source/utils/DisposableObserve.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/Logging.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.queueList = m.top.findNode("queueList")
|
||||
m.queueLabel = m.top.findNode("queueLabel")
|
||||
m.clearButton = m.top.findNode("clearButton")
|
||||
m.showAnimation = m.top.findNode("showAnimation")
|
||||
|
||||
DisposableObserveField(m.clearButton, "buttonSelected", FuncName(OnClearButtonSelected))
|
||||
DisposableObserveField(m.queueList, "itemSelected", FuncName(OnItemSelected))
|
||||
|
||||
SetNavigation(m.queueList, "up", m.clearButton)
|
||||
SetNavigation(m.clearButton, "down", m.queueList)
|
||||
|
||||
m.videosDetailsToLoad = []
|
||||
end function
|
||||
|
||||
function Show(unsued as dynamic)
|
||||
m.showAnimation.control = "start"
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
NodeSetFocus(m.queueList, true)
|
||||
end function
|
||||
|
||||
function OnContentSet() as void
|
||||
content = m.top.content
|
||||
if content = invalid
|
||||
if m.loadDetailsTask <> invalid
|
||||
m.loadDetailsTask.cancel = true
|
||||
m.loadDetailsTask = invalid
|
||||
end if
|
||||
return
|
||||
end if
|
||||
|
||||
if not content.isSameNode(m.queueList.content)
|
||||
m.queueList.content = content
|
||||
end if
|
||||
|
||||
index = content.index
|
||||
if IsInt(index) and index <> -1
|
||||
m.queueLabel.text = `Queue (${index + 1}/${content.getChildCount()})`
|
||||
else
|
||||
m.queueLabel.text = `Queue (${content.getChildCount()})`
|
||||
end if
|
||||
|
||||
LoadVideoDetailsIfNeeded()
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
if NavigationKeyHandler(key, press).handled
|
||||
return true
|
||||
end if
|
||||
|
||||
if press = false
|
||||
return false
|
||||
end if
|
||||
|
||||
if key = "back"
|
||||
Close()
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end function
|
||||
|
||||
function Close()
|
||||
m.top.appController@.PopScreen()
|
||||
m.top.dispose = true
|
||||
end function
|
||||
|
||||
function OnClearButtonSelected()
|
||||
m.top.videoQueue.clearQueue = true
|
||||
end function
|
||||
|
||||
function OnItemSelected() as void
|
||||
content = m.queueList.content
|
||||
if content = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
index = m.queueList.itemSelected
|
||||
if index < 0 or index >= content.getChildCount()
|
||||
return
|
||||
end if
|
||||
|
||||
videoQueue = m.top.videoQueue
|
||||
videoQueue.index = index
|
||||
videoQueue.play = true
|
||||
end function
|
||||
|
||||
function LoadVideoDetailsIfNeeded() as void
|
||||
content = m.queueList.content
|
||||
if content = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
videoNodes = content.getChildren(-1, 0)
|
||||
|
||||
index = m.top.videoQueue.index
|
||||
indexInLoadingArray = -1
|
||||
|
||||
m.videosDetailsToLoad.Clear()
|
||||
for i = 0 to videoNodes.Count() - 1
|
||||
videoNode = videoNodes[i]
|
||||
' If the title is empty, it is likely that the details have not been loaded yet
|
||||
if videoNode.title = ""
|
||||
m.videosDetailsToLoad.Push(videoNode)
|
||||
end if
|
||||
|
||||
if index = i
|
||||
indexInLoadingArray = m.videosDetailsToLoad.Count() - 1
|
||||
end if
|
||||
end for
|
||||
|
||||
for each videoNode in videoNodes
|
||||
if videoNode.title = ""
|
||||
m.videosDetailsToLoad.Push(videoNode)
|
||||
end if
|
||||
end for
|
||||
|
||||
if m.videosDetailsToLoad.Count() = 0
|
||||
return
|
||||
end if
|
||||
|
||||
LogInfo("Loading video details for", m.videosDetailsToLoad.Count(), "videos")
|
||||
|
||||
if m.loadDetailsTask <> invalid
|
||||
m.loadDetailsTask.cancel = true
|
||||
end if
|
||||
|
||||
m.loadDetailsTask = AsyncTask.Start(Tasks.VideoQueueViewContentTask, {
|
||||
videoNodes: m.videosDetailsToLoad
|
||||
invidious: m.top.invidious
|
||||
index: indexInLoadingArray
|
||||
})
|
||||
end function
|
||||
|
||||
function OnDispose()
|
||||
m.queueList.content = invalid
|
||||
DisposeObservers()
|
||||
if m.loadDetailsTask <> invalid
|
||||
m.loadDetailsTask.cancel = true
|
||||
m.loadDetailsTask = invalid
|
||||
end if
|
||||
end function
|
||||
@@ -0,0 +1,65 @@
|
||||
<component name="VideoQueueView" extends="Group" includes="Focus,Disposable">
|
||||
<interface>
|
||||
<field id="content" type="node" onChange="OnContentSet" />
|
||||
<field id="jumpToItem" type="integer" alias="queueList.jumpToItem" />
|
||||
<field id="videoQueue" type="node" />
|
||||
<field id="appController" type="node" />
|
||||
<field id="invidious" type="node" />
|
||||
<function name="Show" />
|
||||
</interface>
|
||||
|
||||
<children>
|
||||
<Rectangle
|
||||
id="background"
|
||||
width="1280"
|
||||
height="720"
|
||||
color="#000000"
|
||||
opacity="0" />
|
||||
<Rectangle
|
||||
id="container"
|
||||
width="470"
|
||||
height="720"
|
||||
translation="[-470,0]"
|
||||
color="0x242424">
|
||||
<Label
|
||||
id="queueLabel"
|
||||
width="270"
|
||||
height="52"
|
||||
text="Queue"
|
||||
vertAlign="center"
|
||||
font="font:MediumBoldSystemFont"
|
||||
translation="[20,20]" />
|
||||
<Button
|
||||
id="clearButton"
|
||||
minWidth="150"
|
||||
height="52"
|
||||
text="Clear"
|
||||
showFocusFootprint="true"
|
||||
translation="[295,15]" />
|
||||
<MarkupGrid
|
||||
id="queueList"
|
||||
itemComponentName="VideoQueueViewCell"
|
||||
itemSize="[432,90]"
|
||||
itemSpacing="[0,15]"
|
||||
numColumns="1"
|
||||
numRows="6"
|
||||
vertFocusAnimationStyle="floatingFocus"
|
||||
translation="[20,90]" />
|
||||
</Rectangle>
|
||||
|
||||
<Animation id="showAnimation"
|
||||
duration="0.3"
|
||||
optional="true">
|
||||
<FloatFieldInterpolator
|
||||
id="fadeInterpolator"
|
||||
key="[0.0, 0.5, 1.0]"
|
||||
keyValue="[0.0, 0.4, 0.8]"
|
||||
fieldToInterp="background.opacity" />
|
||||
<Vector2DFieldInterpolator
|
||||
id="translationInterpolator"
|
||||
key="[0.0, 0.5, 1.0]"
|
||||
keyValue="[[-470,0], [-235,0], [0,0]]"
|
||||
fieldToInterp="container.translation" />
|
||||
</Animation>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,67 @@
|
||||
import "pkg:/source/utils/Logging.bs"
|
||||
import "pkg:/source/utils/TimeUtils.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.durationRect = m.top.FindNode("durationRect")
|
||||
m.durationLabel = m.top.FindNode("durationLabel")
|
||||
end function
|
||||
|
||||
function OnContentSet() as void
|
||||
content = m.top.itemContent
|
||||
if content = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
m.top.title = content.title
|
||||
m.top.thumbnailUri = content.thumbnail
|
||||
|
||||
if ValidInt(content.lengthSeconds) <> 0
|
||||
SetDurationText(content.lengthText)
|
||||
m.top.durationRectVisible = true
|
||||
else
|
||||
m.top.durationRectVisible = false
|
||||
end if
|
||||
|
||||
SetHighlight()
|
||||
end function
|
||||
|
||||
function OnIndexSet() as void
|
||||
SetHighlight()
|
||||
end function
|
||||
|
||||
function SetDurationText(text as string) as void
|
||||
m.top.duration = text
|
||||
|
||||
label = m.durationLabel
|
||||
rect = m.durationRect
|
||||
|
||||
if label = invalid or rect = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
rectParent = rect.getParent()
|
||||
size = label.localBoundingRect()
|
||||
|
||||
rect.width = size.width + 16
|
||||
rect.translation = [rectParent.width - rect.width, rect.translation[1]]
|
||||
end function
|
||||
|
||||
function SetHighlight() as void
|
||||
content = m.top.itemContent
|
||||
if content = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
contentIndex = content.queueIndex
|
||||
index = m.top.index
|
||||
|
||||
if contentIndex = index
|
||||
' bs:disable-next-line LINT3023
|
||||
m.top.thumbnailBlendColor = "#FFFFFFFF"
|
||||
m.top.highlightUri = "pkg:/images/focus_grid.9.png"
|
||||
else
|
||||
m.top.thumbnailBlendColor = "#606060FF"
|
||||
m.top.highlightUri = ""
|
||||
end if
|
||||
end function
|
||||
@@ -0,0 +1,50 @@
|
||||
<component name="VideoQueueViewCell" extends="Group">
|
||||
<interface>
|
||||
<field id="itemContent" type="node" onChange="OnContentSet" />
|
||||
<field id="index" type="integer" onChange="OnIndexSet" />
|
||||
<field id="title" type="string" alias="titleLabel.text" />
|
||||
<field id="thumbnailUri" type="uri" alias="thumbnailPoster.uri" />
|
||||
<field id="thumbnailBlendColor" type="color" alias="thumbnailPoster.blendColor" />
|
||||
<field id="highlightUri" type="uri" alias="highlightPoster.uri" />
|
||||
<field id="duration" type="string" alias="durationLabel.text" />
|
||||
<field id="durationRectVisible" type="boolean" alias="durationRect.visible" />
|
||||
</interface>
|
||||
<children>
|
||||
<Poster
|
||||
id="thumbnailPoster"
|
||||
loadDisplayMode="scaleToZoom"
|
||||
width="160"
|
||||
height="90"
|
||||
failedBitmapUri="pkg:/images/thumbnail-missing.jpg"
|
||||
translation="[2,2]">
|
||||
<Rectangle
|
||||
id="durationRect"
|
||||
width="60"
|
||||
height="26"
|
||||
color="0x000000"
|
||||
opacity="0.8"
|
||||
translation="[100, 58]">
|
||||
<Label
|
||||
height="26"
|
||||
id="durationLabel"
|
||||
horizAlign="center"
|
||||
vertAlign="center"
|
||||
font="font:SmallestSystemFont"
|
||||
translation="[8, 0]" />
|
||||
</Rectangle>
|
||||
</Poster>
|
||||
<Poster
|
||||
id="highlightPoster"
|
||||
blendColor="0xFF1C30"
|
||||
width="164"
|
||||
height="94" />
|
||||
|
||||
<Label
|
||||
id="titleLabel"
|
||||
width="260"
|
||||
font="font:SmallestBoldSystemFont"
|
||||
maxLines="3"
|
||||
wrap="true"
|
||||
translation="[172,2]" />
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,65 @@
|
||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
||||
import "pkg:/source/services/HttpClient.bs"
|
||||
import "pkg:/source/utils/MathUtils.bs"
|
||||
|
||||
@asynctask
|
||||
function VideoQueueViewContentTask(input as object) as object
|
||||
videoNodes = input.videoNodes
|
||||
invidiousNode = input.invidious
|
||||
service = new Invidious.InvidiousService(invidiousNode)
|
||||
instance = service.GetInstance()
|
||||
cancellation = m.top.cancellation
|
||||
|
||||
index = MathUtils.Clamp(input.index - 2, 0, videoNodes.Count() - 1)
|
||||
|
||||
for i = index to videoNodes.Count() - 1
|
||||
videoNode = videoNodes[i]
|
||||
LoadVideoDetail(videoNode, service, instance, cancellation)
|
||||
' Sleep for a bit to avoid creating too much traffic
|
||||
sleep(500)
|
||||
|
||||
if m.top.cancel = true
|
||||
return invalid
|
||||
end if
|
||||
end for
|
||||
|
||||
for i = index - 1 to 0 step -1
|
||||
videoNode = videoNodes[i]
|
||||
LoadVideoDetail(videoNode, service, instance, cancellation)
|
||||
' Sleep for a bit to avoid creating too much traffic
|
||||
sleep(1000)
|
||||
|
||||
if m.top.cancel = true
|
||||
return invalid
|
||||
end if
|
||||
end for
|
||||
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function LoadVideoDetail(videoNode as object, service as object, instance as string, cancellation as object) as void
|
||||
videoId = videoNode.videoId
|
||||
url = `${instance}${Invidious.VIDEOS_ENDPOINT}/${videoId}`
|
||||
|
||||
request = HttpClient.Get(url)
|
||||
request.QueryParams(service.DefaultQueryParams())
|
||||
' A large cache interval, since we don't care about the video detail accuracy
|
||||
request.CacheSeconds(8640000)
|
||||
request.Cancellation(cancellation)
|
||||
|
||||
response = request.Await()
|
||||
metadata = response.Json()
|
||||
|
||||
if not response.IsSuccess() or metadata = invalid
|
||||
LogError("Failed to load video metadata", response.ErrorMessage())
|
||||
if response.StatusCode() = 500
|
||||
' The video is likely not available.
|
||||
' We set the title to make sure we don't try to load it again
|
||||
videoNode.title = "Video not available"
|
||||
end if
|
||||
return
|
||||
end if
|
||||
|
||||
InvidiousContent.ToVideoContentNode(videoNode, metadata, instance)
|
||||
end function
|
||||
@@ -0,0 +1,24 @@
|
||||
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
||||
|
||||
namespace VideoQueueViewUtils
|
||||
|
||||
function Open(videoQueue as object, appController as object) as object
|
||||
videoQueueView = CreateObject("roSGNode", "VideoQueueView")
|
||||
videoQueueView.videoQueue = videoQueue
|
||||
videoQueueView.appController = appController
|
||||
videoQueueView.invidious = videoQueue.invidious
|
||||
appController@.PushScreen(videoQueueView)
|
||||
|
||||
content = videoQueue.content
|
||||
index = videoQueue.index
|
||||
|
||||
videoQueueView.content = content
|
||||
if index > -1 and index < content.GetChildCount()
|
||||
videoQueueView.jumpToItem = index
|
||||
end if
|
||||
|
||||
videoQueueView@.Show()
|
||||
return videoQueueView
|
||||
end function
|
||||
|
||||
end namespace
|
||||
Reference in new issue
Block a user