Make channel fetching error silent and don't wait for video info

This commit is contained in:
Ajay Ramachandran
2021-05-21 17:33:48 -04:00
parent e70a8c724b
commit a5189014ad
4 changed files with 33 additions and 47 deletions

View File

@@ -583,7 +583,8 @@
"message": "hidden: too short" "message": "hidden: too short"
}, },
"channelDataNotFound": { "channelDataNotFound": {
"message": "Channel ID not loaded yet." "description": "This error appears in an alert when they try to whitelist a channel and the extension is unable to determine what channel they are looking at.",
"message": "Channel ID is not loaded yet. If you are using an embedded video, try using the YouTube homepage instead. This could also be caused by changes in the YouTube layout, if you think so, make a comment here:"
}, },
"videoInfoFetchFailed": { "videoInfoFetchFailed": {
"message": "It seems that something is blocking SponsorBlock's ability to get video data. Please see https://github.com/ajayyy/SponsorBlock/issues/741 for more info." "message": "It seems that something is blocking SponsorBlock's ability to get video data. Please see https://github.com/ajayyy/SponsorBlock/issues/741 for more info."
@@ -603,9 +604,6 @@
"adblockerIssueWhitelist": { "adblockerIssueWhitelist": {
"message": "If you are unable to resolve this, then disable the setting 'Force Channel Check Before Skipping', as SponsorBlock is unable to retrieve the channel information for this video" "message": "If you are unable to resolve this, then disable the setting 'Force Channel Check Before Skipping', as SponsorBlock is unable to retrieve the channel information for this video"
}, },
"itCouldBeAdblockerIssue": {
"message": "If this keeps occuring, it could be caused by your ad blocker. Please check https://github.com/ajayyy/SponsorBlock/wiki/Fix-Ad-Blocker-Blocking-SponsorBlock's-Requests"
},
"forceChannelCheck": { "forceChannelCheck": {
"message": "Force Channel Check Before Skipping" "message": "Force Channel Check Before Skipping"
}, },

View File

@@ -1,6 +1,6 @@
import Config from "./config"; import Config from "./config";
import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse, VideoInfo, StorageChangesObject } from "./types"; import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse, VideoInfo, StorageChangesObject, ChannelIDInfo, ChannelIDStatus } from "./types";
import { ContentContainer } from "./types"; import { ContentContainer } from "./types";
import Utils from "./utils"; import Utils from "./utils";
@@ -29,7 +29,7 @@ const skipNotices: SkipNotice[] = [];
// JSON video info // JSON video info
let videoInfo: VideoInfo = null; let videoInfo: VideoInfo = null;
//the channel this video is about //the channel this video is about
let channelID: string; let channelIDInfo: ChannelIDInfo;
// Skips are scheduled to ensure precision. // Skips are scheduled to ensure precision.
// Skips are rescheduled every seeking event. // Skips are rescheduled every seeking event.
@@ -160,7 +160,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
break; break;
case "getChannelID": case "getChannelID":
sendResponse({ sendResponse({
channelID: channelID channelID: channelIDInfo.id
}); });
break; break;
@@ -212,7 +212,10 @@ function resetValues() {
videoInfo = null; videoInfo = null;
channelWhitelisted = false; channelWhitelisted = false;
channelID = null; channelIDInfo = {
status: ChannelIDStatus.Fetching,
id: null
};
//empty the preview bar //empty the preview bar
if (previewBar !== null) { if (previewBar !== null) {
@@ -392,7 +395,7 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?:
if (video.paused) return; if (video.paused) return;
if (Config.config.disableSkipping || channelWhitelisted || (channelID === null && Config.config.forceChannelCheck)){ if (Config.config.disableSkipping || channelWhitelisted || (channelIDInfo.status === ChannelIDStatus.Fetching && Config.config.forceChannelCheck)){
return; return;
} }
@@ -703,21 +706,6 @@ async function getVideoInfo(): Promise<void> {
} }
} }
async function videoInfoFetchFailed(errorMessage: string): Promise<void> {
console.log("failed\t" + errorMessage)
if (utils.isFirefox() && !Config.config.ytInfoPermissionGranted) {
// Attempt to ask permission for youtube.com domain
alert(chrome.i18n.getMessage("youtubePermissionRequest"));
chrome.runtime.sendMessage({
message: "openPage",
url: "permissions/index.html#youtube.com"
});
} else {
alert(chrome.i18n.getMessage("videoInfoFetchFailed") + "\n\n" + chrome.i18n.getMessage(errorMessage));
}
}
function getYouTubeVideoID(url: string) { function getYouTubeVideoID(url: string) {
// For YouTube TV support // For YouTube TV support
if(url.startsWith("https://www.youtube.com/tv#/")) url = url.replace("#", ""); if(url.startsWith("https://www.youtube.com/tv#/")) url = url.replace("#", "");
@@ -817,41 +805,31 @@ function updatePreviewBar(): void {
async function whitelistCheck() { async function whitelistCheck() {
const whitelistedChannels = Config.config.whitelistedChannels; const whitelistedChannels = Config.config.whitelistedChannels;
const getChannelID = () => videoInfo?.videoDetails?.channelId const channelID = document.querySelector(".ytd-channel-name a")?.getAttribute("href")?.replace(/\/.+\//, "") // YouTube
?? document.querySelector(".ytd-channel-name a")?.getAttribute("href")?.replace(/\/.+\//, "") // YouTube
?? document.querySelector(".ytp-title-channel-logo")?.getAttribute("href")?.replace(/https:\/.+\//, "") // YouTube Embed ?? document.querySelector(".ytp-title-channel-logo")?.getAttribute("href")?.replace(/https:\/.+\//, "") // YouTube Embed
?? document.querySelector("a > .channel-profile")?.parentElement?.getAttribute("href")?.replace(/\/.+\//, ""); // Invidious ?? document.querySelector("a > .channel-profile")?.parentElement?.getAttribute("href")?.replace(/\/.+\//, ""); // Invidious
try { if (channelID) {
await utils.wait(() => !!getChannelID(), 6000, 20); channelIDInfo = {
} catch { status: ChannelIDStatus.Found,
if (Config.config.forceChannelCheck) { id: channelID
// treat as not whitelisted
channelID = "";
// Don't warn for Invidious embeds
if (!(onInvidious && document.URL.includes("/embed/"))) {
videoInfoFetchFailed("adblockerIssueWhitelist");
} }
} else {
channelIDInfo = {
status: ChannelIDStatus.Failed,
id: null
} }
return; return;
} }
channelID = getChannelID();
if (!channelID) {
channelID = null;
return;
}
//see if this is a whitelisted channel //see if this is a whitelisted channel
if (whitelistedChannels != undefined && whitelistedChannels.includes(channelID)) { if (whitelistedChannels != undefined && whitelistedChannels.includes(channelID)) {
channelWhitelisted = true; channelWhitelisted = true;
} }
// check if the start of segments were missed // check if the start of segments were missed
if (Config.config.forceChannelCheck && sponsorTimes && sponsorTimes.length > 0) startSkipScheduleCheckingForStartSponsors(); if (Config.config.forceChannelCheck && sponsorTimes?.length > 0) startSkipScheduleCheckingForStartSponsors();
} }
/** /**

View File

@@ -581,8 +581,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
{message: 'getChannelID'}, {message: 'getChannelID'},
function(response) { function(response) {
if (!response.channelID) { if (!response.channelID) {
alert(chrome.i18n.getMessage("channelDataNotFound") + "\n\n" + alert(chrome.i18n.getMessage("channelDataNotFound") + " https://github.com/ajayyy/SponsorBlock/issues/753");
chrome.i18n.getMessage("itCouldBeAdblockerIssue"));
return; return;
} }

View File

@@ -161,3 +161,14 @@ export type VideoID = string;
export type StorageChangesObject = { [key: string]: chrome.storage.StorageChange }; export type StorageChangesObject = { [key: string]: chrome.storage.StorageChange };
export type UnEncodedSegmentTimes = [string, SponsorTime[]][]; export type UnEncodedSegmentTimes = [string, SponsorTime[]][];
export enum ChannelIDStatus {
Fetching,
Found,
Failed
}
export interface ChannelIDInfo {
id: string,
status: ChannelIDStatus
}