mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-23 23:09:28 +00:00
feat: add support for searching within a channel (#262)
* feat(Channel): add support for searching * dev: add channel search test * chore: update docs
This commit is contained in:
@@ -15,7 +15,7 @@ class ExpandableTab extends YTNode {
|
||||
this.title = data.title;
|
||||
this.endpoint = new NavigationEndpoint(data.endpoint);
|
||||
this.selected = data.selected; // If this.selected then we may have content else we do not
|
||||
this.content = data.content ? Parser.parse(data.content) : null;
|
||||
this.content = data.content ? Parser.parseItem(data.content) : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import FilterableFeed from '../../core/FilterableFeed';
|
||||
import Feed from '../../core/Feed';
|
||||
|
||||
import { InnertubeError } from '../../utils/Utils';
|
||||
import ExpandableTab from '../classes/ExpandableTab';
|
||||
|
||||
export default class Channel extends TabbedFeed {
|
||||
header;
|
||||
@@ -37,9 +38,7 @@ export default class Channel extends TabbedFeed {
|
||||
|
||||
this.subscribe_button = this.page.header_memo.getType(SubscribeButton)?.[0];
|
||||
|
||||
const tab = this.page.contents.item().key('tabs').parsed().array().filterType(Tab).get({ selected: true });
|
||||
|
||||
this.current_tab = tab;
|
||||
this.current_tab = this.page.contents.item().key('tabs').parsed().array().filterType(Tab, ExpandableTab).get({ selected: true });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,6 +113,20 @@ export default class Channel extends TabbedFeed {
|
||||
return tab.memo.getType(ChannelAboutFullMetadata)?.[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches within the channel.
|
||||
*/
|
||||
async search(query: string) {
|
||||
const tab = this.memo.getType(ExpandableTab)?.[0];
|
||||
|
||||
if (!tab)
|
||||
throw new InnertubeError('Search tab not found', this);
|
||||
|
||||
const page = await tab.endpoint?.call(this.actions, { query, parse: true });
|
||||
|
||||
return new Channel(this.actions, page, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrives list continuation.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user