From 29651fee1f2b0e58f6f426f2a2ecdbc184197ec4 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Tue, 3 Jan 2023 18:19:29 -0500 Subject: [PATCH] Pass metadata to player --- CHANGELOG.md | 2 ++ .../HomeGridScreen/HomeGridScreen.bs | 5 ++++- src/components/MainScene.bs | 6 +++--- src/components/SearchScreen/SearchScreen.bs | 5 ++++- src/components/VideoPlayer/Video.bs | 10 ++++++++- src/components/VideoPlayer/VideoPlayer.bs | 21 +++++++++++++++++-- src/components/VideoPlayer/VideoPlayer.xml | 1 + 7 files changed, 42 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 732aba86..11addd1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - WebSocket server for realtime events - SponsorBlock tracking - Auto-generated tasks and the @asynctask annotation +- Show known video metadata while loading video details +- Caching for video details ### Changed - The License has changed from MIT to AGPL diff --git a/src/components/HomeGridScreen/HomeGridScreen.bs b/src/components/HomeGridScreen/HomeGridScreen.bs index 945e3f0a..005df181 100644 --- a/src/components/HomeGridScreen/HomeGridScreen.bs +++ b/src/components/HomeGridScreen/HomeGridScreen.bs @@ -110,7 +110,10 @@ function OnHomeGridScreenVideoSelected(event as object) as void videoId = itemContent.videoId - PlayVideo(videoId, m.top) + PlayVideo(videoId, { + metadata: itemContent, + sender: m.top + }) end function function OnkeyEvent(key as string, press as boolean) as boolean diff --git a/src/components/MainScene.bs b/src/components/MainScene.bs index 668b5d9b..b4dbac08 100644 --- a/src/components/MainScene.bs +++ b/src/components/MainScene.bs @@ -93,7 +93,7 @@ end function function OnWebServerCommand() if m.serverTask.command.StartsWith("play:") sender = m.videoContainer.sender ?? m.currentFocued - PlayVideo(m.serverTask.command.Mid(5), sender) + PlayVideo(m.serverTask.command.Mid(5), {sender: sender}) end if end function @@ -112,7 +112,7 @@ function LaunchArgumentsReceived() ? "LaunchArgumentsReceived" m.top.launchArgs if m.top.launchArgs <> invalid and m.top.launchArgs.contentId <> invalid sender = m.videoContainer.sender ?? m.currentFocued - PlayVideo(m.top.launchArgs.contentId, sender) + PlayVideo(m.top.launchArgs.contentId, {sender: sender}) end if end function @@ -120,6 +120,6 @@ function InputArgumentsReceived() ? "InputArgumentsReceived" m.top.inputArgs if m.top.inputArgs <> invalid and m.top.inputArgs.contentId <> invalid sender = m.videoContainer.sender ?? m.currentFocued - PlayVideo(m.top.inputArgs.contentId, sender) + PlayVideo(m.top.inputArgs.contentId, {sender: sender}) end if end function diff --git a/src/components/SearchScreen/SearchScreen.bs b/src/components/SearchScreen/SearchScreen.bs index 368ae2ce..fc1624d3 100644 --- a/src/components/SearchScreen/SearchScreen.bs +++ b/src/components/SearchScreen/SearchScreen.bs @@ -172,7 +172,10 @@ function OnSearchVideoSelected(event as object) itemContent = rowContent.GetChild(selectedRowItem) videoId = itemContent.videoId - PlayVideo(videoId, m.top) + PlayVideo(videoId, { + metadata: itemContent, + sender: m.top + }) end function function OnkeyEvent(key as string, press as boolean) as boolean diff --git a/src/components/VideoPlayer/Video.bs b/src/components/VideoPlayer/Video.bs index 2a7e80bf..b5a08939 100644 --- a/src/components/VideoPlayer/Video.bs +++ b/src/components/VideoPlayer/Video.bs @@ -1,7 +1,14 @@ import "pkg:/source/services/Invidious.bs" import "pkg:/components/Dialog/DialogUtils.bs" -function PlayVideo(videoId as string, sender as object) +function PlayVideo(videoId as string, args = invalid as object) + sender = args?.sender + metadata = args?.metadata + + if metadata <> invalid and GetInterface(metadata, "ifSGNodeField") <> invalid + metadata = args.metadata.getFields() + end if + width = 1280 height = 720 translation = [0.0, 0.0] @@ -17,6 +24,7 @@ function PlayVideo(videoId as string, sender as object) end if videoContainer.videoPlayer = videoContainer.createChild("VideoPlayer") videoContainer.videoPlayer.id = "VideoPlayer" + videoContainer.videoPlayer.metadata = metadata videoContainer.videoPlayer.videoId = videoId videoContainer.videoPlayer.width = width videoContainer.videoPlayer.height = height diff --git a/src/components/VideoPlayer/VideoPlayer.bs b/src/components/VideoPlayer/VideoPlayer.bs index e5cff2b1..955728e2 100644 --- a/src/components/VideoPlayer/VideoPlayer.bs +++ b/src/components/VideoPlayer/VideoPlayer.bs @@ -55,11 +55,27 @@ function OnControlChange() 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 @@ -253,9 +269,10 @@ function OnVideoPlayerStateChange() as void if state = "finished" metadata = m.top.content?.metadata - videoId = metadata?.recommendedVideos?.GetEntry(0)?.videoId + metadata = metadata?.recommendedVideos?.GetEntry(0) + videoId = metadata?.videoId if videoId <> invalid - PlayVideo(videoId, invalid) + PlayVideo(videoId, { metadata: metadata }) else CloseVideo() end if diff --git a/src/components/VideoPlayer/VideoPlayer.xml b/src/components/VideoPlayer/VideoPlayer.xml index 5c70ad2e..ab11a57f 100644 --- a/src/components/VideoPlayer/VideoPlayer.xml +++ b/src/components/VideoPlayer/VideoPlayer.xml @@ -6,6 +6,7 @@ +