* 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>
221 lines
6.5 KiB
Plaintext
221 lines
6.5 KiB
Plaintext
import "pkg:/components/ChannelView/ChannelUtils.bs"
|
|
import "pkg:/components/ContextMenu/ContextMenuUtils.bs"
|
|
import "pkg:/components/Dialog/DialogUtils.bs"
|
|
import "pkg:/components/Navigation/LongPress.bs"
|
|
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
|
import "pkg:/components/VideoFeed/FeedLoadState.bs"
|
|
import "pkg:/source/AsyncTask/AsyncTask.bs"
|
|
import "pkg:/source/AsyncTask/Tasks.bs"
|
|
import "pkg:/source/utils/ErrorUtils.bs"
|
|
import "pkg:/source/utils/FocusManagement.bs"
|
|
import "pkg:/source/utils/Logging.bs"
|
|
import "pkg:/source/utils/StringUtils.bs"
|
|
import "pkg:/source/utils/Types.bs"
|
|
|
|
function Init()
|
|
m.background = m.top.findNode("background")
|
|
m.backgroundSmall = m.top.findNode("backgroundSmall")
|
|
m.titleLabel = m.top.findNode("titleLabel")
|
|
m.subtitleLabel = m.top.findNode("subtitleLabel")
|
|
m.updatedLabel = m.top.findNode("updatedLabel")
|
|
m.descriptionLabel = m.top.findNode("descriptionLabel")
|
|
m.list = m.top.findNode("list")
|
|
end function
|
|
|
|
function OnNodeReady()
|
|
m.list.ObserveField("itemFocused", FuncName(OnItemFocused))
|
|
InitializeLongPress(["OK"])
|
|
end function
|
|
|
|
function OnFocusChange() as void
|
|
if not m.top.focus
|
|
return
|
|
end if
|
|
|
|
NodeSetFocus(m.list, true)
|
|
end function
|
|
|
|
function OnContentSet() as void
|
|
content = m.top.content
|
|
if content = invalid
|
|
return
|
|
end if
|
|
|
|
m.titleLabel.text = content.title
|
|
' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation.
|
|
m.subtitleLabel.text = `${content._author} • ${content.videoCountText} • ${content.viewCountText}`
|
|
m.updatedLabel.text = content.updatedText
|
|
m.descriptionLabel.text = content.description
|
|
|
|
' We use two Posters to cross fade from the low res thumbnail to the high res thumbnail.
|
|
' We can't use a single Poster because we're using the blendColor. There's no loadingBitmapBlendColor.
|
|
m.backgroundSmall.uri = content.thumbnail
|
|
m.background.uri = content.thumbnailBackground
|
|
|
|
itemFocused = m.list.itemFocused
|
|
if not content.isSameNode(m.list.content)
|
|
m.list.content = content
|
|
end if
|
|
if itemFocused > -1 and content.getChildCount() > itemFocused
|
|
m.list.jumpToItem = itemFocused
|
|
end if
|
|
LoadPlaylistIfNeeded()
|
|
end function
|
|
|
|
function OnkeyEvent(key as string, press as boolean) as boolean
|
|
if LongPressHandler(key, press)
|
|
return true
|
|
end if
|
|
|
|
if key = OK_LONG_PRESS_KEY and press
|
|
OnItemLongPressed(m.list.itemFocused)
|
|
return true
|
|
end if
|
|
|
|
if key = "OK" and not press
|
|
OnItemSelected(m.list.itemFocused)
|
|
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()
|
|
if m.playlistLoadTask <> invalid
|
|
m.playlistLoadTask.cancel = true
|
|
m.playlistLoadTask = invalid
|
|
end if
|
|
|
|
m.appController@.PopScreen()
|
|
end function
|
|
|
|
function OnItemFocused()
|
|
LoadPlaylistIfNeeded()
|
|
end function
|
|
|
|
function OnItemSelected(index as integer) as void
|
|
playlist = m.list.content
|
|
if playlist = invalid
|
|
return
|
|
end if
|
|
|
|
if index < 0 or index >= playlist.getChildCount()
|
|
return
|
|
end if
|
|
|
|
playlistId = playlist.playlistId
|
|
video = playlist.getChild(index)
|
|
videoId = video.videoId
|
|
if not StringUtils.IsNullOrEmpty(videoId)
|
|
LogInfo("Play playlist:", playlistId, "video:", videoId)
|
|
m.videoQueue.playPlaylist = {
|
|
playlistNode: playlist
|
|
playlistIndex: index
|
|
}
|
|
end if
|
|
end function
|
|
|
|
function OnItemLongPressed(index as integer) as void
|
|
playlist = m.list.content
|
|
if playlist = invalid
|
|
return
|
|
end if
|
|
|
|
if index < 0 or index >= playlist.getChildCount()
|
|
return
|
|
end if
|
|
|
|
playlistId = playlist.playlistId
|
|
video = playlist.getChild(index)
|
|
videoId = video.videoId
|
|
if StringUtils.IsNullOrEmpty(videoId)
|
|
LogWarn("Long press video with no id in playlist/ playlist:", playlistId, "video:", videoId)
|
|
return
|
|
end if
|
|
|
|
LogInfo("Long press: playlist:", playlistId, "video:", videoId)
|
|
|
|
' TODO:P1 handle case of opening the channel
|
|
' - Owner of a video
|
|
' - Owner of a playlist
|
|
contextMenuProviders = [m.top]
|
|
ContextMenuUtils.Open(contextMenuProviders, m.appController, video)
|
|
end function
|
|
|
|
function GetContextMenuOptionsForItem(video as object) as object
|
|
playlist = m.list.content
|
|
if playlist = invalid
|
|
return []
|
|
end if
|
|
|
|
index = m.list.itemFocused
|
|
if index < 0 or index >= playlist.getChildCount()
|
|
return []
|
|
end if
|
|
|
|
selectedVideo = playlist.getChild(m.list.itemFocused)
|
|
if selectedVideo = invalid or not selectedVideo.isSameNode(video)
|
|
return []
|
|
end if
|
|
|
|
options = [
|
|
ContextMenuUtils.CreateOption("Play", m.videoQueue, "FuncPlayPlaylist", [playlist, index]),
|
|
ContextMenuUtils.CreateOption("Queue", m.videoQueue, "FuncAddToQueuePlaylist", [playlist])
|
|
ContextMenuUtils.CreateOption("Play video", m.videoQueue, "FuncPlayVideo", [video]),
|
|
ContextMenuUtils.CreateOption("Queue video", m.videoQueue, "FuncAddToQueueVideo", [video]),
|
|
]
|
|
|
|
if not StringUtils.IsNullOrEmpty(playlist.authorId)
|
|
options.push(ContextMenuUtils.CreateOption("Open channel", m.top, "OpenPlaylistChannel", [playlist]))
|
|
end if
|
|
|
|
options.append(m.bookmarks@.GetMenuForPlaylist(playlist))
|
|
options.append(m.bookmarks@.GetMenuForVideo(video))
|
|
|
|
return options
|
|
end function
|
|
|
|
function OpenPlaylistChannel(playlist as object) as void
|
|
authorId = playlist.authorId
|
|
if StringUtils.IsNullOrEmpty(authorId)
|
|
LogWarn("Invalid authorId:", authorId)
|
|
return
|
|
end if
|
|
channel = InvidiousContent.ToChannelContentNode(invalid, { authorId: authorId }, invalid)
|
|
ChannelUtils.Open(channel)
|
|
end function
|
|
|
|
'TODO:P1 a playlist could have been opened from the bookmarks, which can be as old as 3 days
|
|
' We should make a request in this case, and let the cache handle freshness.
|
|
function LoadPlaylistIfNeeded() as void
|
|
content = m.top.content
|
|
if content = invalid
|
|
return
|
|
end if
|
|
|
|
if not content.loadState = FeedLoadState.LoadedPage and not content.loadState = FeedLoadState.None
|
|
return
|
|
end if
|
|
|
|
videoCount = content.videoCount
|
|
currentVideosCount = content.getChildCount()
|
|
if videoCount = currentVideosCount
|
|
return
|
|
end if
|
|
|
|
itemFocused = m.list.itemFocused
|
|
if itemFocused < currentVideosCount - 5
|
|
return
|
|
end if
|
|
|
|
m.top.content@.LoadPlaylistPage(m.top.invidious)
|
|
end function
|