From dc0e98701411f5412beca6908f96c01f0f160ac5 Mon Sep 17 00:00:00 2001 From: killer069 <65385476+killer069@users.noreply.github.com> Date: Mon, 29 Nov 2021 09:43:25 +0530 Subject: [PATCH] Fixed Playlist toJSON function --- play-dl/YouTube/classes/Playlist.ts | 4 +-- play-dl/YouTube/classes/Video.ts | 2 +- play-dl/YouTube/utils/cookie.ts | 8 +++--- play-dl/YouTube/utils/extractor.ts | 3 ++- play-dl/index.ts | 40 ++++++++++++++--------------- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/play-dl/YouTube/classes/Playlist.ts b/play-dl/YouTube/classes/Playlist.ts index da60033..1da8245 100644 --- a/play-dl/YouTube/classes/Playlist.ts +++ b/play-dl/YouTube/classes/Playlist.ts @@ -94,7 +94,7 @@ export class YouTubePlayList { this.views = data.views || 0; this.link = data.link || undefined; this.channel = data.author || undefined; - this.thumbnail = data.thumbnail || undefined; + this.thumbnail = new YouTubeThumbnail(data.thumbnail) || undefined; this.videos = data.videos || []; this.__count++; this.fetched_videos.set(`${this.__count}`, this.videos as YouTubeVideo[]); @@ -110,7 +110,7 @@ export class YouTubePlayList { this.id = data.id || undefined; this.url = this.id ? `https://www.youtube.com/playlist?list=${this.id}` : undefined; this.title = data.title || undefined; - this.thumbnail = data.thumbnail || undefined; + this.thumbnail = new YouTubeThumbnail(data.thumbnail) || undefined; this.channel = data.channel || undefined; this.videos = []; this.videoCount = data.videos || 0; diff --git a/play-dl/YouTube/classes/Video.ts b/play-dl/YouTube/classes/Video.ts index 6451af1..a845b0a 100644 --- a/play-dl/YouTube/classes/Video.ts +++ b/play-dl/YouTube/classes/Video.ts @@ -152,7 +152,7 @@ export class YouTubeVideo { this.durationInSec = (data.duration < 0 ? 0 : data.duration) || 0; this.uploadedAt = data.uploadedAt || undefined; this.views = parseInt(data.views) || 0; - this.thumbnail = data.thumbnail || {}; + this.thumbnail = new YouTubeThumbnail(data.thumbnail) || {}; this.channel = new YouTubeChannel(data.channel) || {}; this.likes = data.likes || 0; this.dislikes = data.dislikes || 0; diff --git a/play-dl/YouTube/utils/cookie.ts b/play-dl/YouTube/utils/cookie.ts index c6d8922..59c0c2f 100644 --- a/play-dl/YouTube/utils/cookie.ts +++ b/play-dl/YouTube/utils/cookie.ts @@ -49,17 +49,17 @@ export function setCookieToken(options: { cookie: string }) { /** * Updates cookies locally either in file or in memory. - * + * * Example * ```ts * const response = ... // Any https package get function. - * + * * play.cookieHeaders(response.headers['set-cookie']) - * ``` + * ``` * @param headCookie response headers['set-cookie'] array * @returns Nothing */ - export function cookieHeaders(headCookie: string[]): void { +export function cookieHeaders(headCookie: string[]): void { if (!youtubeData?.cookie) return; headCookie.forEach((x: string) => { x.split(';').forEach((z) => { diff --git a/play-dl/YouTube/utils/extractor.ts b/play-dl/YouTube/utils/extractor.ts index 0e195cb..fb588b2 100644 --- a/play-dl/YouTube/utils/extractor.ts +++ b/play-dl/YouTube/utils/extractor.ts @@ -128,7 +128,8 @@ export async function video_basic_info(url: string, options: InfoOptions = {}): cookies: true }); } - if (body.indexOf('Our systems have detected unusual traffic from your computer network.') !== -1) throw new Error('Captcha page: YouTube has detected that you are a bot!'); + if (body.indexOf('Our systems have detected unusual traffic from your computer network.') !== -1) + throw new Error('Captcha page: YouTube has detected that you are a bot!'); const player_data = body .split('var ytInitialPlayerResponse = ')?.[1] ?.split(';')[0] diff --git a/play-dl/index.ts b/play-dl/index.ts index ff44b7f..253cb44 100644 --- a/play-dl/index.ts +++ b/play-dl/index.ts @@ -88,20 +88,20 @@ import { DeezerAlbum, DeezerPlaylist, DeezerTrack } from './Deezer/classes'; /** * Creates a Stream [ YouTube or SoundCloud ] class from a url for playing. - * - * Example + * + * Example * ```ts * const source = await play.stream('youtube video URL') // YouTube Video Stream - * + * * const source = await play.stream('soundcloud track URL') // SoundCloud Track Stream - * + * * const resource = createAudioResource(source.stream, { * inputType : source.type * }) // Use discordjs voice createAudioResource function. * ``` * @param url Video / Track URL - * @param options - * + * @param options + * * - `number` quality : Quality number. [ 0 = Lowest, 1 = Medium, 2 = Highest ] * - `Proxy[]` proxy : sends data through a proxy * - `boolean` htmldata : given data is html data or not @@ -201,7 +201,7 @@ export async function search( options: { source: { youtube: 'video' } } & SearchOptions ): Promise; export async function search(query: string, options: { limit: number } & SearchOptions): Promise; -export async function search(query: string, options? : SearchOptions ): Promise; +export async function search(query: string, options?: SearchOptions): Promise; /** * Searches through a particular source and gives respective info. * @@ -247,22 +247,22 @@ export async function search( /** * Creates a Stream [ YouTube or SoundCloud ] class from video or track info for playing. - * - * Example + * + * Example * ```ts * const info = await video_info('youtube URL') * const source = await play.stream_from_info(info) // YouTube Video Stream - * + * * const soundInfo = await play.soundcloud('SoundCloud URL') * const source = await play.stream_from_info(soundInfo) // SoundCloud Track Stream - * + * * const resource = createAudioResource(source.stream, { * inputType : source.type * }) // Use discordjs voice createAudioResource function. * ``` * @param info YouTube video info OR SoundCloud track Class - * @param options - * + * @param options + * * - `number` quality : Quality number. [ 0 = Lowest, 1 = Medium, 2 = Highest ] * - `Proxy[]` proxy : sends data through a proxy * - `boolean` htmldata : given data is html data or not @@ -277,13 +277,13 @@ export async function stream_from_info( } /** * Validates url that play-dl supports. - * + * * - `so` - SoundCloud * - `sp` - Spotify * - `dz` - Deezer * - `yt` - YouTube * @param url URL - * @returns + * @returns * ```ts * 'so_playlist' / 'so_track' | 'sp_track' | 'sp_album' | 'sp_playlist' | 'dz_track' | 'dz_playlist' | 'dz_album' | 'yt_video' | 'yt_playlist' | 'search' | false * ``` @@ -322,15 +322,15 @@ export async function validate( } /** * Authorization interface for Spotify, SoundCloud and YouTube. - * + * * Either stores info in `.data` folder or shows relevant data to be used in `setToken` function. - * + * * ```ts * const play = require('play-dl') - * + * * play.authorization() * ``` - * + * * Just run the above command and you will get a interface asking some questions. */ export function authorization(): void { @@ -447,7 +447,7 @@ export function authorization(): void { } /** * Attaches paused, playing, autoPaused Listeners to discordjs voice AudioPlayer. - * + * * Useful if you don't want extra data to be downloaded by play-dl. * @param player discordjs voice AudioPlayer * @param resource A {@link YouTubeStream} or {@link SoundCloudStream}