diff --git a/src/components/UILogic/VideoPlayerLogic.brs b/src/components/UILogic/VideoPlayerLogic.brs index 0df7b669..436e8e6f 100644 --- a/src/components/UILogic/VideoPlayerLogic.brs +++ b/src/components/UILogic/VideoPlayerLogic.brs @@ -6,7 +6,7 @@ sub ShowVideoScreen(videoMetadata as object, videoSponsorBlock as object) SetCaptions(videoMetadata, m.videoPlayer, rowNode) m.videoPlayer.content = rowNode - ShowScreen(m.videoPlayer) + ShowScreen(m.videoPlayer) m.videoPlayer.control = "play" m.videoPlayer.ObserveField("state", "OnVideoPlayerStateChange") m.videoPlayer.ObserveField("visible", "OnVideoVisibleChange") @@ -46,9 +46,31 @@ sub SetCaptions(videoMetadata as object, videoPlayer as object, contentNode as o } end sub -sub OnVideoPlayerStateChange() +sub OnVideoPlayerStateChange() state = m.videoPlayer.state + ' A hack to see if we could use the proxy here + if state = "error" + errorInfo = m.videoPlayer.errorInfo + if errorInfo.category = "http" + 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 = url + "&local=true" + ' This video errored, and is about to finish, so don't close the video yet + ' TODO: perhaps creating a second player is better? + m.ignoreNextFinishedState = true + m.videoPlayer.control = "play" + return + end if + end if + end if + + if state = "finished" and m.ignoreNextFinishedState + m.ignoreNextFinishedState = false + return + end if + if state = "error" or state = "finished" CloseScreen(m.videoPlayer) end if @@ -64,7 +86,7 @@ sub OnVideoVisibleChange() end if end sub -sub OnVideoPositionChange() +sub OnVideoPositionChange() SkipSponsorBlockSections() end sub diff --git a/src/components/tasks/VideoDetailsLoaderTask.brs b/src/components/tasks/VideoDetailsLoaderTask.brs index d45bc2a0..f3e9b84f 100644 --- a/src/components/tasks/VideoDetailsLoaderTask.brs +++ b/src/components/tasks/VideoDetailsLoaderTask.brs @@ -26,10 +26,10 @@ function GetVideoMetadata() videoMetadata = RokuYoutube.Services.Invidious.GetVideoMetadata(videoId) lastItag = videoMetadata.formatStreams[videoMetadata.formatStreams.Count() - 1].itag - ' GetVideoUrl returns a url with the local=true, which is proxied through the instance + ' GetVideoUrl returns a url that redirects to the video stream ' TODO: is this reliable? - ' TODO: try direct videos first, before trying proxy, to avoid additional slowdowns - videoUrl = RokuYoutube.Services.Invidious.GetVideoUrl(videoId, lastItag) + videoUrl = RokuYoutube.Services.Invidious.GetVideoUrl(videoId, lastItag, false) + videoMetadata.formatStreams.push({ itag: lastItag, url: videoUrl diff --git a/src/source/services/Invidious.bs b/src/source/services/Invidious.bs index 0335ade1..8e93285d 100644 --- a/src/source/services/Invidious.bs +++ b/src/source/services/Invidious.bs @@ -57,8 +57,12 @@ namespace RokuYoutube.Services.Invidious end if end function - function GetVideoUrl(videoId as string, itag as string) - return `${API_URL}/latest_version?id=${videoId}&itag=${itag}&local=true` + function GetVideoUrl(videoId as string, itag as string, local as bool) + url = `${API_URL}/latest_version?id=${videoId}&itag=${itag}` + if local + url = url + "&local=true" + end if + return url end function function GetVideoMetadata(videoId as string)