mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
add innertube tests for private videos
This commit is contained in:
parent
90e68caaf7
commit
7fb68937d0
5 changed files with 53 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
||||||
export interface innerTubeVideoDetails {
|
export interface innerTubeVideoDetails {
|
||||||
"videoId": string,
|
"videoId": string,
|
||||||
"title": string,
|
"title": string,
|
||||||
"lengthSeconds": string, // yes, don't ask.
|
"lengthSeconds"?: string, // yes, don't ask.
|
||||||
"channelId": string,
|
"channelId": string,
|
||||||
"isOwnerViewing": boolean,
|
"isOwnerViewing": boolean,
|
||||||
"shortDescription": string,
|
"shortDescription": string,
|
||||||
|
|
|
@ -3,6 +3,30 @@ import { Logger } from "./logger";
|
||||||
import { innerTubeVideoDetails } from "../types/innerTubeApi.model";
|
import { innerTubeVideoDetails } from "../types/innerTubeApi.model";
|
||||||
import DiskCache from "./diskCache";
|
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> {
|
async function getFromITube (videoID: string): Promise<innerTubeVideoDetails> {
|
||||||
// start subrequest
|
// start subrequest
|
||||||
const url = "https://www.youtube.com/youtubei/v1/player";
|
const url = "https://www.youtube.com/youtubei/v1/player";
|
||||||
|
@ -20,9 +44,9 @@ async function getFromITube (videoID: string): Promise<innerTubeVideoDetails> {
|
||||||
});
|
});
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (result.status === 200) {
|
if (result.status === 200) {
|
||||||
return result.data.videoDetails;
|
return result.data?.videoDetails ?? privateResponse(videoID);
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject(result.status);
|
return Promise.reject(`Innertube returned non-200 response: ${result.status}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,4 +46,9 @@ describe("innertube API test", function() {
|
||||||
const videoDetail = await getVideoDetails(videoID);
|
const videoDetail = await getVideoDetails(videoID);
|
||||||
assert.ok(videoDetail);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
|
@ -1292,4 +1292,20 @@ describe("postSkipSegments", () => {
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.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));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -63,6 +63,11 @@ export class YouTubeApiMock {
|
||||||
lengthSeconds: 100,
|
lengthSeconds: 100,
|
||||||
} as APIVideoData
|
} as APIVideoData
|
||||||
};
|
};
|
||||||
|
} else if (obj.id === "private-video") {
|
||||||
|
return {
|
||||||
|
err: false,
|
||||||
|
data: {} as APIVideoData
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
err: false,
|
err: false,
|
||||||
|
|
Loading…
Reference in a new issue