mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-09 04:57:04 +03:00
Don't fail when the YouTube API errors
This commit is contained in:
@@ -411,36 +411,40 @@ module.exports = async function postSkipSegments(req, res) {
|
|||||||
YouTubeAPI.listVideos(videoID, (err, data) => resolve({err, data}));
|
YouTubeAPI.listVideos(videoID, (err, data) => resolve({err, data}));
|
||||||
});
|
});
|
||||||
|
|
||||||
//get all segments for this video and user
|
if (err) {
|
||||||
let allSubmittedByUser = db.prepare('all', "SELECT startTime, endTime FROM sponsorTimes WHERE userID = ? and videoID = ? and votes > -1", [userID, videoID]);
|
logger.error("Error while submitting when connecting to YouTube API: " + err);
|
||||||
let allSegmentTimes = [];
|
} else {
|
||||||
if (allSubmittedByUser !== undefined) {
|
//get all segments for this video and user
|
||||||
//add segments the user has previously submitted
|
let allSubmittedByUser = db.prepare('all', "SELECT startTime, endTime FROM sponsorTimes WHERE userID = ? and videoID = ? and votes > -1", [userID, videoID]);
|
||||||
for (const segmentInfo of allSubmittedByUser) {
|
let allSegmentTimes = [];
|
||||||
allSegmentTimes.push([parseFloat(segmentInfo.startTime), parseFloat(segmentInfo.endTime)])
|
if (allSubmittedByUser !== undefined) {
|
||||||
|
//add segments the user has previously submitted
|
||||||
|
for (const segmentInfo of allSubmittedByUser) {
|
||||||
|
allSegmentTimes.push([parseFloat(segmentInfo.startTime), parseFloat(segmentInfo.endTime)])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//add segments they are trying to add in this submission
|
//add segments they are trying to add in this submission
|
||||||
for (let i = 0; i < segments.length; i++) {
|
for (let i = 0; i < segments.length; i++) {
|
||||||
let startTime = parseFloat(segments[i].segment[0]);
|
let startTime = parseFloat(segments[i].segment[0]);
|
||||||
let endTime = parseFloat(segments[i].segment[1]);
|
let endTime = parseFloat(segments[i].segment[1]);
|
||||||
allSegmentTimes.push([startTime, endTime]);
|
allSegmentTimes.push([startTime, endTime]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//merge all the times into non-overlapping arrays
|
//merge all the times into non-overlapping arrays
|
||||||
const allSegmentsSorted = mergeTimeSegments(allSegmentTimes.sort(function(a, b) { return a[0]-b[0] || a[1]-b[1] }));
|
const allSegmentsSorted = mergeTimeSegments(allSegmentTimes.sort(function(a, b) { return a[0]-b[0] || a[1]-b[1] }));
|
||||||
|
|
||||||
let videoDuration = data.items[0].contentDetails.duration;
|
let videoDuration = data.items[0].contentDetails.duration;
|
||||||
videoDuration = isoDurations.toSeconds(isoDurations.parse(videoDuration));
|
videoDuration = isoDurations.toSeconds(isoDurations.parse(videoDuration));
|
||||||
if (videoDuration != 0) {
|
if (videoDuration != 0) {
|
||||||
let allSegmentDuration = 0;
|
let allSegmentDuration = 0;
|
||||||
//sum all segment times together
|
//sum all segment times together
|
||||||
allSegmentsSorted.forEach(segmentInfo => allSegmentDuration += segmentInfo[1] - segmentInfo[0]);
|
allSegmentsSorted.forEach(segmentInfo => allSegmentDuration += segmentInfo[1] - segmentInfo[0]);
|
||||||
if (allSegmentDuration > (videoDuration/100)*80) {
|
if (allSegmentDuration > (videoDuration/100)*80) {
|
||||||
// Reject submission if all segments combine are over 80% of the video
|
// Reject submission if all segments combine are over 80% of the video
|
||||||
res.status(400).send("Total length of your submitted segments are over 80% of the video.");
|
res.status(400).send("Total length of your submitted segments are over 80% of the video.");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user