From f5da982b5820a7a29eaa50dcc2d42428e639c63b Mon Sep 17 00:00:00 2001 From: killer069 <65385476+killer069@users.noreply.github.com> Date: Wed, 8 Dec 2021 09:47:26 +0530 Subject: [PATCH] Dislike count added --- play-dl/YouTube/classes/Video.ts | 12 +++++++++++- play-dl/YouTube/utils/extractor.ts | 24 +++++++++--------------- play-dl/token.ts | 6 +++--- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/play-dl/YouTube/classes/Video.ts b/play-dl/YouTube/classes/Video.ts index a845b0a..37fca4e 100644 --- a/play-dl/YouTube/classes/Video.ts +++ b/play-dl/YouTube/classes/Video.ts @@ -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 }; diff --git a/play-dl/YouTube/utils/extractor.ts b/play-dl/YouTube/utils/extractor.ts index 1d022fa..cb505fd 100644 --- a/play-dl/YouTube/utils/extractor.ts +++ b/play-dl/YouTube/utils/extractor.ts @@ -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(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 { diff --git a/play-dl/token.ts b/play-dl/token.ts index d2074a0..514bca7 100644 --- a/play-dl/token.ts +++ b/play-dl/token.ts @@ -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.