Skip to content

Commit

Permalink
feat(parser): add MusicCardShelf (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT authored Mar 14, 2023
1 parent a8e7e64 commit 9b005d6
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 5 deletions.
48 changes: 48 additions & 0 deletions src/parser/classes/MusicCardShelf.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions src/parser/classes/MusicCardShelfHeaderBasic.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
6 changes: 6 additions & 0 deletions src/parser/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -891,6 +895,8 @@ const map: Record<string, YTNodeConstructor> = {
Movie,
MovingThumbnail,
MultiMarkersPlayerBar,
MusicCardShelf,
MusicCardShelfHeaderBasic,
MusicCarouselShelf,
MusicCarouselShelfBasicHeader,
MusicDescriptionShelf,
Expand Down
9 changes: 4 additions & 5 deletions src/parser/ytmusic/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -166,8 +167,6 @@ class Search {
}
}

export default Search;

export class SearchContinuation {
#actions: Actions;
#page: ISearchResponse;
Expand Down

0 comments on commit 9b005d6

Please sign in to comment.