mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-30 18:06:15 +00:00
refactor: clean up parser and tests (#387)
* tests: improve coverage * refactor: clean up nodes * chore: lint * feat(parser): ignore `BrandVideoShelf` Seems to be used for ads. * feat(parser): ignore `BrandVideoSingleton` too
This commit is contained in:
@@ -1,50 +1,44 @@
|
||||
import Parser, { RawNode } from '../../index.js';
|
||||
import Text from './Text.js';
|
||||
import Constants from '../../../utils/Constants.js';
|
||||
import { YTNode, observe, type ObservedArray } from '../../helpers.js';
|
||||
import Parser, { type RawNode } from '../../index.js';
|
||||
import NavigationEndpoint from '../NavigationEndpoint.js';
|
||||
import Text from './Text.js';
|
||||
import TextRun from './TextRun.js';
|
||||
import Thumbnail from './Thumbnail.js';
|
||||
import Constants from '../../../utils/Constants.js';
|
||||
import { observe, ObservedArray, YTNode } from '../../helpers.js';
|
||||
|
||||
class Author {
|
||||
export default class Author {
|
||||
#nav_text;
|
||||
|
||||
id: string;
|
||||
name: string;
|
||||
thumbnails: Thumbnail[];
|
||||
endpoint: NavigationEndpoint | null;
|
||||
endpoint?: NavigationEndpoint;
|
||||
badges: ObservedArray<YTNode>;
|
||||
is_moderator?: boolean | null;
|
||||
is_verified?: boolean | null;
|
||||
is_verified_artist?: boolean | null;
|
||||
url: string | null;
|
||||
is_moderator?: boolean;
|
||||
is_verified?: boolean;
|
||||
is_verified_artist?: boolean;
|
||||
url: string;
|
||||
|
||||
constructor(item: RawNode, badges?: any, thumbs?: any, id?: string) {
|
||||
this.#nav_text = new Text(item);
|
||||
|
||||
this.id =
|
||||
id ||
|
||||
(this.#nav_text?.runs?.[0] as TextRun)?.endpoint?.payload?.browseId ||
|
||||
this.#nav_text?.endpoint?.payload?.browseId || 'N/A';
|
||||
|
||||
this.id = id || (this.#nav_text?.runs?.[0] as TextRun)?.endpoint?.payload?.browseId || this.#nav_text?.endpoint?.payload?.browseId || 'N/A';
|
||||
this.name = this.#nav_text?.text || 'N/A';
|
||||
this.thumbnails = thumbs ? Thumbnail.fromResponse(thumbs) : [];
|
||||
this.endpoint = ((this.#nav_text?.runs?.[0] as TextRun) as TextRun)?.endpoint || this.#nav_text?.endpoint || null;
|
||||
this.endpoint = ((this.#nav_text?.runs?.[0] as TextRun) as TextRun)?.endpoint || this.#nav_text?.endpoint;
|
||||
this.badges = Array.isArray(badges) ? Parser.parseArray(badges) : observe([] as YTNode[]);
|
||||
this.is_moderator = this.badges?.some((badge: any) => badge.icon_type == 'MODERATOR') || null;
|
||||
this.is_verified = this.badges?.some((badge: any) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED') || null;
|
||||
this.is_verified_artist = this.badges?.some((badge: any) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED_ARTIST') || null;
|
||||
this.is_moderator = this.badges?.some((badge: any) => badge.icon_type == 'MODERATOR');
|
||||
this.is_verified = this.badges?.some((badge: any) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED');
|
||||
this.is_verified_artist = this.badges?.some((badge: any) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED_ARTIST');
|
||||
|
||||
// @TODO: Refactor this mess.
|
||||
this.url =
|
||||
(this.#nav_text?.runs?.[0] as TextRun)?.endpoint?.metadata?.api_url === '/browse' &&
|
||||
`${Constants.URLS.YT_BASE}${(this.#nav_text?.runs?.[0] as TextRun)?.endpoint?.payload?.canonicalBaseUrl || `/u/${(this.#nav_text?.runs?.[0] as TextRun)?.endpoint?.payload?.browseId}`}` ||
|
||||
`${Constants.URLS.YT_BASE}${this.#nav_text?.endpoint?.payload?.canonicalBaseUrl || `/u/${this.#nav_text?.endpoint?.payload?.browseId}`}` ||
|
||||
null;
|
||||
`${Constants.URLS.YT_BASE}${this.#nav_text?.endpoint?.payload?.canonicalBaseUrl || `/u/${this.#nav_text?.endpoint?.payload?.browseId}`}`;
|
||||
}
|
||||
|
||||
get best_thumbnail(): Thumbnail | undefined {
|
||||
return this.thumbnails[0];
|
||||
}
|
||||
}
|
||||
|
||||
export default Author;
|
||||
}
|
||||
Reference in New Issue
Block a user