From ac037c6f08c0f7978841d6749c1da91ea72ad19e Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Fri, 11 Jun 2021 13:28:42 -0400 Subject: [PATCH] Make get_video_info work again Resolve https://github.com/ajayyy/SponsorBlock/issues/751 for now Potentially helps with https://github.com/ajayyy/SponsorBlock/issues/766 and https://github.com/ajayyy/SponsorBlock/issues/753 --- src/content.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/content.ts b/src/content.ts index 13843746..6ce82711 100644 --- a/src/content.ts +++ b/src/content.ts @@ -721,7 +721,7 @@ function startSkipScheduleCheckingForStartSponsors() { * Get the video info for the current tab from YouTube */ async function getVideoInfo(): Promise { - const result = await utils.asyncRequestToCustomServer("GET", "https://www.youtube.com/get_video_info?video_id=" + sponsorVideoID); + const result = await utils.asyncRequestToCustomServer("GET", "https://www.youtube.com/get_video_info?video_id=" + sponsorVideoID + "&html5=1"); if (result.ok) { const decodedData = decodeURIComponent(result.responseText).match(/player_response=([^&]*)/)[1]; @@ -834,16 +834,19 @@ function updatePreviewBar(): void { async function whitelistCheck() { const whitelistedChannels = Config.config.whitelistedChannels; - const channelID = document.querySelector(".ytd-channel-name a")?.getAttribute("href")?.replace(/\/.+\//, "") // YouTube + const getChannelID = () => videoInfo?.videoDetails?.channelId + ?? document.querySelector(".ytd-channel-name a")?.getAttribute("href")?.replace(/\/.+\//, "") // YouTube ?? document.querySelector(".ytp-title-channel-logo")?.getAttribute("href")?.replace(/https:\/.+\//, "") // YouTube Embed ?? document.querySelector("a > .channel-profile")?.parentElement?.getAttribute("href")?.replace(/\/.+\//, ""); // Invidious - if (channelID) { + try { + await utils.wait(() => !!getChannelID(), 6000, 20); + channelIDInfo = { status: ChannelIDStatus.Found, - id: channelID + id: getChannelID() } - } else { + } catch (e) { channelIDInfo = { status: ChannelIDStatus.Failed, id: null @@ -853,7 +856,7 @@ async function whitelistCheck() { } //see if this is a whitelisted channel - if (whitelistedChannels != undefined && whitelistedChannels.includes(channelID)) { + if (whitelistedChannels != undefined && whitelistedChannels.includes(getChannelID())) { channelWhitelisted = true; }