SuspiciousLookingOwl / youtubei

Get Youtube data such as videos, playlists, channels, video information & comments, related videos, up next video, and more!
https://suspiciouslookingowl.github.io/youtubei
MIT License
240 stars 50 forks source link

[BUG] Unresolved function or method #23

Closed ajoykarmakar459 closed 3 years ago

ajoykarmakar459 commented 3 years ago

These two functions are not working.

  const channelVideos = await video.channel.getVideos();
  const channelPlaylists = await video.channel.getPlaylists();

Attached screenshot -

Screenshot 2021-08-30 at 12 38 50 PM
SuspiciousLookingOwl commented 3 years ago

The correct method name supposed to be .nextVideos() and .nextPlaylists()

https://youtubei.netlify.app/docs/api/classes/channel#methods

ajoykarmakar459 commented 3 years ago

Can I get the all videos from a channel?

SuspiciousLookingOwl commented 3 years ago

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.

ajoykarmakar459 commented 3 years ago

But this isn't working am I missing some important step?

Screenshot 2021-08-30 at 1 01 02 PM
SuspiciousLookingOwl commented 3 years ago

My bad, I copy pasted your code 😂 it's supposed to be nextVideos, not getVideos

const channelVideos = await video.channel.nextVideos(0);
ajoykarmakar459 commented 3 years ago

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?

SuspiciousLookingOwl commented 3 years ago

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.

ajoykarmakar459 commented 3 years ago

So If I get high volume traffic in this library what will happen and how the thing can be sorted, Any Idea?

SuspiciousLookingOwl commented 3 years ago

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

ajoykarmakar459 commented 3 years ago

Ok, thank you for the feedback.

ajoykarmakar459 commented 3 years ago

Is it possible to get the nextVideos in a paginated way?

SuspiciousLookingOwl commented 3 years ago

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
ajoykarmakar459 commented 3 years ago

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?

ajoykarmakar459 commented 3 years ago

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);
SuspiciousLookingOwl commented 3 years ago

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

ajoykarmakar459 commented 3 years ago

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?

SuspiciousLookingOwl commented 3 years ago

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();
ajoykarmakar459 commented 3 years ago

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.

SuspiciousLookingOwl commented 3 years ago

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

musso commented 2 years ago

My bad, I copy pasted your code 😂 it's supposed to be nextVideos, not getVideos

const channelVideos = await video.channel.nextVideos(0);

If the channel is having more than 1000 videos, it will create a timeout error

SuspiciousLookingOwl commented 2 years ago

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)