mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2026-03-16 16:23:26 +03:00
add innerTube API, types and tests
This commit is contained in:
23
src/types/innerTubeApi.model.ts
Normal file
23
src/types/innerTubeApi.model.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
export interface innerTubeVideoDetails {
|
||||
"videoId": string,
|
||||
"title": string,
|
||||
"lengthSeconds": string, // yes, don't ask.
|
||||
"channelId": string,
|
||||
"isOwnerViewing": boolean,
|
||||
"shortDescription": string,
|
||||
"isCrawlable": boolean,
|
||||
"thumbnail": {
|
||||
"thumbnails": [{
|
||||
"url": string,
|
||||
"width": number,
|
||||
"height": number
|
||||
}
|
||||
]
|
||||
},
|
||||
"allowRatings": boolean,
|
||||
"viewCount": string, // yes, don't ask
|
||||
"author": string,
|
||||
"isPrivate": boolean,
|
||||
"isUnpluggedCorpus": boolean,
|
||||
"isLiveContent": boolean
|
||||
}
|
||||
29
src/utils/innerTubeAPI.ts
Normal file
29
src/utils/innerTubeAPI.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import axios from "axios";
|
||||
import { innerTubeVideoDetails } from "../types/innerTubeApi.model";
|
||||
|
||||
export async function getPlayerData(videoID: string): Promise<innerTubeVideoDetails> {
|
||||
// start subrequest
|
||||
const url = "https://www.youtube.com/youtubei/v1/player";
|
||||
const data = {
|
||||
context: {
|
||||
client: {
|
||||
clientName: "WEB",
|
||||
clientVersion: "2.20211129.09.00"
|
||||
}
|
||||
},
|
||||
videoId: videoID
|
||||
};
|
||||
const result = await axios.post(url, data, {
|
||||
timeout: 3500
|
||||
});
|
||||
if (result.status === 200) {
|
||||
return result.data.videoDetails;
|
||||
} else {
|
||||
return Promise.reject(result.status);
|
||||
}
|
||||
}
|
||||
|
||||
export const getLength = (videoID: string): Promise<number> =>
|
||||
getPlayerData(videoID)
|
||||
.then(pData => Number(pData.lengthSeconds))
|
||||
.catch(err => err);
|
||||
Reference in New Issue
Block a user