mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-30 11:28:19 +03:00
Fix auto moderate merge issues
This commit is contained in:
@@ -1,17 +1,19 @@
|
|||||||
var config = require('../config.js');
|
const config = require('../config.js');
|
||||||
|
|
||||||
var databases = require('../databases/databases.js');
|
const databases = require('../databases/databases.js');
|
||||||
var db = databases.db;
|
const db = databases.db;
|
||||||
var privateDB = databases.privateDB;
|
const privateDB = databases.privateDB;
|
||||||
var YouTubeAPI = require('../utils/youtubeAPI.js');
|
const YouTubeAPI = require('../utils/youtubeAPI.js');
|
||||||
var logger = require('../utils/logger.js');
|
const logger = require('../utils/logger.js');
|
||||||
var request = require('request');
|
const request = require('request');
|
||||||
var isoDurations = require('iso8601-duration');
|
const isoDurations = require('iso8601-duration');
|
||||||
|
const fetch = require('node-fetch');
|
||||||
|
|
||||||
|
const getHash = require('../utils/getHash.js');
|
||||||
|
const getIP = require('../utils/getIP.js');
|
||||||
|
const getFormattedTime = require('../utils/getFormattedTime.js');
|
||||||
|
const isUserTrustworthy = require('../utils/isUserTrustworthy.js')
|
||||||
|
|
||||||
var getHash = require('../utils/getHash.js');
|
|
||||||
var getIP = require('../utils/getIP.js');
|
|
||||||
var getFormattedTime = require('../utils/getFormattedTime.js');
|
|
||||||
var isUserTrustworthy = require('../utils/isUserTrustworthy.js')
|
|
||||||
|
|
||||||
function sendDiscordNotification(userID, videoID, UUID, segmentInfo) {
|
function sendDiscordNotification(userID, videoID, UUID, segmentInfo) {
|
||||||
//check if they are a first time user
|
//check if they are a first time user
|
||||||
@@ -73,7 +75,7 @@ function sendDiscordNotification(userID, videoID, UUID, segmentInfo) {
|
|||||||
// Looks like this was broken for no defined youtube key - fixed but IMO we shouldn't return
|
// Looks like this was broken for no defined youtube key - fixed but IMO we shouldn't return
|
||||||
// false for a pass - it was confusing and lead to this bug - any use of this function in
|
// false for a pass - it was confusing and lead to this bug - any use of this function in
|
||||||
// the future could have the same problem.
|
// the future could have the same problem.
|
||||||
async function autoModerateSubmission(submission, callback) {
|
async function autoModerateSubmission(submission) {
|
||||||
// Get the video information from the youtube API
|
// Get the video information from the youtube API
|
||||||
if (config.youtubeAPIKey !== null) {
|
if (config.youtubeAPIKey !== null) {
|
||||||
let {err, data} = await new Promise((resolve, reject) => {
|
let {err, data} = await new Promise((resolve, reject) => {
|
||||||
@@ -95,13 +97,9 @@ async function autoModerateSubmission(submission, callback) {
|
|||||||
if (duration == 0) {
|
if (duration == 0) {
|
||||||
// Allow submission if the duration is 0 (bug in youtube api)
|
// Allow submission if the duration is 0 (bug in youtube api)
|
||||||
return false;
|
return false;
|
||||||
}
|
} else if ((submission.endTime - submission.startTime) > (duration / 100) * 80) {
|
||||||
|
// Reject submission if over 80% of the video
|
||||||
for (const segment of segments) {
|
return "One of your submitted segments is over 80% of the video.";
|
||||||
if ((segment.segment[1] - segment.segment[0]) > (duration / 100) * 80) {
|
|
||||||
// Reject submission if over 80% of the video
|
|
||||||
return "One of your submitted segments is over 80% of the video.";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let neuralBlockURL = config.neuralBlockURL;
|
let neuralBlockURL = config.neuralBlockURL;
|
||||||
@@ -109,27 +107,24 @@ async function autoModerateSubmission(submission, callback) {
|
|||||||
|
|
||||||
let overlap = true;
|
let overlap = true;
|
||||||
|
|
||||||
let response = await fetch(neuralBlockURL + "/api/getSponsorSegments?vid=" + videoID);
|
let response = await fetch(neuralBlockURL + "/api/getSponsorSegments?vid=" + submission.videoID);
|
||||||
if (!response.ok) return false;
|
if (!response.ok) return false;
|
||||||
|
|
||||||
let nbPredictions = await response.json();
|
let nbPredictions = await response.json();
|
||||||
for (const segment of segments) {
|
if (submission.category !== "sponsor") return false;
|
||||||
if (segment.category !== "sponsor") continue;
|
|
||||||
|
|
||||||
let thisSegmentOverlaps = false;
|
let thisSegmentOverlaps = false;
|
||||||
for (const nbSegment of nbPredictions.sponsorSegments) {
|
for (const nbSegment of nbPredictions.sponsorSegments) {
|
||||||
// The submission needs to be similar to the NB prediction by 65% or off by less than 7 seconds
|
// The submission needs to be similar to the NB prediction by 65% or off by less than 7 seconds
|
||||||
// This calculated how off it is
|
// This calculated how off it is
|
||||||
let offAmount = Math.abs(nbSegment[0] - segment.segment[0]) + Math.abs(nbSegment[1] - segment.segment[1]);
|
let offAmount = Math.abs(nbSegment[0] - submission.startTime) + Math.abs(nbSegment[1] - submission.endTime);
|
||||||
if (offAmount / (nbSegment[1] - nbSegment[0]) <= 0.35 || offAmount <= 7) {
|
if (offAmount / (nbSegment[1] - nbSegment[0]) <= 0.35 || offAmount <= 7) {
|
||||||
thisSegmentOverlaps = true;
|
thisSegmentOverlaps = true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!thisSegmentOverlaps){
|
if (!thisSegmentOverlaps){
|
||||||
overlap = false;
|
overlap = false;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (overlap) {
|
if (overlap) {
|
||||||
@@ -226,14 +221,14 @@ module.exports = async function postSkipSegments(req, res) {
|
|||||||
res.sendStatus(409);
|
res.sendStatus(409);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Auto moderator check
|
// Auto moderator check
|
||||||
if (!isVIP) {
|
if (!isVIP) {
|
||||||
let autoModerateResult = await autoModerateSubmission(videoID, segments);
|
let autoModerateResult = await autoModerateSubmission({videoID, startTime, endTime, category: segments[i].category});
|
||||||
if (autoModerateResult) {
|
if (autoModerateResult) {
|
||||||
res.status(403).send("Request rejected by auto moderator: " + autoModerateResult + " If this is an issue, send a message on Discord.");
|
res.status(403).send("Request rejected by auto moderator: " + autoModerateResult + " If this is an issue, send a message on Discord.");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user