Dislike count added
This commit is contained in:
parent
68f435a658
commit
f5da982b58
@ -55,6 +55,10 @@ interface VideoOptions {
|
|||||||
* YouTube Video's dislikes
|
* YouTube Video's dislikes
|
||||||
*/
|
*/
|
||||||
dislikes: number;
|
dislikes: number;
|
||||||
|
/**
|
||||||
|
* YouTube Video's average Rating
|
||||||
|
*/
|
||||||
|
averageRating: number;
|
||||||
/**
|
/**
|
||||||
* YouTube Video live status
|
* YouTube Video live status
|
||||||
*/
|
*/
|
||||||
@ -124,6 +128,10 @@ export class YouTubeVideo {
|
|||||||
* YouTube Video's dislikes
|
* YouTube Video's dislikes
|
||||||
*/
|
*/
|
||||||
dislikes: number;
|
dislikes: number;
|
||||||
|
/**
|
||||||
|
* YouTube Video's average Rating
|
||||||
|
*/
|
||||||
|
averageRating: number;
|
||||||
/**
|
/**
|
||||||
* YouTube Video live status
|
* YouTube Video live status
|
||||||
*/
|
*/
|
||||||
@ -155,7 +163,8 @@ export class YouTubeVideo {
|
|||||||
this.thumbnail = new YouTubeThumbnail(data.thumbnail) || {};
|
this.thumbnail = new YouTubeThumbnail(data.thumbnail) || {};
|
||||||
this.channel = new YouTubeChannel(data.channel) || {};
|
this.channel = new YouTubeChannel(data.channel) || {};
|
||||||
this.likes = data.likes || 0;
|
this.likes = data.likes || 0;
|
||||||
this.dislikes = data.dislikes || 0;
|
this.averageRating = data.averageRating || 0;
|
||||||
|
this.dislikes = Math.floor((this.likes * (5 - this.averageRating)) / (this.averageRating - 1)) || 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 || [];
|
||||||
@ -186,6 +195,7 @@ export class YouTubeVideo {
|
|||||||
tags: this.tags,
|
tags: this.tags,
|
||||||
likes: this.likes,
|
likes: this.likes,
|
||||||
dislikes: this.dislikes,
|
dislikes: this.dislikes,
|
||||||
|
averageRating: this.averageRating,
|
||||||
live: this.live,
|
live: this.live,
|
||||||
private: this.private
|
private: this.private
|
||||||
};
|
};
|
||||||
|
|||||||
@ -85,13 +85,13 @@ export function extractID(url: string): string {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Basic function to get data from a YouTube url or ID.
|
* Basic function to get data from a YouTube url or ID.
|
||||||
*
|
*
|
||||||
* Example
|
* Example
|
||||||
* ```ts
|
* ```ts
|
||||||
* const video = await play.video_basic_info('youtube video url')
|
* const video = await play.video_basic_info('youtube video url')
|
||||||
*
|
*
|
||||||
* const res = ... // Any https package get function.
|
* const res = ... // Any https package get function.
|
||||||
*
|
*
|
||||||
* const video = await play.video_basic_info(res.body, { htmldata : true })
|
* const video = await play.video_basic_info(res.body, { htmldata : true })
|
||||||
* ```
|
* ```
|
||||||
* @param url YouTube url or ID or html body data
|
* @param url YouTube url or ID or html body data
|
||||||
@ -156,7 +156,6 @@ export async function video_basic_info(url: string, options: InfoOptions = {}):
|
|||||||
)?.videoPrimaryInfoRenderer.videoActions.menuRenderer.topLevelButtons ?? [];
|
)?.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}`,
|
|
||||||
title: vid.title,
|
title: vid.title,
|
||||||
description: vid.shortDescription,
|
description: vid.shortDescription,
|
||||||
duration: Number(vid.lengthSeconds),
|
duration: Number(vid.lengthSeconds),
|
||||||
@ -179,11 +178,6 @@ export async function video_basic_info(url: string, options: InfoOptions = {}):
|
|||||||
.find((button: any) => button.toggleButtonRenderer.defaultIcon.iconType === 'LIKE')
|
.find((button: any) => button.toggleButtonRenderer.defaultIcon.iconType === 'LIKE')
|
||||||
?.toggleButtonRenderer.defaultText.accessibility?.accessibilityData.label.replace(/\D+/g, '') ?? 0
|
?.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
|
||||||
});
|
});
|
||||||
@ -284,13 +278,13 @@ function parseSeconds(seconds: number): string {
|
|||||||
* ```
|
* ```
|
||||||
* video_basic_info + decipher_info = video_info
|
* video_basic_info + decipher_info = video_info
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* Example
|
* Example
|
||||||
* ```ts
|
* ```ts
|
||||||
* const video = await play.video_info('youtube video url')
|
* const video = await play.video_info('youtube video url')
|
||||||
*
|
*
|
||||||
* const res = ... // Any https package get function.
|
* const res = ... // Any https package get function.
|
||||||
*
|
*
|
||||||
* const video = await play.video_info(res.body, { htmldata : true })
|
* const video = await play.video_info(res.body, { htmldata : true })
|
||||||
* ```
|
* ```
|
||||||
* @param url YouTube url or ID or html body data
|
* @param url YouTube url or ID or html body data
|
||||||
@ -319,17 +313,17 @@ export async function decipher_info<T extends InfoData | StreamInfoData>(data: T
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Gets YouTube playlist info from a playlist url.
|
* Gets YouTube playlist info from a playlist url.
|
||||||
*
|
*
|
||||||
* Example
|
* Example
|
||||||
* ```ts
|
* ```ts
|
||||||
* const playlist = await play.playlist_info('youtube playlist url')
|
* const playlist = await play.playlist_info('youtube playlist url')
|
||||||
*
|
*
|
||||||
* const playlist = await play.playlist_info('youtube playlist url', { incomplete : true })
|
* const playlist = await play.playlist_info('youtube playlist url', { incomplete : true })
|
||||||
* ```
|
* ```
|
||||||
* @param url Playlist URL
|
* @param url Playlist URL
|
||||||
* @param options Playlist Info Options
|
* @param options Playlist Info Options
|
||||||
* - `boolean` incomplete : If set to true, parses playlist with hidden videos.
|
* - `boolean` incomplete : If set to true, parses playlist with hidden videos.
|
||||||
*
|
*
|
||||||
* @returns YouTube Playlist
|
* @returns YouTube Playlist
|
||||||
*/
|
*/
|
||||||
export async function playlist_info(url: string, options: PlaylistOptions = {}): Promise<YouTubePlayList> {
|
export async function playlist_info(url: string, options: PlaylistOptions = {}): Promise<YouTubePlayList> {
|
||||||
|
|||||||
@ -30,15 +30,15 @@ interface tokenOptions {
|
|||||||
* iv> Useragents :- array of string.
|
* iv> Useragents :- array of string.
|
||||||
*
|
*
|
||||||
* locally in memory.
|
* locally in memory.
|
||||||
*
|
*
|
||||||
* Example :
|
* Example :
|
||||||
* ```ts
|
* ```ts
|
||||||
* play.setToken({
|
* play.setToken({
|
||||||
* youtube : {
|
* youtube : {
|
||||||
* cookie : "Your Cookies"
|
* cookie : "Your Cookies"
|
||||||
* }
|
* }
|
||||||
* }) // YouTube Cookies
|
* }) // YouTube Cookies
|
||||||
*
|
*
|
||||||
* play.setToken({
|
* play.setToken({
|
||||||
* useragent: ['Your User-agent']
|
* useragent: ['Your User-agent']
|
||||||
* }) // Use this to avoid 429 errors.
|
* }) // Use this to avoid 429 errors.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user