diff --git a/lib/parser/youtube/VideoInfo.js b/lib/parser/youtube/VideoInfo.js index f6da1d23..7a579eb8 100644 --- a/lib/parser/youtube/VideoInfo.js +++ b/lib/parser/youtube/VideoInfo.js @@ -1,7 +1,7 @@ 'use strict'; const Parser = require('../contents'); -const { InnertubeError } = require('../../utils/Utils'); +const { InnertubeError, observe } = require('../../utils/Utils'); /** namespace **/ class VideoInfo { @@ -116,15 +116,31 @@ class VideoInfo { this.comments_entry_point_header = comments_entry_point?.contents.get({ type: 'commentsEntryPointHeaderRenderer' }) || {}; } - async selectFilter(chip) { - const response = await chip.endpoint.call(this.#actions); - + /** + * Applies given filter to the watch next feed. + * @param {string} filter + * @returns {Promise.} + */ + async selectFilter(name) { + if (!this.filters.includes(name)) + throw new InnertubeError('Invalid filter', { available_filters: this.filters }); + + const filter = this.related_chip_cloud.chips.get({ text: name }); + if (filter.is_selected) return this; + + const response = await filter.endpoint.call(this.#actions); const data = response.on_response_received_endpoints.get({ target_id: 'watch-next-feed' }); + this.watch_next_feed = data.continuation_items; - + return this; } + /** @type {string} */ + get filters() { + return this.related_chip_cloud.chips.map((chip) => chip.text); + } + get page() { return this.#page; }