Skip to content

Commit

Permalink
feat: add getVideoPlayData (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-online authored May 8, 2024
1 parent c9536fb commit 55a5928
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 2 deletions.
108 changes: 106 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,37 @@ export class BunnyCdnStream {
);
}

/**
* Get video play data
* @returns A {@link BunnyCdnStream.VideoPlayDataResponse} instance.
* @param videoId The video id to get play data from
* @param expires The expiration time of the token
* @param data The data to fetch video play data with
* @example
* ```typescript
* await stream.getVideoPlayData("0273f24a-79d1-d0fe-97ca-b0e36bed31es")
* ```
*/
public async getVideoPlayData(
videoId: string,
data: {
token?: string;
expires?: number;
} = {
token: undefined,
expires: 0,
},
) {
const options = this.getOptions();
options.method = "GET";
options.url += `/library/${this.options.videoLibrary}/videos/${videoId}/play`;
options.params = data;

return this.request<BunnyCdnStream.VideoPlayDataResponse>(
options,
"getPlayData",
);
}
/**
* Get video statistics
* @returns A {@link BunnyCdnStream.VideoStatisticsResponse} instance.
Expand Down Expand Up @@ -841,9 +872,82 @@ export namespace BunnyCdnStream {
engagementScore: number;
}

export type VideoHeatmapResponse = {
export interface VideoHeatmapResponse {
heatmap: Record<string, string | number>;
};
}

export interface VideoPlayDataResponse {
video: {
videoLibraryId: number;
guid: string;
title: string;
dateUploaded: string;
views: number;
isPublic: boolean;
length: number;
status: number;
framerate: number;
rotation: number;
width: number;
height: number;
availableResolutions: string;
thumbnailCount: number;
encodeProgress: number;
storageSize: number;
captions: {
srclang: string;
label: string;
}[];
hasMP4Fallback: boolean;
collectionId: string;
thumbnailFileName: string;
averageWatchTime: number;
totalWatchTime: number;
category: string;
chapters: {
title: string;
start: number;
end: number;
}[];
moments: {
label: string;
timestamp: number;
}[];
metaTags: {
property: string;
value: string;
}[];
transcodingMessages: {
timeStamp: string;
level: number;
issueCode: number;
message: string;
value: string;
}[];
};
captionsPath: string;
seekPath: string;
thumbnailUrl: string;
fallbackUrl: string;
videoPlaylistUrl: string;
originalUrl: string;
previewUrl: string;
controls: string;
enableDRM: boolean;
drmVersion: number;
playerKeyColor: string;
vastTagUrl: string;
captionsFontSize: number;
captionsFontColor: string;
captionsBackground: string;
uiLanguage: string;
allowEarlyPlay: boolean;
tokenAuthEnabled: boolean;
enableMP4Fallback: boolean;
showHeatmap: boolean;
fontFamily: string;
playbackSpeeds: string;
}

export interface ListVideosResponse {
totalItems: number;
Expand Down
58 changes: 58 additions & 0 deletions tests/Bunny.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,64 @@ describe("BunnyCdnStream", () => {
expect(res).toEqual({ heatmap: {} });
});

test("GIVEN library w/ encoded video THEN can get play data", async () => {
const res = await stream.getVideoPlayData(videoGuid);

expect(res).toMatchObject({
video: {
videoLibraryId: expect.any(Number),
guid: expect.any(String),
title: expect.any(String),
dateUploaded: expect.any(String),
views: expect.any(Number),
isPublic: expect.any(Boolean),
length: expect.any(Number),
status: 4,
framerate: expect.any(Number),
rotation: expect.any(Number),
width: expect.any(Number),
height: expect.any(Number),
availableResolutions: expect.any(String),
thumbnailCount: expect.any(Number),
encodeProgress: 100,
storageSize: expect.any(Number),
captions: expect.arrayContaining([expect.any(Object)]),
hasMP4Fallback: expect.any(Boolean),
collectionId: expect.any(String),
thumbnailFileName: expect.any(String),
averageWatchTime: expect.any(Number),
totalWatchTime: expect.any(Number),
category: expect.any(String),
chapters: expect.any(Array),
moments: expect.any(Array),
metaTags: expect.any(Array),
transcodingMessages: expect.any(Array),
},
captionsPath: expect.any(String),
seekPath: expect.any(String),
thumbnailUrl: expect.any(String),
fallbackUrl: expect.any(String),
videoPlaylistUrl: expect.any(String),
originalUrl: null,
previewUrl: expect.any(String),
controls: expect.any(String),
enableDRM: expect.any(Boolean),
drmVersion: expect.any(Number),
playerKeyColor: expect.any(String),
vastTagUrl: null,
captionsFontSize: expect.any(Number),
captionsFontColor: expect.any(String),
captionsBackground: expect.any(String),
uiLanguage: expect.any(String),
allowEarlyPlay: expect.any(Boolean),
tokenAuthEnabled: expect.any(Boolean),
enableMP4Fallback: expect.any(Boolean),
showHeatmap: expect.any(Boolean),
fontFamily: expect.any(String),
playbackSpeeds: expect.any(String),
});
});

test("GIVEN library w/ encoded video THEN can update", async () => {
await stream.updateVideo(videoGuid, { title: "updated" });
const vid = await stream.getVideo(videoGuid);
Expand Down

0 comments on commit 55a5928

Please sign in to comment.