Add endpoint to submit unlisted videos

A temporary measure which will be removed next month

https://support.google.com/youtube/answer/9230970
This commit is contained in:
Ajay Ramachandran 2021-06-23 19:19:30 -04:00
parent 746dc4f81d
commit 42da1b6c23
3 changed files with 46 additions and 0 deletions

View file

@ -0,0 +1,10 @@
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "unlistedVideos" (
"videoID" TEXT NOT NULL,
"timeSubmitted" INTEGER NOT NULL
);
UPDATE "config" SET value = 15 WHERE key = 'version';
COMMIT;

View file

@ -30,6 +30,7 @@ import {rateLimitMiddleware} from './middleware/requestRateLimit';
import dumpDatabase, {redirectLink} from './routes/dumpDatabase';
import {endpoint as getSegmentInfo} from './routes/getSegmentInfo';
import {postClearCache} from './routes/postClearCache';
import { addUnlistedVideo } from './routes/addUnlistedVideo';
export function createServer(callback: () => void) {
// Create a service (the app object is just a callback).
@ -140,6 +141,8 @@ function setupRoutes(app: Express) {
//clear cache as VIP
app.post('/api/clearCache', postClearCache)
app.post('/api/unlistedVideo', addUnlistedVideo)
if (config.postgres) {
app.get('/database', (req, res) => dumpDatabase(req, res, true));
app.get('/database.json', (req, res) => dumpDatabase(req, res, false));

View file

@ -0,0 +1,33 @@
import { time } from 'console';
import {Request, Response} from 'express';
import { db } from '../databases/databases';
import { Logger } from '../utils/logger';
/**
* Optional API method that will be used temporarily to help collect
* unlisted videos created before 2017
*
* https://support.google.com/youtube/answer/9230970
*/
export function addUnlistedVideo(req: Request, res: Response) {
const videoID = req.body.videoID;
console.log(req.body)
if (videoID === undefined || typeof(videoID) !== "string" || videoID.length !== 11) {
res.status(400).send("Invalid parameters");
return;
}
try {
const timeSubmitted = Date.now();
db.prepare('run', `INSERT INTO "unlistedVideos" ("videoID", "timeSubmitted") values (?, ?)`, [videoID, timeSubmitted]);
} catch (err) {
Logger.error(err);
res.sendStatus(500);
return;
}
res.sendStatus(200);
}