Merge pull request #170 from absidue/extract-youtube-ratings
Extract YouTube video ratings
This commit is contained in:
commit
4ff2c5a19f
@ -154,8 +154,8 @@ export class YouTubeVideo {
|
||||
this.views = parseInt(data.views) || 0;
|
||||
this.thumbnail = data.thumbnail || {};
|
||||
this.channel = new YouTubeChannel(data.channel) || {};
|
||||
this.likes = (data.ratings?.likes as number) || 0;
|
||||
this.dislikes = data.ratings?.dislikes || 0;
|
||||
this.likes = data.likes || 0;
|
||||
this.dislikes = data.dislikes || 0;
|
||||
this.live = !!data.live;
|
||||
this.private = !!data.private;
|
||||
this.tags = data.tags || [];
|
||||
|
||||
@ -162,6 +162,10 @@ export async function video_basic_info(url: string, options: InfoOptions = {}):
|
||||
const format = [];
|
||||
const vid = player_response.videoDetails;
|
||||
const microformat = player_response.microformat.playerMicroformatRenderer;
|
||||
const ratingButtons =
|
||||
initial_response.contents.twoColumnWatchNextResults.results.results.contents.find(
|
||||
(content: any) => content.videoPrimaryInfoRenderer
|
||||
)?.videoPrimaryInfoRenderer.videoActions.menuRenderer.topLevelButtons ?? [];
|
||||
const video_details = new YouTubeVideo({
|
||||
id: vid.videoId,
|
||||
url: `https://www.youtube.com/watch?v=${vid.videoId}`,
|
||||
@ -182,6 +186,16 @@ export async function video_basic_info(url: string, options: InfoOptions = {}):
|
||||
views: vid.viewCount,
|
||||
tags: vid.keywords,
|
||||
averageRating: vid.averageRating,
|
||||
likes: parseInt(
|
||||
ratingButtons
|
||||
.find((button: any) => button.toggleButtonRenderer.defaultIcon.iconType === 'LIKE')
|
||||
?.toggleButtonRenderer.defaultText.accessibility?.accessibilityData.label.replace(/\D+/g, '') ?? 0
|
||||
),
|
||||
dislikes: parseInt(
|
||||
ratingButtons
|
||||
.find((button: any) => button.toggleButtonRenderer.defaultIcon.iconType === 'DISLIKE')
|
||||
?.toggleButtonRenderer.defaultText.accessibility?.accessibilityData.label.replace(/\D+/g, '') ?? 0
|
||||
),
|
||||
live: vid.isLiveContent,
|
||||
private: vid.isPrivate
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user