Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions databases/_upgrade_sponsorTimes_45.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
BEGIN TRANSACTION;

ALTER TABLE "sponsorTimes" ADD "cropLeft" INTEGER;
ALTER TABLE "sponsorTimes" ADD "cropRight" INTEGER;
ALTER TABLE "sponsorTimes" ADD "cropTop" INTEGER;
ALTER TABLE "sponsorTimes" ADD "cropBottom" INTEGER;

ALTER TABLE "archivedSponsorTimes" ADD "cropLeft" INTEGER;
ALTER TABLE "archivedSponsorTimes" ADD "cropRight" INTEGER;
ALTER TABLE "archivedSponsorTimes" ADD "cropTop" INTEGER;
ALTER TABLE "archivedSponsorTimes" ADD "cropBottom" INTEGER;

UPDATE "config" SET value = 45 WHERE key = 'version';

COMMIT;
5 changes: 3 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ addDefaults(config, {
privateDBSchema: "./databases/_private.db.sql",
readOnly: false,
webhooks: [],
categoryList: ["sponsor", "selfpromo", "exclusive_access", "interaction", "intro", "outro", "preview", "music_offtopic", "filler", "poi_highlight", "chapter"],
categoryList: ["sponsor", "selfpromo", "exclusive_access", "interaction", "intro", "outro", "preview", "music_offtopic", "filler", "poi_highlight", "chapter", "windowbox"],
casualCategoryList: ["funny", "creative", "clever", "descriptive", "other"],
categorySupport: {
sponsor: ["skip", "mute", "full"],
Expand All @@ -32,7 +32,8 @@ addDefaults(config, {
filler: ["skip", "mute"],
music_offtopic: ["skip"],
poi_highlight: ["poi"],
chapter: ["chapter"]
chapter: ["chapter", "crop"],
windowbox: ["full", "crop"]
},
deArrowTypes: ["title", "thumbnail"],
maxTitleLength: 110,
Expand Down
4 changes: 2 additions & 2 deletions src/routes/getSkipSegments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ async function getSegmentsFromDBByHash(hashedVideoIDPrefix: VideoIDHash, service
const fetchFromDB = () => db
.prepare(
"all",
`SELECT "videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "category", "actionType", "videoDuration", "hidden", "reputation", "shadowHidden", "hashedVideoID", "timeSubmitted", "description" FROM "sponsorTimes"
`SELECT "videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "category", "actionType", "videoDuration", "hidden", "reputation", "shadowHidden", "hashedVideoID", "timeSubmitted", "description", "cropLeft", "cropRight", "cropTop", "cropBottom" FROM "sponsorTimes"
WHERE "hashedVideoID" LIKE ? AND "service" = ? ORDER BY "startTime"`,
[`${hashedVideoIDPrefix}%`, service],
{ useReplica: true }
Expand All @@ -237,7 +237,7 @@ async function getSegmentsFromDBByVideoID(videoID: VideoID, service: Service): P
const fetchFromDB = () => db
.prepare(
"all",
`SELECT "startTime", "endTime", "votes", "locked", "UUID", "userID", "category", "actionType", "videoDuration", "hidden", "reputation", "shadowHidden", "timeSubmitted", "description" FROM "sponsorTimes"
`SELECT "startTime", "endTime", "votes", "locked", "UUID", "userID", "category", "actionType", "videoDuration", "hidden", "reputation", "shadowHidden", "timeSubmitted", "description", "cropLeft", "cropRight", "cropTop", "cropBottom" FROM "sponsorTimes"
WHERE "videoID" = ? AND "service" = ? ORDER BY "startTime"`,
[videoID, service],
{ useReplica: true }
Expand Down
34 changes: 31 additions & 3 deletions src/routes/postSkipSegments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,34 @@
return { pass: false, errorMessage: "ActionType is not supported with this category.", errorCode: 400 };
}

if (segments[i].actionType === ActionType.Crop) {
const cropFields = [
{ name: 'cropLeft', value: segments[i].cropLeft },

Check warning on line 307 in src/routes/postSkipSegments.ts

View workflow job for this annotation

GitHub Actions / Lint with ESLint and build

Strings must use doublequote
{ name: 'cropRight', value: segments[i].cropRight },

Check warning on line 308 in src/routes/postSkipSegments.ts

View workflow job for this annotation

GitHub Actions / Lint with ESLint and build

Strings must use doublequote
{ name: 'cropTop', value: segments[i].cropTop },

Check warning on line 309 in src/routes/postSkipSegments.ts

View workflow job for this annotation

GitHub Actions / Lint with ESLint and build

Strings must use doublequote
{ name: 'cropBottom', value: segments[i].cropBottom }

Check warning on line 310 in src/routes/postSkipSegments.ts

View workflow job for this annotation

GitHub Actions / Lint with ESLint and build

Strings must use doublequote
];
for (const field of cropFields) {
if (field.value !== undefined) {
if (!Number.isInteger(field.value) || field.value < 0 || field.value > 255) {
return { pass: false, errorMessage: `${field.name} must be an integer between 0 and 255.`, errorCode: 400 };
}
}
}

Check warning on line 319 in src/routes/postSkipSegments.ts

View workflow job for this annotation

GitHub Actions / Lint with ESLint and build

Trailing spaces not allowed
const leftValue = segments[i].cropLeft || 0;
const rightValue = segments[i].cropRight || 0;
const topValue = segments[i].cropTop || 0;
const bottomValue = segments[i].cropBottom || 0;

Check warning on line 324 in src/routes/postSkipSegments.ts

View workflow job for this annotation

GitHub Actions / Lint with ESLint and build

Trailing spaces not allowed
if (leftValue + rightValue > 256) {
return { pass: false, errorMessage: "cropLeft + cropRight must not exceed 256.", errorCode: 400 };
}
if (topValue + bottomValue > 256) {
return { pass: false, errorMessage: "cropTop + cropBottom must not exceed 256.", errorCode: 400 };
}
}

const startTime = parseFloat(segments[i].segment[0]);
const endTime = parseFloat(segments[i].segment[1]);

Expand Down Expand Up @@ -612,10 +640,10 @@
const startingLocked = isVIP ? 1 : 0;
try {
await db.prepare("run", `INSERT INTO "sponsorTimes"
("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "reputation", "shadowHidden", "hashedVideoID", "userAgent", "description")
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "reputation", "shadowHidden", "hashedVideoID", "userAgent", "description", "cropLeft", "cropRight", "cropTop", "cropBottom")
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
videoID, segmentInfo.segment[0], segmentInfo.segment[1], startingVotes, startingLocked, UUID, userID, timeSubmitted, 0
, segmentInfo.category, segmentInfo.actionType, service, videoDuration, reputation, isBanned ? 1 : 0, hashedVideoID, userAgent, segmentInfo.description
, segmentInfo.category, segmentInfo.actionType, service, videoDuration, reputation, isBanned ? 1 : 0, hashedVideoID, userAgent, segmentInfo.description, segmentInfo.cropLeft, segmentInfo.cropRight, segmentInfo.cropTop, segmentInfo.cropBottom
],
);

Expand Down
19 changes: 16 additions & 3 deletions src/types/segments.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { HashedUserID, UserID } from "./user.model";
export type SegmentUUID = string & { __segmentUUIDBrand: unknown };
export type VideoID = string & { __videoIDBrand: unknown };
export type VideoDuration = number & { __videoDurationBrand: unknown };
export type Category = ("sponsor" | "selfpromo" | "interaction" | "intro" | "outro" | "preview" | "music_offtopic" | "poi_highlight" | "chapter" | "filler" | "exclusive_access") & { __categoryBrand: unknown };
export type Category = ("sponsor" | "selfpromo" | "interaction" | "intro" | "outro" | "preview" | "music_offtopic" | "poi_highlight" | "chapter" | "filler" | "exclusive_access" | "windowbox") & { __categoryBrand: unknown };
export type DeArrowType = "title" | "thumbnail";
export type VideoIDHash = VideoID & HashedValue;
export type IPAddress = string & { __ipAddressBrand: unknown };
Expand All @@ -16,7 +16,8 @@ export enum ActionType {
Mute = "mute",
Chapter = "chapter",
Full = "full",
Poi = "poi"
Poi = "poi",
Crop = "crop"
}

// Uncomment as needed
Expand All @@ -35,6 +36,10 @@ export interface IncomingSegment {
actionType: ActionType;
segment: string[];
description?: string;
cropLeft?: number;
cropRight?: number;
cropTop?: number;
cropBottom?: number;

// Used to remove in pre-check stage
ignoreSegment?: boolean;
Expand All @@ -49,6 +54,10 @@ export interface Segment {
locked: boolean;
votes: number;
description: string;
cropLeft?: number;
cropRight?: number;
cropTop?: number;
cropBottom?: number;
}

export enum Visibility {
Expand Down Expand Up @@ -78,6 +87,10 @@ export interface DBSegment {
userAgent: string;
service: Service;
description: string;
cropLeft?: number;
cropRight?: number;
cropTop?: number;
cropBottom?: number;
}

export interface OverlappingSegmentGroup {
Expand Down Expand Up @@ -133,4 +146,4 @@ export enum VoteType {
ExtraDownvote = 2,
Undo = 20,
Malicious = 30
}
}
Loading