Closed ajoykarmakar459 closed 3 years ago
The correct method name supposed to be .nextVideos()
and .nextPlaylists()
https://youtubei.netlify.app/docs/api/classes/channel#methods
Can I get the all videos from a channel?
Yes, you just need to pass 0
on the param
const channelVideos = await video.channel.getVideos(0);
Keep in mind that the library can only fetch 30 videos at a time (due to limitation from Youtube). So if the channel has 200 videos, fetching all of them means that the lib will send 7 requests one at a time, so it might take a while.
But this isn't working am I missing some important step?
My bad, I copy pasted your code 😂 it's supposed to be nextVideos
, not getVideos
const channelVideos = await video.channel.nextVideos(0);
Ok, great man! One question is, It will be safe to use this library to run in the production app? I mean can we expect the library update from time to time?
I will keep maintaining the library as long as Youtube doesn't keep making breaking changes on the API, but that most likely won't happen anytime soon.
I wouldn't recommend using it on production app, especially if your app sends lots of requests to Youtube, mostly because it's not 100% reliable (because the library isn't using the official Youtube API) and AFAIK it's violates Youtube's TOS, but they most likely won't care if your usage is "low".
Since your problem is solved, I will close this issue now.
So If I get high volume traffic in this library what will happen and how the thing can be sorted, Any Idea?
Haven't really used the library on a high traffic app, you might get IP banned from Youtube (never happens to me before). I don't think there are any solution to this except to just use the Youtube's Official API
Ok, thank you for the feedback.
Is it possible to get the nextVideos in a paginated way?
Yes, please consult the docs: https://youtubei.netlify.app/docs/api/classes/channel/#nextvideos
let videos = await video.channel.nextVideos();
console.log(videos); // 1st page
videos = await video.channel.nextVideos();
console.log(videos); // 2nd page
videos = await video.channel.nextVideos();
console.log(videos); // 3rd page
console.log(video.channel.videos) // videos from 1st to 3rd page
Yes, I followed the docs but it's should not hold any keys or paginate numbers so If I make the API then it always shows the first few videos. Am I able to clear the problem that is situated?
If it's a future plan to do that then it will be a good option if we can fetch with paginate numbers and the number of videos. Ex -
videos = await video.channel.nextVideos(paginate numbers: 1, number of videos: 20);
Ah I see what you mean, unfortunately due to limitation from Youtube, you can only paginate sequentially from 1st page, to 2nd page, and 3rd, and so on, just like you would on https://youtube.com. You can't skip to n-th page.
Exposing the pagination key seems like a good idea so you can pass the key to, lets say, client, and have them pass it back to your server so you know which page to fetch, something like:
const videos = await video.channel.nextVideos();
const paginationKey = video.channel.videoPaginationKey;
res.send({
videos,
paginationKey
});
// later when server receives the request
const paginationKey = req.query.key; // sent from client
const videos = await video.channel.nextVideos(paginationKey)
// ...
Feature will be tracked here
Yes, that I am talking about. You said that now we can only paginate sequentially from 1st page to 2nd page, and 3rd, and so on - so can you please share how can we do that?
I've already shown you on the previous comment, you just need to call .nextVideos()
multiple times
const videoOnFirstPage = await video.channel.nextVideos();
const videosOnSecondPage = await video.channel.nextVideos();
const videosOnThirdPage = await video.channel.nextVideos();
Ah Ok.. I thought there was any other function to get the list. Thank you for the reponse. Best wishes to you and your library.
Nope, it's only .nextVideos()
, alternatively you can pass number
as the first parameter telling how many pages to fetch, for example;
const videos = await video.channel.nextVideos(7);
videos
now will contain channel's videos from page 1,2,3... through 7.
or as I mentioned before, you can pass 0
to get all videos on the channel
My bad, I copy pasted your code 😂 it's supposed to be
nextVideos
, notgetVideos
const channelVideos = await video.channel.nextVideos(0);
If the channel is having more than 1000 videos, it will create a timeout error
If the channel is having more than 1000 videos, it will create a timeout error
@musso appreciate you reporting bugs, but please create a new issue next time for better tracking.
About the timeout error, it's most likely caused by an unstable connection. I successfully fetched all videos from Linus Tech Tips channel (ID: UCXuqSBlHAE6Xw-yeJA0Tunw
), which has 5796 videos (at the time I write this comment), it took me 46.3 seconds (it sent 194 requests sequentially, each fetch get 30 videos)
These two functions are not working.
Attached screenshot -