mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-25 07:42:11 +00:00
feat: add MusicSortFilterButton (#151)
This commit is contained in:
@@ -19,7 +19,7 @@ class MusicDetailHeader extends YTNode {
|
||||
badges;
|
||||
author?: {
|
||||
name: string;
|
||||
channel_id: string;
|
||||
channel_id: string | undefined;
|
||||
endpoint: NavigationEndpoint | undefined;
|
||||
};
|
||||
menu;
|
||||
|
||||
@@ -13,6 +13,7 @@ class MusicShelf extends YTNode {
|
||||
endpoint: NavigationEndpoint | null;
|
||||
continuation: string | null;
|
||||
bottom_text: Text | null;
|
||||
subheaders?: Array<any>;
|
||||
|
||||
constructor(data: any) {
|
||||
super();
|
||||
@@ -24,6 +25,9 @@ class MusicShelf extends YTNode {
|
||||
data.continuations?.[0].nextContinuationData?.continuation ||
|
||||
data.continuations?.[0].reloadContinuationData?.continuation || null;
|
||||
this.bottom_text = Reflect.has(data, 'bottomText') ? new Text(data.bottomText) : null;
|
||||
if (data.subheaders) {
|
||||
this.subheaders = Parser.parseArray(data.subheaders);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
19
src/parser/classes/MusicSideAlignedItem.ts
Normal file
19
src/parser/classes/MusicSideAlignedItem.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import Parser from '../index';
|
||||
|
||||
import { YTNode } from '../helpers';
|
||||
|
||||
class MusicSideAlignedItem extends YTNode {
|
||||
static type = 'MusicSideAlignedItem';
|
||||
|
||||
start_items?;
|
||||
|
||||
constructor(data: any) {
|
||||
super();
|
||||
|
||||
if (data.startItems) {
|
||||
this.start_items = Parser.parseArray(data.startItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default MusicSideAlignedItem;
|
||||
23
src/parser/classes/MusicSortFilterButton.ts
Normal file
23
src/parser/classes/MusicSortFilterButton.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import Parser from '../index';
|
||||
|
||||
import { YTNode } from '../helpers';
|
||||
import MusicMultiSelectMenu from './menus/MusicMultiSelectMenu';
|
||||
import Text from './misc/Text';
|
||||
|
||||
class MusicSortFilterButton extends YTNode {
|
||||
static type = 'MusicSortFilterButton';
|
||||
|
||||
title: string;
|
||||
icon_type: string;
|
||||
menu: MusicMultiSelectMenu | null;
|
||||
|
||||
constructor(data: any) {
|
||||
super();
|
||||
|
||||
this.title = new Text(data.title).text;
|
||||
this.icon_type = data.icon?.icon_type || null;
|
||||
this.menu = Parser.parseItem(data.menu, MusicMultiSelectMenu);
|
||||
}
|
||||
}
|
||||
|
||||
export default MusicSortFilterButton;
|
||||
@@ -25,13 +25,13 @@ class MusicTwoRowItem extends YTNode {
|
||||
|
||||
artists?: {
|
||||
name: string;
|
||||
channel_id: string;
|
||||
channel_id: string | undefined;
|
||||
endpoint: NavigationEndpoint | undefined;
|
||||
}[];
|
||||
|
||||
author?: {
|
||||
name: string;
|
||||
channel_id: string;
|
||||
channel_id: string | undefined;
|
||||
endpoint: NavigationEndpoint | undefined;
|
||||
};
|
||||
|
||||
|
||||
@@ -18,7 +18,13 @@ class NavigationEndpoint extends YTNode {
|
||||
};
|
||||
|
||||
// TODO: these should be given proper types, currently infered
|
||||
browse;
|
||||
browse?: {
|
||||
id: string,
|
||||
params: string | null,
|
||||
base_url: string | null,
|
||||
page_type: string | null,
|
||||
form_data?: {}
|
||||
};
|
||||
watch;
|
||||
search;
|
||||
subscribe;
|
||||
|
||||
12
src/parser/classes/menus/MusicMenuItemDivider.ts
Normal file
12
src/parser/classes/menus/MusicMenuItemDivider.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { YTNode } from '../../helpers';
|
||||
|
||||
class MusicMenuItemDivider extends YTNode {
|
||||
static type = 'MusicMenuItemDivider';
|
||||
|
||||
// eslint-disable-next-line
|
||||
constructor(data: any) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
export default MusicMenuItemDivider;
|
||||
21
src/parser/classes/menus/MusicMultiSelectMenu.ts
Normal file
21
src/parser/classes/menus/MusicMultiSelectMenu.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import MusicMultiSelectMenuItem from './MusicMultiSelectMenuItem';
|
||||
import MusicMenuItemDivider from './MusicMenuItemDivider';
|
||||
import { YTNode } from '../../helpers';
|
||||
import Text from '../misc/Text';
|
||||
import Parser from '../..';
|
||||
|
||||
class MusicMultiSelectMenu extends YTNode {
|
||||
static type = 'MusicMultiSelectMenu';
|
||||
|
||||
title: string;
|
||||
options: Array<MusicMultiSelectMenuItem | MusicMenuItemDivider>;
|
||||
|
||||
constructor(data: any) {
|
||||
super();
|
||||
|
||||
this.title = new Text(data.title.musicMenuTitleRenderer?.primaryText).text;
|
||||
this.options = Parser.parseArray(data.options, [ MusicMultiSelectMenuItem, MusicMenuItemDivider ]);
|
||||
}
|
||||
}
|
||||
|
||||
export default MusicMultiSelectMenu;
|
||||
37
src/parser/classes/menus/MusicMultiSelectMenuItem.ts
Normal file
37
src/parser/classes/menus/MusicMultiSelectMenuItem.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { YTNode } from '../../helpers';
|
||||
import Text from '../misc/Text';
|
||||
import NavigationEndpoint from '../NavigationEndpoint';
|
||||
|
||||
class MusicMultiSelectMenuItem extends YTNode {
|
||||
static type = 'MusicMultiSelectMenuItem';
|
||||
|
||||
title: string;
|
||||
form_item_entity_key: string;
|
||||
selected_icon_type: string;
|
||||
endpoint?: NavigationEndpoint;
|
||||
selected: boolean;
|
||||
|
||||
constructor(data: any) {
|
||||
super();
|
||||
|
||||
this.title = new Text(data.title).text;
|
||||
this.form_item_entity_key = data.formItemEntityKey;
|
||||
this.selected_icon_type = data.selectedIcon?.iconType || null;
|
||||
const command = data.selectedCommand?.commandExecutorCommand?.commands?.find((command: any) => command.musicBrowseFormBinderCommand?.browseEndpoint);
|
||||
if (command) {
|
||||
/**
|
||||
* At this point, endpoint will still be missing `form_data` field which is required for
|
||||
* selection to take effect. This can only be obtained from the response data which
|
||||
* we don't have here. We shall delegate this task back to `Parser`.
|
||||
*/
|
||||
this.endpoint = new NavigationEndpoint(command.musicBrowseFormBinderCommand);
|
||||
}
|
||||
/**
|
||||
* Inferring selected state from existence of endpoint. `Parser` shall
|
||||
* update this with the definitive value obtained from response data.
|
||||
*/
|
||||
this.selected = !!this.endpoint;
|
||||
}
|
||||
}
|
||||
|
||||
export default MusicMultiSelectMenuItem;
|
||||
Reference in New Issue
Block a user