mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-13 06:57:05 +03:00
Added automod check with NB
This commit is contained in:
@@ -17,7 +17,8 @@
|
||||
"http": "0.0.0",
|
||||
"iso8601-duration": "^1.2.0",
|
||||
"uuid": "^3.3.2",
|
||||
"youtube-api": "^2.0.10"
|
||||
"youtube-api": "^2.0.10",
|
||||
"node-fetch": "^2.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^7.1.1",
|
||||
|
||||
@@ -10,6 +10,7 @@ var isoDurations = require('iso8601-duration');
|
||||
var getHash = require('../utils/getHash.js');
|
||||
var getIP = require('../utils/getIP.js');
|
||||
var getFormattedTime = require('../utils/getFormattedTime.js');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
// TODO: might need to be a util
|
||||
//returns true if the user is considered trustworthy
|
||||
@@ -110,7 +111,26 @@ async function autoModerateSubmission(submission, callback) {
|
||||
if ((submission.endTime - submission.startTime) > (duration/100)*80) {
|
||||
return "Sponsor segment is over 80% of the video.";
|
||||
} else {
|
||||
return false;
|
||||
let overlap = false;
|
||||
nb_predictions = fetch("https://ai.neuralblock.app/api/getSponsorSegments?vid=" + submission.videoID).then().then();
|
||||
for (nb_seg in nb_predictions.sponsorSegments){
|
||||
let head = 0;
|
||||
let tail = 0;
|
||||
// If there's an overlap, find the percentage of overlap.
|
||||
if (submission.startTime <= nb_seg[1] && nb_seg[0] <= submission.endTime){
|
||||
head = Math.max(submission.startTime, nb_seg[0]);
|
||||
tail = Math.min(submission.endTime, nb_seg[1]);
|
||||
}
|
||||
if ((tail-head)/(nb_seg[1]-nb_seg[0]) > 0.65){
|
||||
overlap = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (overlap){
|
||||
return "Sponsor segment has passed checks.";
|
||||
} else{
|
||||
return "Sponsor segment doesn't have at least 65% match.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,16 @@ describe('postSkipSegments', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('Should be rejected if there\'s not at least 65% overlap with NB' , (done) => {
|
||||
request.get(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?videoID=LevkAjUE6d4&startTime=40&endTime=60&userID=testing", null,
|
||||
(err, res, body) => {
|
||||
if (err) done("Couldn't call endpoint");
|
||||
else if (res.statusCode === 403) done(); // pass
|
||||
else done("non 403 status code: " + res.statusCode + " ("+body+")");
|
||||
});
|
||||
});
|
||||
|
||||
it('Should be rejected if not a valid videoID', (done) => {
|
||||
request.get(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?videoID=knownWrongID&startTime=30&endTime=1000000&userID=testing", null,
|
||||
|
||||
Reference in New Issue
Block a user