From b7e6a1ea8334aeba19141a379a2646befdf3e4c6 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Mon, 1 May 2023 17:19:57 -0400 Subject: [PATCH] Refactor format stream url --- .../src/components/VideoPlayer/VideoPlayer.bs | 7 ++----- .../components/WebServer/Middleware/DashRouter.bs | 6 +----- playlet-lib/src/source/services/Invidious.bs | 13 +++++++++++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs index 94878ebc..042b5317 100644 --- a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs +++ b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs @@ -136,11 +136,8 @@ function OnVideoDetailsTaskResults(output as object) as void end if if metadata.formatStreams.Count() > 0 - stream = metadata.formatStreams[metadata.formatStreams.Count() - 1] - itag = stream.itag - - playletStreamUrls.push(Invidious.GetVideoUrl(videoId, itag, false)) - playletStreamUrls.push(Invidious.GetVideoUrl(videoId, itag, true)) + playletStreamUrls.push(Invidious.GetVideoStreamUrl(videoId, false)) + playletStreamUrls.push(Invidious.GetVideoStreamUrl(videoId, true)) end if end if diff --git a/playlet-lib/src/components/WebServer/Middleware/DashRouter.bs b/playlet-lib/src/components/WebServer/Middleware/DashRouter.bs index 6a23100b..5d4b09a0 100644 --- a/playlet-lib/src/components/WebServer/Middleware/DashRouter.bs +++ b/playlet-lib/src/components/WebServer/Middleware/DashRouter.bs @@ -19,17 +19,13 @@ namespace Http instance = InvidiousSettings.GetSelectedInstance() metadata = router.GetVideoMetadata(context, v) - dashUrl = `${instance}/api/manifest/dash/id/${v}` + dashUrl = Invidious.GetVideoDashUrl(v, local <> invalid) if metadata = invalid and local = invalid response.Redirect(dashUrl) return true end if - if local <> invalid - dashUrl = `${dashUrl}?local=${local}` - end if - resp = Requests().get(dashUrl, { parseJson: false }) text = resp.text ?? "" if resp.statuscode = 200 and local = "true" diff --git a/playlet-lib/src/source/services/Invidious.bs b/playlet-lib/src/source/services/Invidious.bs index 07a81390..b6024d5b 100644 --- a/playlet-lib/src/source/services/Invidious.bs +++ b/playlet-lib/src/source/services/Invidious.bs @@ -42,15 +42,24 @@ namespace Invidious return invalid end function - function GetVideoUrl(videoId as string, itag as string, local as boolean) as string + function GetVideoStreamUrl(videoId as string, local as boolean) as string instance = InvidiousSettings.GetSelectedInstance() - url = `${instance}/latest_version?id=${videoId}&itag=${itag}` + url = `${instance}/latest_version?id=${videoId}` if local url = url + "&local=true" end if return url end function + function GetVideoDashUrl(videoId as string, local as boolean) as string + instance = InvidiousSettings.GetSelectedInstance() + url = `${instance}/api/manifest/dash/id/${videoId}` + if local + url = url + "?local=true" + end if + return url + end function + function GetVideoMetadata(videoId as string) as object instance = InvidiousSettings.GetSelectedInstance() url = `${instance}${Invidious.VIDEOS_ENDPOINT}/${videoId}`