Fixed Playlist toJSON function

This commit is contained in:
killer069 2021-11-29 09:43:25 +05:30
parent 83d7810eae
commit dc0e987014
5 changed files with 29 additions and 28 deletions

View File

@ -94,7 +94,7 @@ export class YouTubePlayList {
this.views = data.views || 0; this.views = data.views || 0;
this.link = data.link || undefined; this.link = data.link || undefined;
this.channel = data.author || undefined; this.channel = data.author || undefined;
this.thumbnail = data.thumbnail || undefined; this.thumbnail = new YouTubeThumbnail(data.thumbnail) || undefined;
this.videos = data.videos || []; this.videos = data.videos || [];
this.__count++; this.__count++;
this.fetched_videos.set(`${this.__count}`, this.videos as YouTubeVideo[]); this.fetched_videos.set(`${this.__count}`, this.videos as YouTubeVideo[]);
@ -110,7 +110,7 @@ export class YouTubePlayList {
this.id = data.id || undefined; this.id = data.id || undefined;
this.url = this.id ? `https://www.youtube.com/playlist?list=${this.id}` : undefined; this.url = this.id ? `https://www.youtube.com/playlist?list=${this.id}` : undefined;
this.title = data.title || undefined; this.title = data.title || undefined;
this.thumbnail = data.thumbnail || undefined; this.thumbnail = new YouTubeThumbnail(data.thumbnail) || undefined;
this.channel = data.channel || undefined; this.channel = data.channel || undefined;
this.videos = []; this.videos = [];
this.videoCount = data.videos || 0; this.videoCount = data.videos || 0;

View File

@ -152,7 +152,7 @@ export class YouTubeVideo {
this.durationInSec = (data.duration < 0 ? 0 : data.duration) || 0; this.durationInSec = (data.duration < 0 ? 0 : data.duration) || 0;
this.uploadedAt = data.uploadedAt || undefined; this.uploadedAt = data.uploadedAt || undefined;
this.views = parseInt(data.views) || 0; this.views = parseInt(data.views) || 0;
this.thumbnail = 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.dislikes = data.dislikes || 0;

View File

@ -59,7 +59,7 @@ export function setCookieToken(options: { cookie: string }) {
* @param headCookie response headers['set-cookie'] array * @param headCookie response headers['set-cookie'] array
* @returns Nothing * @returns Nothing
*/ */
export function cookieHeaders(headCookie: string[]): void { export function cookieHeaders(headCookie: string[]): void {
if (!youtubeData?.cookie) return; if (!youtubeData?.cookie) return;
headCookie.forEach((x: string) => { headCookie.forEach((x: string) => {
x.split(';').forEach((z) => { x.split(';').forEach((z) => {

View File

@ -128,7 +128,8 @@ export async function video_basic_info(url: string, options: InfoOptions = {}):
cookies: true 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 const player_data = body
.split('var ytInitialPlayerResponse = ')?.[1] .split('var ytInitialPlayerResponse = ')?.[1]
?.split(';</script>')[0] ?.split(';</script>')[0]

View File

@ -201,7 +201,7 @@ export async function search(
options: { source: { youtube: 'video' } } & SearchOptions options: { source: { youtube: 'video' } } & SearchOptions
): Promise<YouTubeVideo[]>; ): Promise<YouTubeVideo[]>;
export async function search(query: string, options: { limit: number } & SearchOptions): Promise<YouTubeVideo[]>; export async function search(query: string, options: { limit: number } & SearchOptions): Promise<YouTubeVideo[]>;
export async function search(query: string, options? : SearchOptions ): Promise<YouTubeVideo[]>; export async function search(query: string, options?: SearchOptions): Promise<YouTubeVideo[]>;
/** /**
* Searches through a particular source and gives respective info. * Searches through a particular source and gives respective info.
* *