add innertube tests for private videos

This commit is contained in:
Michael C 2022-11-09 14:39:02 -05:00
parent 90e68caaf7
commit 7fb68937d0
No known key found for this signature in database
GPG key ID: FFB04FB3B878B7B4
5 changed files with 53 additions and 3 deletions

View file

@ -1,7 +1,7 @@
export interface innerTubeVideoDetails {
"videoId": string,
"title": string,
"lengthSeconds": string, // yes, don't ask.
"lengthSeconds"?: string, // yes, don't ask.
"channelId": string,
"isOwnerViewing": boolean,
"shortDescription": string,

View file

@ -3,6 +3,30 @@ import { Logger } from "./logger";
import { innerTubeVideoDetails } from "../types/innerTubeApi.model";
import DiskCache from "./diskCache";
const privateResponse = (videoId: string): innerTubeVideoDetails => ({
videoId,
title: "",
channelId: "",
// exclude video duration
isOwnerViewing: false,
shortDescription: "",
isCrawlable: false,
thumbnail: {
thumbnails: [{
url: "https://s.ytimg.com/yts/img/meh7-vflGevej7.png",
width: 140,
height: 100
}]
},
allowRatings: false,
viewCount: "0", // yes, don't ask
author: "",
isPrivate: true,
isUnpluggedCorpus: true,
isLiveContent: false,
publishDate: ""
});
async function getFromITube (videoID: string): Promise<innerTubeVideoDetails> {
// start subrequest
const url = "https://www.youtube.com/youtubei/v1/player";
@ -20,9 +44,9 @@ async function getFromITube (videoID: string): Promise<innerTubeVideoDetails> {
});
/* istanbul ignore else */
if (result.status === 200) {
return result.data.videoDetails;
return result.data?.videoDetails ?? privateResponse(videoID);
} else {
return Promise.reject(result.status);
return Promise.reject(`Innertube returned non-200 response: ${result.status}`);
}
}

View file

@ -46,4 +46,9 @@ describe("innertube API test", function() {
const videoDetail = await getVideoDetails(videoID);
assert.ok(videoDetail);
});
it("Should not fail when getting data for private video", async function () {
const privateVideoId = "ZuibAax0VD8";
const videoDetail = await getVideoDetails(privateVideoId);
assert.ok(videoDetail);
});
});

View file

@ -1292,4 +1292,20 @@ describe("postSkipSegments", () => {
})
.catch(err => done(err));
});
it("Should successfully submit if video is private", (done) => {
const videoID = "private-video";
postSkipSegmentParam({
videoID,
startTime: 1,
endTime: 5,
category: "sponsor",
userID: submitUserTwo
})
.then(res => {
assert.strictEqual(res.status, 200);
done();
})
.catch(err => done(err));
});
});

View file

@ -63,6 +63,11 @@ export class YouTubeApiMock {
lengthSeconds: 100,
} as APIVideoData
};
} else if (obj.id === "private-video") {
return {
err: false,
data: {} as APIVideoData
};
} else {
return {
err: false,