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:
Brahim Hadricheandgithub-action linter authored and GitHub committed 2024-02-19 16:30:48 -05:00
1 parent ec9178d687
commit 7d1ba07286
85 files changed
+3666 -938

No files matched your search

@@ -1,8 +1,9 @@
import "pkg:/components/Dialog/DialogUtils.bs"
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
import "pkg:/components/VideoPlayer/Lounge.bs"
import "pkg:/components/VideoPlayer/SponsorBlock.bs"
import "pkg:/components/VideoPlayer/VideoPlayerStyle.bs"
import "pkg:/components/VideoPlayer/VideoUtils.bs"
import "pkg:/components/VideoQueue/VideoQueueUtils.bs"
import "pkg:/source/AsyncTask/AsyncTask.bs"
import "pkg:/source/AsyncTask/Tasks.bs"
import "pkg:/source/utils/ErrorUtils.bs"
@@ -70,11 +71,13 @@ function PlayWithContent(contentNode as object)
if not StringUtils.IsNullOrEmpty(contentNode.title)
videoContentNode.title = contentNode.title
end if
if not StringUtils.IsNullOrEmpty(contentNode.author)
videoContentNode.secondaryTitle = contentNode.author
' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation.
if not StringUtils.IsNullOrEmpty(contentNode._author)
videoContentNode.secondaryTitle = contentNode._author
end if
StartVideoContentTask(videoContentNode)
Lounge.SendNowPlayingLoading(contentNode.videoId)
end function
function StartVideoContentTask(videoContentNode as object)
@@ -113,7 +116,8 @@ function OnVideoContentTaskResults(output as object) as void
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()
m.videoQueue.closePlayer = true
Lounge.SendOnStateChange()
return
end if
@@ -161,6 +165,8 @@ function Close(_unused as dynamic)
end function
function OnVideoPlayerStateChange() as void
Lounge.SendOnStateChange()
state = m.top.state
content = m.top.content
' If we successfully played the video, then any error that comes later is not due to a 403 (FORBIDDEN).
@@ -227,67 +233,14 @@ function OnVideoPlayerStateChange() as void
LogError(title, messageLines)
DialogUtils.ShowDialog(messageLines, title, true)
' TODO:P1 play next video in the queue after showing the error dialog
VideoUtils.CloseVideo()
m.videoQueue.closePlayer = true
end if
end function
function OnVideoFinished() as void
content = m.top.content
if content = invalid
m.playQueue@.watchedVideosClear()
VideoUtils.CloseVideo()
return
if not VideoQueueUtils.PlayNext(m.videoQueue, m.invidious, m.preferences)
m.videoQueue.closePlayer = true
end if
metadata = content.metadata
if metadata = invalid
m.playQueue@.watchedVideosClear()
VideoUtils.CloseVideo()
return
end if
if not PlayNext(metadata.recommendedVideos)
m.playQueue@.watchedVideosClear()
VideoUtils.CloseVideo()
end if
end function
function PlayNext(recommendedVideos as object) as boolean
if m.playQueue@.PlayNextItem()
return true
end if
return PlayNextRecommendedVideo(recommendedVideos)
end function
' TODO:P2 move this to the play queue
function PlayNextRecommendedVideo(recommendedVideos as object) as boolean
if m.preferences["playback.autoplay"] <> true
return false
end if
if recommendedVideos = invalid or recommendedVideos.Count() = 0
return false
end if
for each metadata in recommendedVideos
if metadata = invalid
continue for
end if
videoId = metadata.videoId
if videoId = invalid
continue for
end if
if not m.playQueue@.watchedVideosContain(videoId)
LogInfo(`Playing next recommended video (${videoId})`)
instance = m.invidious@.GetCurrentInstance()
node = InvidiousContent.ToVideoContentNode(invalid, metadata, instance)
m.playQueue@.Play(node, -1)
return true
end if
end for
return false
end function
function OnkeyEvent(key as string, press as boolean) as boolean
@@ -298,14 +251,13 @@ function OnkeyEvent(key as string, press as boolean) as boolean
' 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()
if VideoQueueUtils.ToggleVideoPictureInPicture(m.videoQueue)
return true
end if
end if
if key = "back"
m.playQueue@.watchedVideosClear()
VideoUtils.CloseVideo()
m.videoQueue.closePlayer = true
return true
end if
return false