From 45c618ccda60fa19b4bb652113a999f0e02ff7d1 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Sat, 5 Nov 2022 15:49:48 -0400 Subject: [PATCH] Potentially a more reliable way to get streams --- src/components/tasks/VideoDetailsLoaderTask.brs | 13 ++++++++++++- src/source/services/Invidious.bs | 6 +++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/tasks/VideoDetailsLoaderTask.brs b/src/components/tasks/VideoDetailsLoaderTask.brs index 7bb89883..8975f881 100644 --- a/src/components/tasks/VideoDetailsLoaderTask.brs +++ b/src/components/tasks/VideoDetailsLoaderTask.brs @@ -23,7 +23,18 @@ end sub function GetVideoMetadata() videoId = m.top.getField("videoid") - return RokuYoutube.Services.Invidious.GetVideoMetadataForVideo(videoId) + videoMetadata = RokuYoutube.Services.Invidious.GetVideoMetadata(videoId) + lastItag = videoMetadata.formatStreams[videoMetadata.formatStreams.Count() - 1].itag + + ' GetVideoUrl returns a url with the local=true, leading to less change of rate limit (403) - maybe? + ' TODO: is this reliable? + videoUrl = RokuYoutube.Services.Invidious.GetVideoUrl(videoId, lastItag) + videoMetadata.formatStreams.push({ + itag: lastItag, + url: videoUrl + }) + + return videoMetadata end function function GetVideoSponsorBlock() diff --git a/src/source/services/Invidious.bs b/src/source/services/Invidious.bs index 32afda28..4908aada 100644 --- a/src/source/services/Invidious.bs +++ b/src/source/services/Invidious.bs @@ -39,7 +39,11 @@ namespace RokuYoutube.Services.Invidious end if end function - function GetVideoMetadataForVideo(videoId as string) + function GetVideoUrl(videoId as string, itag as string) + return `${API_URL}/latest_version?id=${videoId}&itag=${itag}&local=true` + end function + + function GetVideoMetadata(videoId as string) url = `${API_URL}${VIDEOS_ENDPOINT}/${videoId}` response = Requests().get(url)