From b113fcfe7e169b1353b3c6cdea6e39f180db732f Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Tue, 22 Nov 2022 15:55:46 -0500 Subject: [PATCH] DASH support --- CHANGELOG.md | 1 + src/components/VideoPlayer/Video.bs | 28 +++++++++++++++++++++------- src/source/services/Invidious.bs | 13 +------------ 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a031c12e..fa432b8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Play video API - Play video by ID/URL in web app - Metadata to Video Player +- Support for DASH and Live videos ### Fixed - Bug where Settings page and home page are both visible, if settings page is selected, and user logs in. diff --git a/src/components/VideoPlayer/Video.bs b/src/components/VideoPlayer/Video.bs index 75e7d41c..470644af 100644 --- a/src/components/VideoPlayer/Video.bs +++ b/src/components/VideoPlayer/Video.bs @@ -79,13 +79,17 @@ function OnVideoPlayerStateChange() as void ' A hack to see if we could use the proxy here if m.videoPlayingSuccess <> true errorInfo = m.videoPlayer.errorInfo - if errorInfo.category = "http" - videoId = m.videoPlayer.videoId - itag = m.videoPlayer.content.itag + ' http for stream format, mediaerror for DASH + if errorInfo.category = "http" or errorInfo.category = "mediaerror" url = m.videoPlayer.content.url if url.InStr("local=true") = -1 print(`Video ${url} failed to play. Trying a proxy (local=true)`) - m.videoPlayer.content.url = Invidious.GetVideoUrl(videoId, itag, true) + if url.InStr("?") = -1 + url += "?local=true" + else + url += "&local=true" + end if + m.videoPlayer.content.url = url ' This video errored, and is about to finish, so don't close the video yet ' TODO: perhaps creating a second player is better? m.videoPlayer.ignoreNextFinishedState = true @@ -123,10 +127,20 @@ function StartVideoDetailsTask(videoId as string) videoId = task.output.videoId metadata = task.output.metadata if metadata <> invalid - stream = metadata.formatStreams[metadata.formatStreams.Count() - 1] contentNode = CreateObject("roSGNode", "ContentNode") - contentNode.addFields({ videoId: videoId, itag: stream.itag }) - contentNode.url = stream.url + contentNode.addFields({ videoId: videoId }) + + if metadata.hlsUrl <> invalid + contentNode.url = metadata.hlsUrl + else if metadata.dashUrl <> invalid + contentNode.url = metadata.dashUrl + else + stream = metadata.formatStreams[metadata.formatStreams.Count() - 1] + itag = stream.itag + ' Use an url relative to the host, so we can proxy(local=true) in case it fails + contentNode.url = Invidious.GetVideoUrl(videoId, itag) + end if + contentNode.title = metadata.title contentNode.secondaryTitle = metadata.author SetCaptions(metadata, m.videoPlayer, contentNode) diff --git a/src/source/services/Invidious.bs b/src/source/services/Invidious.bs index 6805b6c7..7a2b5744 100644 --- a/src/source/services/Invidious.bs +++ b/src/source/services/Invidious.bs @@ -75,18 +75,7 @@ namespace Invidious ' TODO: handle 500 {"error":"This video is unavailable"} if response.statuscode = 200 - videoMetadata = response.json - lastItag = videoMetadata.formatStreams[videoMetadata.formatStreams.Count() - 1].itag - - ' GetVideoUrl returns a url that redirects to the video stream - ' TODO: is this reliable? - videoUrl = Invidious.GetVideoUrl(videoId, lastItag, false) - - videoMetadata.formatStreams.push({ - itag: lastItag, - url: videoUrl - }) - return videoMetadata + return response.json end if return invalid end function