Files
YouTube.js/src/parser/classes/ChannelHeaderLinks.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

34 lines
1.1 KiB
TypeScript

import { YTNode, observe, type ObservedArray } from '../helpers.js';
import type { RawNode } from '../index.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import Text from './misc/Text.js';
import Thumbnail from './misc/Thumbnail.js';
// XXX (LuanRT): This is not a real YTNode, but we treat it as one to keep things clean.
export class HeaderLink extends YTNode {
static type = 'HeaderLink';
endpoint: NavigationEndpoint;
icon: Thumbnail[];
title: Text;
constructor(data: RawNode) {
super();
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
this.icon = Thumbnail.fromResponse(data.icon);
this.title = new Text(data.title);
}
}
export default class ChannelHeaderLinks extends YTNode {
static type = 'ChannelHeaderLinks';
primary: ObservedArray<HeaderLink>;
secondary: ObservedArray<HeaderLink>;
constructor(data: RawNode) {
super();
this.primary = observe(data.primaryLinks?.map((link: RawNode) => new HeaderLink(link)) || []);
this.secondary = observe(data.secondaryLinks?.map((link: RawNode) => new HeaderLink(link)) || []);
}
}