Dislike count added

This commit is contained in:
killer069 2021-12-08 09:47:26 +05:30
parent 68f435a658
commit f5da982b58
3 changed files with 23 additions and 19 deletions

View File

@ -55,6 +55,10 @@ interface VideoOptions {
* YouTube Video's dislikes
*/
dislikes: number;
/**
* YouTube Video's average Rating
*/
averageRating: number;
/**
* YouTube Video live status
*/
@ -124,6 +128,10 @@ export class YouTubeVideo {
* YouTube Video's dislikes
*/
dislikes: number;
/**
* YouTube Video's average Rating
*/
averageRating: number;
/**
* YouTube Video live status
*/
@ -155,7 +163,8 @@ export class YouTubeVideo {
this.thumbnail = new YouTubeThumbnail(data.thumbnail) || {};
this.channel = new YouTubeChannel(data.channel) || {};
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.private = !!data.private;
this.tags = data.tags || [];
@ -186,6 +195,7 @@ export class YouTubeVideo {
tags: this.tags,
likes: this.likes,
dislikes: this.dislikes,
averageRating: this.averageRating,
live: this.live,
private: this.private
};

View File

@ -85,13 +85,13 @@ export function extractID(url: string): string {
}
/**
* Basic function to get data from a YouTube url or ID.
*
*
* Example
* ```ts
* const video = await play.video_basic_info('youtube video url')
*
*
* const res = ... // Any https package get function.
*
*
* const video = await play.video_basic_info(res.body, { htmldata : true })
* ```
* @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 ?? [];
const video_details = new YouTubeVideo({
id: vid.videoId,
url: `https://www.youtube.com/watch?v=${vid.videoId}`,
title: vid.title,
description: vid.shortDescription,
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')
?.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
});
@ -284,13 +278,13 @@ function parseSeconds(seconds: number): string {
* ```
* video_basic_info + decipher_info = video_info
* ```
*
*
* Example
* ```ts
* const video = await play.video_info('youtube video url')
*
*
* const res = ... // Any https package get function.
*
*
* const video = await play.video_info(res.body, { htmldata : true })
* ```
* @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.
*
*
* Example
* ```ts
* const playlist = await play.playlist_info('youtube playlist url')
*
*
* const playlist = await play.playlist_info('youtube playlist url', { incomplete : true })
* ```
* @param url Playlist URL
* @param options Playlist Info Options
* - `boolean` incomplete : If set to true, parses playlist with hidden videos.
*
*
* @returns YouTube Playlist
*/
export async function playlist_info(url: string, options: PlaylistOptions = {}): Promise<YouTubePlayList> {

View File

@ -30,15 +30,15 @@ interface tokenOptions {
* iv> Useragents :- array of string.
*
* locally in memory.
*
* Example :
*
* Example :
* ```ts
* play.setToken({
* youtube : {
* cookie : "Your Cookies"
* }
* }) // YouTube Cookies
*
*
* play.setToken({
* useragent: ['Your User-agent']
* }) // Use this to avoid 429 errors.