From 8c23bd70799f4d1701bc64efed8737df7ef7abc1 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Mon, 14 Oct 2024 10:59:59 -0400 Subject: [PATCH] Hook dev player into new backend --- CHANGELOG.md | 4 ++++ .../VideoPlayerDev/VideoContentTaskDev.bs | 23 +++++++++++++++++-- .../VideoPlayerDev/VideoPlayerDev.bs | 1 + .../VideoPlayerDev/VideoPlayerDev.xml | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aaff746f..c6eaeaa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +- Nothing worth mentioning yet. + ## [0.28.0] - 2024-10-13 ### Added diff --git a/playlet-lib/src/components/VideoPlayerDev/VideoContentTaskDev.bs b/playlet-lib/src/components/VideoPlayerDev/VideoContentTaskDev.bs index 92b21ee7..73b2d363 100644 --- a/playlet-lib/src/components/VideoPlayerDev/VideoContentTaskDev.bs +++ b/playlet-lib/src/components/VideoPlayerDev/VideoContentTaskDev.bs @@ -1,3 +1,4 @@ +import "pkg:/components/Services/Innertube/InnertubeService.bs" import "pkg:/components/Services/Invidious/InvidiousService.bs" import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs" @@ -8,6 +9,7 @@ function VideoContentTaskDev(input as object) as object backgroundPoster = input.backgroundPoster contentNode = input.content invidiousNode = input.invidious + preferencesNode = input.preferences titleLabel.text = contentNode.title secondaryTitleLabel.text = contentNode.secondaryTitle @@ -23,7 +25,12 @@ function VideoContentTaskDev(input as object) as object backgroundPoster.uri = `${instance}/vi/${videoId}/maxresdefault.jpg` - response = service.GetVideoMetadata(videoId, { cancellation: m.top.cancellation }) + backend = preferencesNode["playback.backend"] + if backend = "playlet" + response = InnertubeService.GetVideoMetadata(videoId, { cancellation: m.top.cancellation }) + else + response = service.GetVideoMetadata(videoId, { cancellation: m.top.cancellation }) + end if if m.top.cancel return invalid @@ -55,7 +62,7 @@ function VideoContentTaskDev(input as object) as object secondaryTitleLabel.text = secondaryTitle contentNode.live = metadata.liveNow - streamUrls = [`http://127.0.0.1:8888/api/dash?v=${metadata.videoId}`] + streamUrls = CreateStreamUrls(metadata) contentNode.url = streamUrls[0] contentNode.addFields({ @@ -69,3 +76,15 @@ function VideoContentTaskDev(input as object) as object success: true } end function + +function CreateStreamUrls(metadata as object) as object + streamUrls = [] + + if metadata.hlsUrl <> invalid + streamUrls.push(metadata.hlsUrl) + else + streamUrls.push(`http://127.0.0.1:8888/api/dash?v=${metadata.videoId}`) + end if + + return streamUrls +end function diff --git a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs index 087b146c..559ebadb 100644 --- a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs +++ b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs @@ -96,6 +96,7 @@ function StartVideoContentTask(videoContentNode as object) secondaryTitleLabel: m.secondaryTitleLabel content: videoContentNode invidious: m.top.invidious + preferences: m.top.preferences backgroundPoster: m.backgroundPoster }, OnVideoContentTaskResults) end function diff --git a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml index a0ae9356..a60a67a4 100644 --- a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml +++ b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml @@ -9,6 +9,7 @@ +