Request specific continuation #385
-
Is there a way, after using "getContinuationData" to add that to request? To just requeset data of specific continuation? Instead of spamming getContinuation? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 2 replies
-
Most definitely yes but I think I need more context here. When you say “after using "getContinuationData" to add that to request”, do you mean getting the next continuation node from the response of that method and then retrieving its data instead of using If you can, please feel free to provide code/pseudocode that demonstrates what you mean. |
Beta Was this translation helpful? Give feedback.
-
Previously i was using yt-comment-scraper for example and here's simple code
i was printing the result and handling that in my app, then i could just get the continuation data, pass it to the next execution and it would fetch that exact continuation. Usage example: |
Beta Was this translation helpful? Give feedback.
-
Ah, got it! Thanks for clarifying. Please correct me if I'm wrong here:
I think you should be able to do that with the import { Innertube, UniversalCache, YTNodes } from 'youtubei.js';
(async () => {
const yt = await Innertube.create({ cache: new UniversalCache(false), generate_session_locally: true });
const search = await yt.search('Mac Miller right');
const comments = await yt.getComments(search.videos[0].id);
// Get the continuation node from the first response. This contains the token and other parameters needed to get the next page.
const continuation_node = comments.page.on_response_received_endpoints.at(1).contents.firstOfType(YTNodes.ContinuationItem);
/**
* The Actions#execute(endpoint, args?) method takes an endpoint and payload and then proceeds to make the request.
* I recommend that you save the entire continuation node in your app so you don't have to manually
* create the payload and find the correct api url. In case your app can only save the token, you
* may use the "/next" endpoint and pass the token as "continuation" or "token" in the args.
*
* See the example below. Which uses the metadata and endpoint from the continuation node
* to make the request with all the parameters needed.
*
* Note that the "parse" argument is set to true. This means that the response will be parsed by the library.
*/
const response = await yt.actions.execute(continuation_node.endpoint.metadata.api_url, {
...continuation_node.endpoint.payload,
parse: true
});
// Unwrap the response. Incremental continuation data is almost always inside special properties like this.
const contents = response.on_response_received_endpoints.first().contents;
// Print the response.
console.log(contents);
// Print the next continuation node (in case you can't/don't want to utilize the utility methods, the continuation is always at the bottom of the list):
console.log(contents.firstOfType(YTNodes.ContinuationItem));
})(); The same concept can be applied to the many other feeds YouTube provides. |
Beta Was this translation helpful? Give feedback.
-
By your description it's exactly what i needed but let me test the code and get back to you! Thank a ton for help! |
Beta Was this translation helpful? Give feedback.
-
@LuanRT I was trying to apply your example to channel videos but i have some trouble. on_response_received_endpoints doesn't seem to exist in videos page
continuationData is undefined |
Beta Was this translation helpful? Give feedback.
-
I think i got it, exactly what i wanted
I think I now can apply same logic to other things as well. Thanks a ton for help! |
Beta Was this translation helpful? Give feedback.
Ah, got it! Thanks for clarifying.
Please correct me if I'm wrong here:
I think you should be able to do that with the
Actions#execute
method. Here's a small example for comments: