SponsorBlockServer/test/youtubeMock.ts

88 lines
3.1 KiB
TypeScript
Raw Normal View History

2021-06-03 04:34:38 +02:00
import { APIVideoData, APIVideoInfo } from "../src/types/youtubeApi.model";
export class YouTubeApiMock {
2021-09-23 05:34:46 +02:00
// eslint-disable-next-line require-await
2021-07-04 07:34:31 +02:00
static async listVideos(videoID: string): Promise<APIVideoInfo> {
const obj = {
id: videoID
};
if (obj.id === "knownWrongID") {
2021-04-09 02:37:19 +02:00
return {
2021-06-03 04:34:38 +02:00
err: "No video found"
2021-04-09 02:37:19 +02:00
};
}
2021-04-09 02:37:19 +02:00
if (obj.id === "noDuration" || obj.id === "full_video_duration_segment") {
2021-04-09 02:37:19 +02:00
return {
err: null,
data: {
2021-06-03 04:34:38 +02:00
title: "Example Title",
lengthSeconds: 0,
videoThumbnails: [
2021-04-09 02:37:19 +02:00
{
2021-07-12 08:43:46 +02:00
quality: "maxres",
url: "https://sponsor.ajay.app/LogoSponsorBlockSimple256px.png",
second__originalUrl:"https://sponsor.ajay.app/LogoSponsorBlockSimple256px.png",
width: 1280,
height: 720
},
]
} as APIVideoData
};
} else if (obj.id === "duration-update") {
return {
err: null,
data: {
title: "Example Title",
lengthSeconds: 500,
videoThumbnails: [
{
quality: "maxres",
url: "https://sponsor.ajay.app/LogoSponsorBlockSimple256px.png",
second__originalUrl:"https://sponsor.ajay.app/LogoSponsorBlockSimple256px.png",
2021-07-12 08:43:46 +02:00
width: 1280,
height: 720
2020-10-17 20:56:54 +02:00
},
2021-06-03 04:34:38 +02:00
]
} as APIVideoData
2021-04-09 02:37:19 +02:00
};
2021-12-31 10:26:37 +01:00
} else if (obj.id === "channelid-convert") {
return {
err: null,
data: {
title: "Video Lookup Title",
author: "ChannelAuthor",
authorId: "ChannelID"
} as APIVideoData
};
} else if (obj.id === "duration-changed") {
return {
err: null,
data: {
lengthSeconds: 100,
} as APIVideoData
};
} else {
2021-04-09 02:37:19 +02:00
return {
err: null,
data: {
2021-06-03 04:34:38 +02:00
title: "Example Title",
2021-10-17 20:42:48 +02:00
authorId: "ExampleChannel",
published: 123,
2021-06-03 04:34:38 +02:00
lengthSeconds: 4980,
videoThumbnails: [
2021-04-09 02:37:19 +02:00
{
2021-07-12 08:43:46 +02:00
quality: "maxres",
url: "https://sponsor.ajay.app/LogoSponsorBlockSimple256px.png",
second__originalUrl:"https://sponsor.ajay.app/LogoSponsorBlockSimple256px.png",
width: 1280,
height: 720
2020-10-17 20:56:54 +02:00
},
2021-06-03 04:34:38 +02:00
]
} as APIVideoData
2021-04-09 02:37:19 +02:00
};
}
}
}