add innerTube as primary videoInfo endpoint

- drop videoInfo.genreUrl since it's always empty
- bump ts target to ES2021 for Promise.any
- fix mocks to return err: false
- get maxResThumbnail from static endpoint
This commit is contained in:
Michael C
2022-09-15 17:02:33 -04:00
parent 3c09033267
commit 62a9b0eddd
15 changed files with 130 additions and 109 deletions

View File

@@ -19,9 +19,9 @@ if (db instanceof Postgres) {
await db.prepare("run", query, [chapterNamesVid1, 70, 75, 2, 0, "chapterNamesVid-2", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, 0, "A different one"]);
await db.prepare("run", query, [chapterNamesVid1, 71, 76, 2, 0, "chapterNamesVid-3", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, 0, "Something else"]);
await db.prepare("run", `INSERT INTO "videoInfo" ("videoID", "channelID", "title", "published", "genreUrl")
SELECT ?, ?, ?, ?, ?`, [
chapterNamesVid1, chapterChannelID, "", 0, ""
await db.prepare("run", `INSERT INTO "videoInfo" ("videoID", "channelID", "title", "published")
SELECT ?, ?, ?, ?`, [
chapterNamesVid1, chapterChannelID, "", 0
]);
});

View File

@@ -4,10 +4,10 @@ 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";
const videoID = "dQw4w9WgXcQ";
const expected = { // partial type of innerTubeVideoDetails
const expectedInnerTube = { // partial type of innerTubeVideoDetails
videoId: videoID,
title: "Rick Astley - Never Gonna Give You Up (Official Music Video)",
lengthSeconds: "212",
@@ -25,17 +25,12 @@ const currentViews = 1284257550;
describe("innertube API test", function() {
it("should be able to get innerTube details", async () => {
const result = await innerTube.getPlayerData(videoID);
assert.ok(partialDeepEquals(result, expected));
assert.ok(partialDeepEquals(result, expectedInnerTube));
});
it("Should have more views than current", async () => {
const result = await innerTube.getPlayerData(videoID);
assert.ok(Number(result.viewCount) >= currentViews);
});
it("Should have the same video duration from both endpoints", async () => {
const playerData = await innerTube.getPlayerData(videoID);
const length = await innerTube.getLength(videoID);
assert.equal(Number(playerData.lengthSeconds), length);
});
it("Should have equivalent response from NewLeaf", async function () {
if (!config.newLeafURLs || config.newLeafURLs.length <= 0 || config.newLeafURLs[0] == "placeholder") this.skip();
const itResponse = await innerTube.getPlayerData(videoID);
@@ -48,4 +43,8 @@ describe("innertube API test", function() {
// 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);
});
});

View File

@@ -141,7 +141,6 @@ describe("postSkipSegments", () => {
title: "Example Title",
channelID: "ExampleChannel",
published: 123,
genreUrl: ""
};
assert.ok(partialDeepEquals(videoInfo, expectedVideoInfo));

View File

@@ -15,7 +15,7 @@ export class YouTubeApiMock {
if (obj.id === "noDuration" || obj.id === "full_video_duration_segment") {
return {
err: null,
err: false,
data: {
title: "Example Title",
lengthSeconds: 0,
@@ -32,7 +32,7 @@ export class YouTubeApiMock {
};
} else if (obj.id === "duration-update") {
return {
err: null,
err: false,
data: {
title: "Example Title",
lengthSeconds: 500,
@@ -49,7 +49,7 @@ export class YouTubeApiMock {
};
} else if (obj.id === "channelid-convert") {
return {
err: null,
err: false,
data: {
title: "Video Lookup Title",
author: "ChannelAuthor",
@@ -58,14 +58,14 @@ export class YouTubeApiMock {
};
} else if (obj.id === "duration-changed") {
return {
err: null,
err: false,
data: {
lengthSeconds: 100,
} as APIVideoData
};
} else {
return {
err: null,
err: false,
data: {
title: "Example Title",
authorId: "ExampleChannel",