SponsorBlockServer/test/cases/innerTubeApi.ts

54 lines
2.3 KiB
TypeScript
Raw Normal View History

2022-09-14 06:33:52 +02:00
import { config } from "../../src/config";
import assert from "assert";
import { YouTubeAPI } from "../../src/utils/youtubeApi";
import * as innerTube from "../../src/utils/innerTubeAPI";
import { partialDeepEquals } from "../utils/partialDeepEquals";
import { getVideoDetails } from "../../src/utils/getVideoDetails";
2022-09-14 06:33:52 +02:00
const videoID = "BaW_jenozKc";
const expectedInnerTube = { // partial type of innerTubeVideoDetails
2022-09-14 06:33:52 +02:00
videoId: videoID,
title: "youtube-dl test video \"'/\\ä↭𝕐",
lengthSeconds: "10",
channelId: "UCLqxVugv74EIW3VWh2NOa3Q",
2022-09-14 06:33:52 +02:00
isOwnerViewing: false,
isCrawlable: true,
allowRatings: true,
author: "Philipp Hagemeister",
2022-09-14 06:33:52 +02:00
isPrivate: false,
isUnpluggedCorpus: false,
isLiveContent: false
};
const currentViews = 49816;
2022-09-14 06:33:52 +02:00
describe("innertube API test", function() {
it("should be able to get innerTube details", async () => {
2022-09-26 21:58:33 +02:00
const result = await innerTube.getPlayerData(videoID, true);
assert.ok(partialDeepEquals(result, expectedInnerTube));
2022-09-14 06:33:52 +02:00
});
it("Should have more views than current", async () => {
2022-09-26 21:58:33 +02:00
const result = await innerTube.getPlayerData(videoID, true);
2022-09-14 06:33:52 +02:00
assert.ok(Number(result.viewCount) >= currentViews);
});
it("Should have equivalent response from NewLeaf", async function () {
if (!config.newLeafURLs || config.newLeafURLs.length <= 0 || config.newLeafURLs[0] == "placeholder") this.skip();
2022-09-26 21:58:33 +02:00
const itResponse = await innerTube.getPlayerData(videoID, true);
2022-09-14 06:33:52 +02:00
const newLeafResponse = await YouTubeAPI.listVideos(videoID, true);
// validate videoID
assert.strictEqual(itResponse.videoId, videoID);
assert.strictEqual(newLeafResponse.data?.videoId, videoID);
// validate description
assert.strictEqual(itResponse.shortDescription, newLeafResponse.data?.description);
// validate authorId
assert.strictEqual(itResponse.channelId, newLeafResponse.data?.authorId);
});
it("Should return data from generic endpoint", async function () {
const videoDetail = await getVideoDetails(videoID);
assert.ok(videoDetail);
});
2022-11-09 20:39:02 +01:00
it("Should not fail when getting data for private video", async function () {
const privateVideoId = "ZuibAax0VD8";
const videoDetail = await getVideoDetails(privateVideoId);
assert.ok(videoDetail);
});
2022-09-14 06:33:52 +02:00
});