refactor(Parser)!: general refactoring of parsers (#344)

* refactor: move common info into MediaInfo

* refactor: better inference on Memo

* refactor: improved typesafety in parser methods

* refactor: remove PlaylistAuthor in favor of Author

* refactor: cleanup live chat parsers

- Replace non standard author type with Author class
- Remove redundant code

* fix: new errors due to changes

* fix: pass actions to FormatUtils#toDash

* refactor!: merge NavigatableText and Text into single class
This commit is contained in:
Daniel Wykerd
2023-03-15 23:25:12 +02:00
committed by GitHub
parent 3d3436472f
commit b13bf6e992
78 changed files with 400 additions and 737 deletions

View File

@@ -1,9 +1,10 @@
import Parser from '../../index.js';
import Parser, { RawNode } from '../../index.js';
import Text from './Text.js';
import NavigationEndpoint from '../NavigationEndpoint.js';
import TextRun from './TextRun.js';
import Thumbnail from './Thumbnail.js';
import Constants from '../../../utils/Constants.js';
import Text from './Text.js';
import { observe, ObservedArray, YTNode } from '../../helpers.js';
class Author {
#nav_text;
@@ -11,23 +12,26 @@ class Author {
id: string;
name: string;
thumbnails: Thumbnail[];
endpoint?: NavigationEndpoint;
badges?: any;
endpoint: NavigationEndpoint | null;
badges: ObservedArray<YTNode>;
is_moderator?: boolean | null;
is_verified?: boolean | null;
is_verified_artist?: boolean | null;
url: string | null;
constructor(item: any, badges?: any, thumbs?: any) {
constructor(item: RawNode, badges?: any, thumbs?: any, id?: string) {
this.#nav_text = new Text(item);
this.id =
(this.#nav_text.runs?.[0] as TextRun)?.endpoint?.payload?.browseId ||
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.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;
this.badges = Array.isArray(badges) ? Parser.parseArray(badges) : [];
this.endpoint = ((this.#nav_text?.runs?.[0] as TextRun) as TextRun)?.endpoint || this.#nav_text?.endpoint || null;
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;

View File

@@ -1,12 +0,0 @@
import Author from './Author.js';
class PlaylistAuthor extends Author {
constructor(item: any, badges?: any, thumbs?: any) {
super(item, badges, thumbs);
delete this.badges;
delete this.is_verified;
delete this.is_verified_artist;
}
}
export default PlaylistAuthor;