Extract YouTube video ratings
This commit is contained in:
parent
fdf6e6defe
commit
3380b2a72c
@ -154,8 +154,8 @@ export class YouTubeVideo {
|
|||||||
this.views = parseInt(data.views) || 0;
|
this.views = parseInt(data.views) || 0;
|
||||||
this.thumbnail = data.thumbnail || {};
|
this.thumbnail = data.thumbnail || {};
|
||||||
this.channel = new YouTubeChannel(data.channel) || {};
|
this.channel = new YouTubeChannel(data.channel) || {};
|
||||||
this.likes = (data.ratings?.likes as number) || 0;
|
this.likes = data.likes || 0;
|
||||||
this.dislikes = data.ratings?.dislikes || 0;
|
this.dislikes = data.dislikes || 0;
|
||||||
this.live = !!data.live;
|
this.live = !!data.live;
|
||||||
this.private = !!data.private;
|
this.private = !!data.private;
|
||||||
this.tags = data.tags || [];
|
this.tags = data.tags || [];
|
||||||
|
|||||||
@ -162,6 +162,10 @@ export async function video_basic_info(url: string, options: InfoOptions = {}):
|
|||||||
const format = [];
|
const format = [];
|
||||||
const vid = player_response.videoDetails;
|
const vid = player_response.videoDetails;
|
||||||
const microformat = player_response.microformat.playerMicroformatRenderer;
|
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({
|
const video_details = new YouTubeVideo({
|
||||||
id: vid.videoId,
|
id: vid.videoId,
|
||||||
url: `https://www.youtube.com/watch?v=${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,
|
views: vid.viewCount,
|
||||||
tags: vid.keywords,
|
tags: vid.keywords,
|
||||||
averageRating: vid.averageRating,
|
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,
|
live: vid.isLiveContent,
|
||||||
private: vid.isPrivate
|
private: vid.isPrivate
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user