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,26 +1,16 @@
import { observe, ObservedArray, YTNode } from '../../../helpers.js';
import Parser from '../../../index.js';
import LiveChatAuthorBadge from '../../LiveChatAuthorBadge.js';
import MetadataBadge from '../../MetadataBadge.js';
import { YTNode } from '../../../helpers.js';
import Text from '../../misc/Text.js';
import Thumbnail from '../../misc/Thumbnail.js';
import NavigationEndpoint from '../../NavigationEndpoint.js';
import type { RawNode } from '../../../index.js';
import Author from '../../misc/Author.js';
class LiveChatPaidSticker extends YTNode {
static type = 'LiveChatPaidSticker';
id: string;
author: {
id: string;
name: Text;
thumbnails: Thumbnail[];
badges: ObservedArray<LiveChatAuthorBadge | MetadataBadge>;
is_moderator: boolean | null;
is_verified: boolean | null;
is_verified_artist: boolean | null;
};
author: Author;
money_chip_background_color: number;
money_chip_text_color: number;
@@ -36,22 +26,7 @@ class LiveChatPaidSticker extends YTNode {
super();
this.id = data.id;
this.author = {
id: data.authorExternalChannelId,
name: new Text(data.authorName),
thumbnails: Thumbnail.fromResponse(data.authorPhoto),
badges: observe([]).as(LiveChatAuthorBadge, MetadataBadge),
is_moderator: null,
is_verified: null,
is_verified_artist: null
};
const badges = Parser.parseArray<LiveChatAuthorBadge | MetadataBadge>(data.authorBadges, [ MetadataBadge, LiveChatAuthorBadge ]);
this.author.badges = badges;
this.author.is_moderator = badges ? badges.some((badge) => badge.icon_type == 'MODERATOR') : null;
this.author.is_verified = badges ? badges.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED') : null;
this.author.is_verified_artist = badges ? badges.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED_ARTIST') : null;
this.author = new Author(data.authorName, data.authorBadges, data.authorPhoto, data.authorExternalChannelId);
this.money_chip_background_color = data.moneyChipBackgroundColor;
this.money_chip_text_color = data.moneyChipTextColor;