mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-19 04:21:35 +00:00
feat(parser): add MusicCardShelf (#358)
This commit is contained in:
48
src/parser/classes/MusicCardShelf.ts
Normal file
48
src/parser/classes/MusicCardShelf.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { ObservedArray, YTNode } from '../helpers.js';
|
||||
import Parser, { RawNode } from '../index.js';
|
||||
import Button from './Button.js';
|
||||
import Menu from './menus/Menu.js';
|
||||
import Text from './misc/Text.js';
|
||||
import MusicCardShelfHeaderBasic from './MusicCardShelfHeaderBasic.js';
|
||||
import MusicInlineBadge from './MusicInlineBadge.js';
|
||||
import MusicItemThumbnailOverlay from './MusicItemThumbnailOverlay.js';
|
||||
import MusicThumbnail from './MusicThumbnail.js';
|
||||
import NavigationEndpoint from './NavigationEndpoint.js';
|
||||
|
||||
export default class MusicCardShelf extends YTNode {
|
||||
static type = 'MusicCardShelf';
|
||||
|
||||
thumbnail: MusicThumbnail | null;
|
||||
title: Text;
|
||||
subtitle: Text;
|
||||
buttons: ObservedArray<Button> | null;
|
||||
menu: Menu | null;
|
||||
on_tap: NavigationEndpoint;
|
||||
header: MusicCardShelfHeaderBasic | null;
|
||||
end_icon_type?: string;
|
||||
subtitle_badges: ObservedArray<MusicInlineBadge>;
|
||||
thumbnail_overlay: MusicItemThumbnailOverlay | null;
|
||||
contents?: ObservedArray<YTNode> | null;
|
||||
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
this.thumbnail = Parser.parseItem(data.thumbnail, MusicThumbnail);
|
||||
this.title = new Text(data.title);
|
||||
this.subtitle = new Text(data.subtitle);
|
||||
this.buttons = Parser.parseArray(data.buttons, Button);
|
||||
this.menu = Parser.parseItem(data.menu, Menu);
|
||||
this.on_tap = new NavigationEndpoint(data.onTap);
|
||||
this.header = Parser.parseItem(data.header, MusicCardShelfHeaderBasic);
|
||||
|
||||
if (Reflect.has(data, 'endIcon') && Reflect.has(data.endIcon, 'iconType')) {
|
||||
this.end_icon_type = data.endIcon.iconType;
|
||||
}
|
||||
|
||||
this.subtitle_badges = Parser.parseArray(data.subtitleBadges, MusicInlineBadge);
|
||||
this.thumbnail_overlay = Parser.parseItem(data.thumbnailOverlay, MusicItemThumbnailOverlay);
|
||||
|
||||
if (Reflect.has(data, 'contents')) {
|
||||
this.contents = Parser.parseArray(data.contents);
|
||||
}
|
||||
}
|
||||
}
|
||||
14
src/parser/classes/MusicCardShelfHeaderBasic.ts
Normal file
14
src/parser/classes/MusicCardShelfHeaderBasic.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { YTNode } from '../helpers.js';
|
||||
import { RawNode } from '../index.js';
|
||||
import Text from './misc/Text.js';
|
||||
|
||||
export default class MusicCardShelfHeaderBasic extends YTNode {
|
||||
static type = 'MusicCardShelfHeaderBasic';
|
||||
|
||||
title: Text;
|
||||
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
this.title = new Text(data.title);
|
||||
}
|
||||
}
|
||||
@@ -398,6 +398,10 @@ import { default as MovingThumbnail } from './classes/MovingThumbnail.js';
|
||||
export { MovingThumbnail };
|
||||
import { default as MultiMarkersPlayerBar } from './classes/MultiMarkersPlayerBar.js';
|
||||
export { MultiMarkersPlayerBar };
|
||||
import { default as MusicCardShelf } from './classes/MusicCardShelf.js';
|
||||
export { MusicCardShelf };
|
||||
import { default as MusicCardShelfHeaderBasic } from './classes/MusicCardShelfHeaderBasic.js';
|
||||
export { MusicCardShelfHeaderBasic };
|
||||
import { default as MusicCarouselShelf } from './classes/MusicCarouselShelf.js';
|
||||
export { MusicCarouselShelf };
|
||||
import { default as MusicCarouselShelfBasicHeader } from './classes/MusicCarouselShelfBasicHeader.js';
|
||||
@@ -891,6 +895,8 @@ const map: Record<string, YTNodeConstructor> = {
|
||||
Movie,
|
||||
MovingThumbnail,
|
||||
MultiMarkersPlayerBar,
|
||||
MusicCardShelf,
|
||||
MusicCardShelfHeaderBasic,
|
||||
MusicCarouselShelf,
|
||||
MusicCarouselShelfBasicHeader,
|
||||
MusicDescriptionShelf,
|
||||
|
||||
@@ -7,6 +7,7 @@ import ChipCloudChip from '../classes/ChipCloudChip.js';
|
||||
import DidYouMean from '../classes/DidYouMean.js';
|
||||
import ItemSection from '../classes/ItemSection.js';
|
||||
import Message from '../classes/Message.js';
|
||||
import MusicCardShelf from '../classes/MusicCardShelf.js';
|
||||
import MusicHeader from '../classes/MusicHeader.js';
|
||||
import MusicResponsiveListItem from '../classes/MusicResponsiveListItem.js';
|
||||
import MusicShelf from '../classes/MusicShelf.js';
|
||||
@@ -18,13 +19,13 @@ import type { ObservedArray } from '../helpers.js';
|
||||
import type { ISearchResponse } from '../types/ParsedResponse.js';
|
||||
import type { ApiResponse } from '../../core/Actions.js';
|
||||
|
||||
class Search {
|
||||
export default class Search {
|
||||
#page: ISearchResponse;
|
||||
#actions: Actions;
|
||||
#continuation?: string;
|
||||
|
||||
header?: ChipCloud;
|
||||
contents?: ObservedArray<MusicShelf | ItemSection>;
|
||||
contents?: ObservedArray<MusicShelf | MusicCardShelf | ItemSection>;
|
||||
|
||||
constructor(response: ApiResponse, actions: Actions, is_filtered?: boolean) {
|
||||
this.#actions = actions;
|
||||
@@ -44,7 +45,7 @@ class Search {
|
||||
throw new InnertubeError('Target tab did not have any content.');
|
||||
|
||||
this.header = tab_content.header?.item().as(ChipCloud);
|
||||
this.contents = tab_content.contents.as(MusicShelf, ItemSection);
|
||||
this.contents = tab_content.contents.as(MusicShelf, MusicCardShelf, ItemSection);
|
||||
|
||||
if (is_filtered) {
|
||||
this.#continuation = this.contents.firstOfType(MusicShelf)?.continuation;
|
||||
@@ -166,8 +167,6 @@ class Search {
|
||||
}
|
||||
}
|
||||
|
||||
export default Search;
|
||||
|
||||
export class SearchContinuation {
|
||||
#actions: Actions;
|
||||
#page: ISearchResponse;
|
||||
|
||||
Reference in New Issue
Block a user