Skip to content

Commit

Permalink
feat: add is_live and is_upcoming to VideoDetails (#271)
Browse files Browse the repository at this point in the history
* feat: add is_live and is_upcoming to VideoDetails

* chore: add tests
  • Loading branch information
absidue authored Jan 3, 2023
1 parent b704c8e commit 22b9c17
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/parser/classes/misc/VideoDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class VideoDetails {
view_count: number;
author: string;
is_private: boolean;
is_live: boolean;
is_live_content: boolean;
is_upcoming: boolean;
is_crawlable: boolean;

constructor(data: any) {
Expand All @@ -29,7 +31,9 @@ class VideoDetails {
this.view_count = parseInt(data.viewCount);
this.author = data.author;
this.is_private = !!data.isPrivate;
this.is_live = !!data.isLive;
this.is_live_content = !!data.isLiveContent;
this.is_upcoming = !!data.isUpcoming;
this.is_crawlable = !!data.isCrawlable;
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ export const VIDEOS = [
{
ID: 'OqiXFXlYFi8',
QUERY: 'formatted comment text'
},
{
ID: 'O3cCYok_ukk',
QUERY: 'upcoming video'
},
{
ID: 'jfKfPfyJRdk',
QUERY: 'live video'
}
];

Expand Down
10 changes: 10 additions & 0 deletions test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ describe('YouTube.js Tests', () => {
const b_info = await yt.getBasicInfo(VIDEOS[0].ID);
expect(b_info.basic_info.id).toBe(VIDEOS[0].ID);
});

it('should be upcoming', async () => {
const b_info = await yt.getBasicInfo(VIDEOS[4].ID);
expect(b_info.basic_info.is_upcoming).toBe(true);
});

it('should be live', async () => {
const b_info = await yt.getBasicInfo(VIDEOS[5].ID);
expect(b_info.basic_info.is_live).toBe(true);
});
});

describe('Search', () => {
Expand Down

0 comments on commit 22b9c17

Please sign in to comment.