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
236 stars 49 forks source link

Getting an error on VERCEL but working fine on Google cloud run and localhost #113

Closed altr closed 4 days ago

altr commented 2 months ago

Describe the bug I don't know whether it's a bug, however when hosting on VERCEL I'm consistently getting an error for const video = await youtube.getVideo(id). This issue doesn't occur on localhost and when hosted on Google Cloud Run. The exact error message is: Cannot read properties of undefined (reading 'videoId')

Additional context This wasn't happening 4 weeks ago as this worked fine in the past. Could IP/Proxy or similar factors play a role here?

mehdi89 commented 2 months ago

Same here, it's working in local, but not working from Vercel, Google cloud functions and Digital Ocean Server. Any Idea why or how to fix it ?

MaitreGEEK commented 2 months ago

Same here

Donald646 commented 2 months ago

It's prob getting blocked, this happened on another library, I was hoping to switch here to avoid it, but ig not.

MaitreGEEK commented 2 months ago

Yep tried in youtube-sr too

SuspiciousLookingOwl commented 4 days ago

Your IP most likely got banned by google, there's nothing that I can do about this unfortunately.

However, I've implemented OAuth into this library, which allows you to send authenticated request, I used this too on my server (because my server got IP banned too) and it has been working fine. Usage:

const client = new Client({
    oauth: {
        enabled: true,
        refreshToken: "optional", // optional if you already have a refresh token 
    }
})
MaitreGEEK commented 2 days ago

Your IP most likely got banned by google, there's nothing that I can do about this unfortunately.

However, I've implemented OAuth into this library, which allows you to send authenticated request, I used this too on my server (because my server got IP banned too) and it has been working fine. Usage:

const client = new Client({
    oauth: {
        enabled: true,
        refreshToken: "optional", // optional if you already have a refresh token 
    }
})

Is there any way to have multiple tokens ? I have a list of cookies and would like to use it with youtubei for a big API

SuspiciousLookingOwl commented 2 days ago

I'm not sure if I'm going to implement that into the library, I feel like it's out of the library's scope, but I'll consider it.

The closest thing you can do right now is to create multiple youtubei client and roll them

Example (not tested):

import { Client } from "youtubei";

const refreshTokens = ["...", "...", "..."];

const clients = refreshTokens.map(refreshToken => new Client({
    oauth: {
        enabled: true,
        refreshToken,
    }
}));

const videoIds = ["...", "...", "..."];

let currentClientIndex = 0;

const getVideo = async (videoId: string) => {
    if (currentClientIndex >= clients.length) {
        currentClientIndex = 0;
    }
    const client = clients[currentClientIndex];
    return client.getVideo(videoId);
}

for (const videoId of videoIds) {
    getVideo(videoId).then(video => {
        console.log(video.title);
    }).catch(console.error);
}
MaitreGEEK commented 2 days ago

Yeah great idea thanks!