Skip to content

Commit

Permalink
fix(Parser): Add SortFilterHeader (#563)
Browse files Browse the repository at this point in the history
* Fix for SortFilterHeader

* fix(Settings): Use `YTNode#is` to identify headers with a title

---------

Co-authored-by: LuanRT <[email protected]>
  • Loading branch information
iBicha and LuanRT authored Jan 8, 2024
1 parent abd8a82 commit 8f07e49
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/parser/classes/ItemSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ import { Parser, type RawNode } from '../index.js';
import ItemSectionHeader from './ItemSectionHeader.js';
import ItemSectionTabbedHeader from './ItemSectionTabbedHeader.js';
import CommentsHeader from './comments/CommentsHeader.js';
import SortFilterHeader from './SortFilterHeader.js';

export default class ItemSection extends YTNode {
static type = 'ItemSection';

header: CommentsHeader | ItemSectionHeader | ItemSectionTabbedHeader | null;
header: CommentsHeader | ItemSectionHeader | ItemSectionTabbedHeader | SortFilterHeader | null;
contents: ObservedArray<YTNode>;
target_id?: string;
continuation?: string;

constructor(data: RawNode) {
super();
this.header = Parser.parseItem(data.header, [ CommentsHeader, ItemSectionHeader, ItemSectionTabbedHeader ]);
this.header = Parser.parseItem(data.header, [ CommentsHeader, ItemSectionHeader, ItemSectionTabbedHeader, SortFilterHeader ]);
this.contents = Parser.parseArray(data.contents);

if (data.targetId || data.sectionIdentifier) {
Expand Down
13 changes: 13 additions & 0 deletions src/parser/classes/SortFilterHeader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { YTNode } from '../helpers.js';
import { Parser, YTNodes, type RawNode } from '../index.js';

export default class SortFilterHeader extends YTNode {
static type = 'SortFilterHeader';

filter_menu: YTNodes.SortFilterSubMenu | null;

constructor(data: RawNode) {
super();
this.filter_menu = Parser.parseItem(data.filterMenu, YTNodes.SortFilterSubMenu);
}
}
1 change: 1 addition & 0 deletions src/parser/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ export { default as SingleColumnMusicWatchNextResults } from './classes/SingleCo
export { default as SingleHeroImage } from './classes/SingleHeroImage.js';
export { default as SlimOwner } from './classes/SlimOwner.js';
export { default as SlimVideoMetadata } from './classes/SlimVideoMetadata.js';
export { default as SortFilterHeader } from './classes/SortFilterHeader.js';
export { default as SortFilterSubMenu } from './classes/SortFilterSubMenu.js';
export { default as StructuredDescriptionContent } from './classes/StructuredDescriptionContent.js';
export { default as StructuredDescriptionPlaylistLockup } from './classes/StructuredDescriptionPlaylistLockup.js';
Expand Down
6 changes: 4 additions & 2 deletions src/parser/youtube/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import SectionList from '../classes/SectionList.js';
import SettingsOptions from '../classes/SettingsOptions.js';
import SettingsSidebar from '../classes/SettingsSidebar.js';
import SettingsSwitch from '../classes/SettingsSwitch.js';
import CommentsHeader from '../classes/comments/CommentsHeader.js';
import ItemSectionHeader from '../classes/ItemSectionHeader.js';
import ItemSectionTabbedHeader from '../classes/ItemSectionTabbedHeader.js';
import Tab from '../classes/Tab.js';
import TwoColumnBrowseResults from '../classes/TwoColumnBrowseResults.js';

import type Actions from '../../core/Actions.js';
import type { ApiResponse } from '../../core/Actions.js';
import type { IBrowseResponse } from '../types/ParsedResponse.js';
Expand Down Expand Up @@ -42,7 +44,7 @@ class Settings {
this.introduction = contents?.shift()?.contents?.firstOfType(PageIntroduction);

this.sections = contents?.map((el: ItemSection) => ({
title: el.header?.title.toString() || null,
title: el.header?.is(CommentsHeader, ItemSectionHeader, ItemSectionTabbedHeader) ? el.header.title.toString() : null,
contents: el.contents
}));
}
Expand Down

0 comments on commit 8f07e49

Please sign in to comment.