Files
YouTube.js/src/parser/classes/C4TabbedHeader.ts
LuanRT 257bd475a0 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
2023-04-23 06:37:33 -03:00

72 lines
2.1 KiB
TypeScript

import { YTNode } from '../helpers.js';
import Parser, { type RawNode } from '../index.js';
import Button from './Button.js';
import ChannelHeaderLinks from './ChannelHeaderLinks.js';
import SubscribeButton from './SubscribeButton.js';
import Author from './misc/Author.js';
import Text from './misc/Text.js';
import Thumbnail from './misc/Thumbnail.js';
export default class C4TabbedHeader extends YTNode {
static type = 'C4TabbedHeader';
author: Author;
banner?: Thumbnail[];
tv_banner?: Thumbnail[];
mobile_banner?: Thumbnail[];
subscribers?: Text;
videos_count?: Text;
sponsor_button?: Button | null;
subscribe_button?: SubscribeButton | Button | null;
header_links?: ChannelHeaderLinks | null;
channel_handle?: Text;
channel_id?: string;
constructor(data: RawNode) {
super();
this.author = new Author({
simpleText: data.title,
navigationEndpoint: data.navigationEndpoint
}, data.badges, data.avatar);
if (Reflect.has(data, 'banner')) {
this.banner = Thumbnail.fromResponse(data.banner);
}
if (Reflect.has(data, 'tv_banner')) {
this.tv_banner = Thumbnail.fromResponse(data.tvBanner);
}
if (Reflect.has(data, 'mobile_banner')) {
this.mobile_banner = Thumbnail.fromResponse(data.mobileBanner);
}
if (Reflect.has(data, 'subscriberCountText')) {
this.subscribers = new Text(data.subscriberCountText);
}
if (Reflect.has(data, 'videosCountText')) {
this.videos_count = new Text(data.videosCountText);
}
if (Reflect.has(data, 'sponsorButton')) {
this.sponsor_button = Parser.parseItem(data.sponsorButton, Button);
}
if (Reflect.has(data, 'subscribeButton')) {
this.subscribe_button = Parser.parseItem(data.subscribeButton, [ SubscribeButton, Button ]);
}
if (Reflect.has(data, 'headerLinks')) {
this.header_links = Parser.parseItem(data.headerLinks, ChannelHeaderLinks);
}
if (Reflect.has(data, 'channelHandleText')) {
this.channel_handle = new Text(data.channelHandleText);
}
if (Reflect.has(data, 'channelId')) {
this.channel_id = data.channelId;
}
}
}