ybd-project / ytdl-core

Fast and secure YouTube downloader for JavaScript and TypeScript
MIT License
28 stars 5 forks source link

All player APIs #9

Closed badDevelopper closed 2 months ago

badDevelopper commented 3 months ago

Describe the bug

Error: All player APIs responded with an error. (Clients: web_creator, ios, android) at _getBasicInfo (/home/container/node_modules/@ybd-project/ytdl-core/package/info.js:326:15) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async _getInfo (/home/container/node_modules/@ybd-project/ytdl-core/package/info.js:362:18) Emitted 'error' event on Client instance at: at emitUnhandledRejectionOrErr (node:events:402:10) at process.processTicksAndRejections (node:internal/process/task_queues:84:21)

Node.js v20.16.0

ybd-project commented 3 months ago

Which video URL is causing that problem? Please provide the code you are implementing.

badDevelopper commented 3 months ago

y just try in local pc. dont wok more, an also run im my vps ubuntu, and not work....

const videoUrl = https://www.youtube.com/watch?v=${videoId};

ytdown(videoUrl, { format: 'json' }).then((response) => {
  const videoMp4Url = response.data.video; // URL do vídeo em MP4

  res.header('Content-Disposition', 'attachment; filename="video.mp4"');

       axios({
    url: videoMp4Url,
    method: 'GET',
    responseType: 'stream'
  }).then(videoResponse => {
    videoResponse.data.pipe(res);
  }).catch(error => {
    console.log(error)
    res.status(500).send('Erro ao baixar o vídeo.');
  });

}

).catch(error => { console.log(error) res.status(500).send('Erro ao processar o vídeo.'); });

ybd-project commented 3 months ago

You can specify poToken and visitorData as the second argument of the function. Use https://github.com/fsholehan/scrape-youtube to generate poToken and visitorData. It would still be helpful if you could give us the exact video URL.

// Like this
ytdl.getInfo(VIDEO_URL, {
    poToken: 'PO_TOKEN',
    visitorData: 'VISITOR_DATA',
});
dfxphoenix commented 3 months ago

I have the same error but only on my ubuntu server. On my ubuntu desktop and windows works fine.

/root/test/node_modules/@ybd-project/ytdl-core/package/info.js:326
        throw new Error(`All player APIs responded with an error. (Clients: ${options.clients.join(', ')})`);
              ^

Error: All player APIs responded with an error. (Clients: web_creator, ios, android)
    at _getBasicInfo (/root/test/node_modules/@ybd-project/ytdl-core/package/info.js:326:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async _getInfo (/root/test/node_modules/@ybd-project/ytdl-core/package/info.js:362:18)
Emitted 'error' event on PassThrough instance at:
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v20.13.1

this is my test script

const ytdl = require('@ybd-project/ytdl-core');
// TypeScript: import ytdl from '@ybd-project/ytdl-core'; with --esModuleInterop
// TypeScript: import * as ytdl from '@ybd-project/ytdl-core'; with --allowSyntheticDefaultImports
// TypeScript: import ytdl = require('@ybd-project/ytdl-core'); with neither of the above

// Download a video
ytdl('http://www.youtube.com/watch?v=aqz-KE-bpKQ', { poToken: xxx', visitorData: 'xxx' }).pipe(require('fs').createWriteStream('video.mp4'));
dfxphoenix commented 3 months ago

Resolved by generate new poToken with https://github.com/YunzheZJU/youtube-po-token-generator

EmilianoTalamo commented 2 months ago

Didn't work on my vps. Fetching info works, but the download returns that error even when passing a poToken and visitorData from youtube-po-token-generator.

ybd-project commented 2 months ago

Didn't work on my vps. Fetching info works, but the download returns that error even when passing a poToken and visitorData from youtube-po-token-generator.

We are currently aware of this issue. Basically, if fetching information works, then downloading should also work.

EmilianoTalamo commented 2 months ago

Update: I was using the distubejs/ytdl-core library for info fetching. Replaced it with this one and it throws the same error on both methods.

Code

info = await ytdl.getInfo(`http://www.youtube.com/watch?v=${id}`, {
    agent,
        poToken: player.trustedTokens?.PO_TOKEN || undefined,
    visitorData: player.trustedTokens?.VISITOR_DATA || undefined,
})

ytdl(`http://youtube.com/watch?v=${id}`, {
    filter: 'audioonly',
    quality: 'highestaudio',
    dlChunkSize: 0,
    highWaterMark: 1 << 62,
    liveBuffer: 1 << 62,
    poToken: player.trustedTokens?.PO_TOKEN || undefined,
    visitorData: player.trustedTokens?.VISITOR_DATA || undefined,
})

Error

AudioPlayerError: All player APIs responded with an error. (Clients: web_creator, ios, android)
    at _getBasicInfo (/app/node_modules/@ybd-project/ytdl-core/src/info.ts:452:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at _getInfo (/app/node_modules/@ybd-project/ytdl-core/src/info.ts:504:34) {
  resource: AudioResource {
    playStream: OggDemuxer {
      _events: [Object],
      _readableState: [ReadableState],
      _writableState: [WritableState],
      allowHalfOpen: true,
      _maxListeners: undefined,
      _eventsCount: 6,
      _remainder: null,
      _head: null,
      _bitstream: null,
      [Symbol(shapeMode)]: true,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: null
    },
    edges: [ [Object], [Object] ],
    metadata: null,
    volume: undefined,
    encoder: undefined,
    audioPlayer: AudioPlayer {
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      _state: [Object],
      subscribers: [Array],
      behaviors: [Object],
      debug: [Function (anonymous)],
      [Symbol(shapeMode)]: false,
      [Symbol(kCapture)]: false
    },
    playbackDuration: 0,
    started: false,
    silencePaddingFrames: 5,
    silenceRemaining: -1
  }
}
ybd-project commented 2 months ago

I don't know if this will improve things, but try adding clients: ['web_creator', 'ios', 'android', 'tv_embedded'] as an argument.

ytdl(`http://youtube.com/watch?v=${id}`, {
    filter: 'audioonly',
    quality: 'highestaudio',
    dlChunkSize: 0,
    highWaterMark: 1 << 62,
    liveBuffer: 1 << 62,
    poToken: player.trustedTokens?.PO_TOKEN || undefined,
    visitorData: player.trustedTokens?.VISITOR_DATA || undefined,
        clients: ['web_creator', 'ios', 'android', 'tv_embedded'],
})
EmilianoTalamo commented 2 months ago

I don't know if this will improve things, but try adding clients: ['web_creator', 'ios', 'android', 'tv_embedded'] as an argument.

ytdl(`http://youtube.com/watch?v=${id}`, {
  filter: 'audioonly',
  quality: 'highestaudio',
  dlChunkSize: 0,
  highWaterMark: 1 << 62,
  liveBuffer: 1 << 62,
  poToken: player.trustedTokens?.PO_TOKEN || undefined,
  visitorData: player.trustedTokens?.VISITOR_DATA || undefined,
        clients: ['web_creator', 'ios', 'android', 'tv_embedded'],
})

Same issue

Error: All player APIs responded with an error. (Clients: web_creator, ios, android, tv_embedded)
ybd-project commented 2 months ago

Same issue

Error: All player APIs responded with an error. (Clients: web_creator, ios, android, tv_embedded)

I understand. Then does the problem occur with all videos?

EmilianoTalamo commented 2 months ago

Same issue

Error: All player APIs responded with an error. (Clients: web_creator, ios, android, tv_embedded)

I understand. Then does the problem occur with all videos?

Yup, locally seems to be working fine (I don't even need poToken or cookies when running locally). The issue arises when using my aws vps.

ybd-project commented 2 months ago

On my test Glitch server, it works fine with the PoToken setting, so it is possible that the AWS VPS IP address is banned. I plan to have the next version output the details of the error.

AnteaterKit commented 2 months ago

On the digitalocean vps with the PoToken. onFailed Error: All player APIs responded with an error. (Clients: web_creator, ios, android) at _getBasicInfo (/usr/src/app/node_modules/@ybd-project/ytdl-core/package/info.js:326:15) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async _getInfo (/usr/src/app/node_modules/@ybd-project/ytdl-core/package/info.js:362:18)

shawnchiao commented 2 months ago

I got the same issue when running it at AWS lambda function but no problem in local machine too

ybd-project commented 2 months ago

A few bug fixes and functions related to error logging have been added. (v5.0.14) Please try npm install @ybd-project/ytdl-core@latest. For debugging logs, specify the environment variable “YTDL_DEBUG=true”.

AnteaterKit commented 2 months ago

A few bug fixes and functions related to error logging have been added. (v5.0.14) Please try npm install @ybd-project/ytdl-core@latest. For debugging logs, specify the environment variable “YTDL_DEBUG=true”.

digitalocean vps

Reason: Error: Status Code: 400

Reason: Error: Status Code: 400

Reason: Error: Status Code: 400 RequestError: Status Code: 400 at Object.request (/usr/src/app/node_modules/@ybd-project/ytdl-core/package/utils.js:193:19) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async playerAPI (/usr/src/app/node_modules/@ybd-project/ytdl-core/package/info.js:209:19) at async fetchSpecifiedPlayer (/usr/src/app/node_modules/@ybd-project/ytdl-core/package/info.js:268:12) at async Promise.allSettled (index 0) at async _getBasicInfo (/usr/src/app/node_modules/@ybd-project/ytdl-core/package/info.js:318:34) at async _getInfo (/usr/src/app/node_modules/@ybd-project/ytdl-core/package/info.js:367:18) { statusCode: 400 } onFailed Error: All player APIs responded with an error. (Clients: web_creator, ios, android) at _getBasicInfo (/usr/src/app/node_modules/@ybd-project/ytdl-core/package/info.js:331:15) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async _getInfo (/usr/src/app/node_modules/@ybd-project/ytdl-core/package/info.js:367:18)

ybd-project commented 2 months ago

digitalocean vps

Thanks for providing the logs. I think the status code 400 means that the IP is banned.

shawnchiao commented 2 months ago

could anyone tell me what is the best reliable way to work around the server's IP being banned?

EmilianoTalamo commented 2 months ago

could anyone tell me what is the best reliable way to work around the server's IP being banned?

With a proxy, but it's not reliable at all and might have the same issues later on.

ybd-project commented 2 months ago

I agree vehemently. I used to use a proxy but it was not stable with occasional errors. I think the best way to get around the IP ban is to use serverless functions.

ybd-project commented 2 months ago

We are currently working on OAuth2 token support. Once this becomes possible, IP restrictions will be less likely than they are now.

ybd-project commented 2 months ago

OAuth2 tokens are now supported. Please install (npm i @ybd-project/ytdl-core@5.0.16) the new version (v5.0.16). See README for usage.

shawnchiao commented 2 months ago

OAuth2 tokens are now supported. Please install (npm i @ybd-project/ytdl-core@5.0.15) the new version (v5.0.15). See README for usage.

tested and worked for me in aws Lambda function. Just wondering how to automate the refreshing access token in the future instead of manual work.

ybd-project commented 2 months ago

tested and worked for me in aws Lambda function. Just wondering how to automate the refreshing access token in the future instead of manual work.

I have implemented access token refresh, but I don't have expired tokens so I'd like to test it.

paradix commented 2 months ago

Well I was trying to run it with the oauth2 token on an Oracle Free Tier server and it got

 UnrecoverableError: This live event will begin in 33 hours.

when runnint getInfo method.

ybd-project commented 2 months ago

Well I was trying to run it with the oauth2 token on an Oracle Free Tier server and it got

 UnrecoverableError: This live event will begin in 33 hours.

when runnint getInfo method.

As you can see from the text, this error means that the video has not yet been released. Since videos that have not yet been released are not available, you will need to try again in 33 hours.

paradix commented 2 months ago

The original ytdl-core always provided video info or basic info even if the stream was scheduled in future

ybd-project commented 2 months ago

The original ytdl-core always provided video info or basic info even if the stream was scheduled in future

I see. That is the first time I have heard of that. Please wait while we implement it so that you can get the minimum information without error.

ybd-project commented 2 months ago

We are currently working on improving all Player API requests, etc., and this issue will be substantially remedied. A version implementing this will be released later today. This version will be the last update before the minor update.

ybd-project commented 2 months ago

A new version v5.0.20 has been released with improved requests to the player API and other improvements. Maybe this version will solve most of this problem.

paradix commented 2 months ago

@ybd-project my getInfo problem is resolved now. Still can't download my live streams with ytarchive. But that's not issue of your project.

ybd-project commented 2 months ago

@ybd-project my getInfo problem is resolved now. Still can't download my live streams with ytarchive. But that's not issue of your project.

Good. We are currently working on v5.1.0, so please be patient.

paradix commented 2 months ago

btw. the getFullInfo() method returns a lot less information than the getInfo() method from the node-ytdl-core package. Is this intentional or did youtube change ?

ybd-project commented 2 months ago

btw. the getFullInfo() method returns a lot less information than the getInfo() method from the node-ytdl-core package. Is this intentional or did youtube change ?

What specific information is this? I deleted data that I thought was unnecessary, so that may be the reason.

paradix commented 2 months ago

I used the whole videoDetails

paradix commented 2 months ago

I have a backend application monitoring given channels, I get pubsubhub notifications on new upcoming videos. I fetch videoDetails with ytdl-code and plan, schedule, etc. the recording of live events based on the data in this container.

ybd-project commented 2 months ago

I think the information in the videoDetails conforms to the original as much as possible. What information is missing from the videoDetails?

paradix commented 2 months ago

hmm... I'll test again to check it out.

ybd-project commented 2 months ago

hmm... I'll test again to check it out.

If possible, please let me know what specific information you would like to retrieve.

paradix commented 2 months ago

Quick check and I'm missing data for upcoming live events (example https://www.youtube.com/watch?v=PzfyPxadxVY) This lacks:

ybd-project commented 2 months ago

Quick check and I'm missing data for upcoming live events (example https://www.youtube.com/watch?v=PzfyPxadxVY) This lacks:

  • videoDetails.isLiveContent
  • videoDetails.liveBroadcastDetails
  • videoDetails.videoId
  • videoDetails.title

Thank you, this will help us improve v5.1.0.

ybd-project commented 2 months ago

image Is it okay like this?

paradix commented 2 months ago

looks great. thnx

paradix commented 2 months ago

any ETA on the 5.1.0 version?

ybd-project commented 2 months ago

any ETA on the 5.1.0 version?

Is the v5.1.0 release? Or is it about the download progress?

paradix commented 2 months ago

No no its about the expected release time of v 5.1.0

ybd-project commented 2 months ago

No no its about the expected release time of v 5.1.0

Then, I still have two more things to do, so the earliest I can do that is tomorrow.

ybd-project commented 2 months ago

v5.1.0 has been released. Please refer to the README as significant changes have been made since the previous version.

ybd-project commented 2 months ago

Is the problem resolved? If no progress is made, close as not necessary to correct.