mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-11 22:17:21 +03:00
Separate refetch to a new option
This commit is contained in:
@@ -208,6 +208,12 @@
|
|||||||
"whatQueryByHashPrefix": {
|
"whatQueryByHashPrefix": {
|
||||||
"message": "Instead of requesting segments from the server using the videoID, the first 4 characters of the hash of the videoID are sent. This server will send back data for all videos with similar hashes."
|
"message": "Instead of requesting segments from the server using the videoID, the first 4 characters of the hash of the videoID are sent. This server will send back data for all videos with similar hashes."
|
||||||
},
|
},
|
||||||
|
"enableRefetchWhenNotFound": {
|
||||||
|
"message": "Refetch Segments On New Videos"
|
||||||
|
},
|
||||||
|
"whatRefetchWhenNotFound": {
|
||||||
|
"message": "If the video is new, and there are no segments found, it will keep refetching every few minutes while you watch."
|
||||||
|
},
|
||||||
"showNotice": {
|
"showNotice": {
|
||||||
"message": "Show Notice Again"
|
"message": "Show Notice Again"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -322,6 +322,23 @@
|
|||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
|
<div option-type="toggle" sync-option="refetchWhenNotFound">
|
||||||
|
<label class="switch-container" label-name="__MSG_enableRefetchWhenNotFound__">
|
||||||
|
<label class="switch">
|
||||||
|
<input type="checkbox" checked>
|
||||||
|
<span class="slider round"></span>
|
||||||
|
</label>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<div class="small-description">__MSG_whatRefetchWhenNotFound__</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
|
||||||
<div option-type="toggle" sync-option="checkForUnlistedVideos">
|
<div option-type="toggle" sync-option="checkForUnlistedVideos">
|
||||||
<label class="switch-container" label-name="__MSG_unlistedCheck__">
|
<label class="switch-container" label-name="__MSG_unlistedCheck__">
|
||||||
<label class="switch">
|
<label class="switch">
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ const utils = new Utils();
|
|||||||
|
|
||||||
interface SBConfig {
|
interface SBConfig {
|
||||||
userID: string,
|
userID: string,
|
||||||
// sponsorTimes: SBMap<string, SponsorTime[]>,
|
|
||||||
segmentTimes: SBMap<string, SponsorTime[]>,
|
segmentTimes: SBMap<string, SponsorTime[]>,
|
||||||
defaultCategory: string,
|
defaultCategory: string,
|
||||||
whitelistedChannels: string[],
|
whitelistedChannels: string[],
|
||||||
@@ -35,7 +34,8 @@ interface SBConfig {
|
|||||||
audioNotificationOnSkip,
|
audioNotificationOnSkip,
|
||||||
checkForUnlistedVideos: boolean,
|
checkForUnlistedVideos: boolean,
|
||||||
testingServer: boolean,
|
testingServer: boolean,
|
||||||
hashPrefix: boolean
|
hashPrefix: boolean,
|
||||||
|
refetchWhenNotFound: boolean,
|
||||||
|
|
||||||
// What categories should be skipped
|
// What categories should be skipped
|
||||||
categorySelections: CategorySelection[],
|
categorySelections: CategorySelection[],
|
||||||
@@ -168,6 +168,7 @@ var Config: SBObject = {
|
|||||||
checkForUnlistedVideos: false,
|
checkForUnlistedVideos: false,
|
||||||
testingServer: false,
|
testingServer: false,
|
||||||
hashPrefix: false,
|
hashPrefix: false,
|
||||||
|
refetchWhenNotFound: true,
|
||||||
|
|
||||||
categorySelections: [{
|
categorySelections: [{
|
||||||
name: "sponsor",
|
name: "sponsor",
|
||||||
|
|||||||
@@ -632,20 +632,23 @@ function sponsorsLookup(id: string) {
|
|||||||
}
|
}
|
||||||
getRequest.then(async (response: FetchResponse) => {
|
getRequest.then(async (response: FetchResponse) => {
|
||||||
if (response?.ok) {
|
if (response?.ok) {
|
||||||
let getResult = JSON.parse(response.responseText);
|
let result = JSON.parse(response.responseText);
|
||||||
if (Config.config.hashPrefix) {
|
if (Config.config.hashPrefix) {
|
||||||
getResult = getResult.filter((video) => video.videoID === id);
|
result = result.filter((video) => video.videoID === id);
|
||||||
if (getResult.length > 0) {
|
if (result.length > 0) {
|
||||||
getResult = getResult[0].segments;
|
result = result[0].segments;
|
||||||
if (getResult.length === 0) { // return if no segments found
|
if (result.length === 0) { // return if no segments found
|
||||||
|
retryFetch(id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else { // return if no video found
|
} else { // return if no video found
|
||||||
|
console.log("refetching")
|
||||||
|
retryFetch(id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let recievedSegments: SponsorTime[] = getResult;
|
let recievedSegments: SponsorTime[] = result;
|
||||||
if (!recievedSegments.length) {
|
if (!recievedSegments.length) {
|
||||||
console.error("[SponsorBlock] Server returned malformed response: " + JSON.stringify(recievedSegments));
|
console.error("[SponsorBlock] Server returned malformed response: " + JSON.stringify(recievedSegments));
|
||||||
return;
|
return;
|
||||||
@@ -689,32 +692,38 @@ function sponsorsLookup(id: string) {
|
|||||||
|
|
||||||
sponsorLookupRetries = 0;
|
sponsorLookupRetries = 0;
|
||||||
} else if (response?.status === 404) {
|
} else if (response?.status === 404) {
|
||||||
sponsorDataFound = false;
|
retryFetch(id);
|
||||||
|
|
||||||
//check if this video was uploaded recently
|
|
||||||
utils.wait(() => !!videoInfo).then(() => {
|
|
||||||
let dateUploaded = videoInfo?.microformat?.playerMicroformatRenderer?.uploadDate;
|
|
||||||
|
|
||||||
//if less than 3 days old
|
|
||||||
if (Date.now() - new Date(dateUploaded).getTime() < 259200000) {
|
|
||||||
//TODO lower when server becomes better
|
|
||||||
setTimeout(() => sponsorsLookup(id), 180000);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
sponsorLookupRetries = 0;
|
|
||||||
} else if (sponsorLookupRetries < 90 && !recheckStarted) {
|
} else if (sponsorLookupRetries < 90 && !recheckStarted) {
|
||||||
recheckStarted = true;
|
recheckStarted = true;
|
||||||
|
|
||||||
//TODO lower when server becomes better (back to 1 second)
|
//TODO lower when server becomes better (back to 1 second)
|
||||||
//some error occurred, try again in a second
|
//some error occurred, try again in a second
|
||||||
setTimeout(() => sponsorsLookup(id), 10000);
|
setTimeout(() => sponsorsLookup(id), 10000 + Math.random() * 30000);
|
||||||
|
|
||||||
sponsorLookupRetries++;
|
sponsorLookupRetries++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function retryFetch(id: string): void {
|
||||||
|
if (!Config.config.refetchWhenNotFound) return;
|
||||||
|
|
||||||
|
sponsorDataFound = false;
|
||||||
|
|
||||||
|
//check if this video was uploaded recently
|
||||||
|
utils.wait(() => !!videoInfo).then(() => {
|
||||||
|
let dateUploaded = videoInfo?.microformat?.playerMicroformatRenderer?.uploadDate;
|
||||||
|
|
||||||
|
//if less than 3 days old
|
||||||
|
if (Date.now() - new Date(dateUploaded).getTime() < 259200000) {
|
||||||
|
//TODO lower when server becomes better
|
||||||
|
setTimeout(() => sponsorsLookup(id), 120000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sponsorLookupRetries = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only should be used when it is okay to skip a sponsor when in the middle of it
|
* Only should be used when it is okay to skip a sponsor when in the middle of it
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user