distubejs / ytdl-core

YouTube video downloader in javascript.
MIT License
279 stars 50 forks source link

UnrecoverableError: Sign in to confirm you’re not a bot #76

Closed Xing-Deal closed 2 weeks ago

Xing-Deal commented 3 months ago

Describe the bug

Debug File

Environment

omerman commented 3 months ago

Same here :X

fsholehan commented 3 months ago

use cookies bro

tonykx commented 3 months ago

use cookies, cara

Não sei como adicionar, você pode me enviar sua case sem o token?

fsholehan commented 3 months ago

use cookies, cara

Não sei como adicionar, você pode me enviar sua case sem o token?

I just followed the instructions in the README, and it worked for me.

tonykx commented 3 months ago

Use cookies, cara

Não sei como adicionar, você pode me enviar sua case sem o token?

Eu apenas segui as instruções no README e funcionou para mim.

Envie aqui sua função completa pra eu testar na minha máquina

tonykx commented 3 months ago

Apenas a função, os cookies eu consigo encontrar

fsholehan commented 3 months ago

const cookies = [....]

const agent = distube.createAgent(cookies);

exports.audioOnly = async (req, res) => { const { videoId } = req.query; let info = await distube.getInfo(videoId, { agent }); let audioFormats = distube.filterFormats(info.formats, "audioonly"); res.json(audioFormats); };

tonykx commented 3 months ago

const cookies = [....]

const agente = distube.createAgent(cookies);

exports.audioOnly = async (req, res) => { const { videoId } = req.query; let info = await distube.getInfo(videoId, { agent }); let audioFormats = distube.filterFormats(info.formats, "audioonly"); res.json(audioFormats); };

Envia a função completa por favor, da case ao break, ficarei grato!

EAxelGM commented 3 months ago

Where can I get a cookie? to use in the example

fsholehan commented 3 months ago

Where can I get a cookie? to use in the example

Read This

EAxelGM commented 3 months ago

Where can I get a cookie? to use in the example

Read This

Thank you bro, I will try this.

magickaito commented 3 months ago

I just tested, cookies works, but any idea how long does the cookies work?

tonykx commented 3 months ago

Acabei de testar, os cookies funcionam, mas alguma ideia de quanto tempo os cookies funcionam?

Me envia aí mano sua função adaptada com os cookies pra eu ver como fica, não consegui adaptar no meu! Não precisa enviar seus cookies

EAxelGM commented 3 months ago

Well I did about the cookies, it works in my local, but in the server isn't work I have the same error, i did the same steps that in the documentation image

NeKosmico commented 3 months ago

Acabei de testar, os cookies funcionam, mas alguma ideia de quanto tempo os cookies funcionam?

Me envia aí mano sua função adaptada com os cookies pra eu ver como fica, não consegui adaptar no meu! Não precisa enviar seus cookies

Aquí encontré un código que usa las cookies y si me funcionó. Ejemplo

ybd-project commented 3 months ago

Well I did about the cookies, it works in my local, but in the server isn't work I have the same error, i did the same steps that in the documentation image

In my case, I used a proxy like 152.26.229.66:9443 to address this issue. (#70) However, it does slow down the processing speed a bit.

omerman commented 3 months ago

Well I did about the cookies, it works in my local, but in the server isn't work I have the same error, i did the same steps that in the documentation image

Same here

omerman commented 3 months ago

@EAxelGM Adding the referer works for me.

const agentOptions = {
    headers: {
      referer: 'https://www.youtube.com/',
    },
  };
  const agent = ytdl.createAgent(cookies, agentOptions);
ybd-project commented 3 months ago

@EAxelGM Adding the referer works for me.

const agentOptions = {
    headers: {
      referer: 'https://www.youtube.com/',
    },
  };
  const agent = ytdl.createAgent(cookies, agentOptions);

I did the following, but it does not work on my Glitch server.

const agentOptions = {
    headers: {
        referer: "https://www.youtube.com/",
    },
},
    agent = ytdl.createAgent(cookies, agentOptions);

const info = await ytdl.getInfo(url, { agent });

server js – marsh-numerous-oak - Google Chrome 2024_08_08 12_35_58

omerman commented 3 months ago

@ybd-project Male sure to get the cookies while in incognito and then close the browser, do not log out

quickRyan commented 3 months ago

Went through the steps to get the cookies through incognito mode, used known good working proxies and still having the issue:

image

image

As mentioned above by another user, It works on my local machine but not on my server. Now I can assume it's something to do with whom I'm hosting with. But shouldn't the proxies fix that?

ybd-project commented 3 months ago

@ybd-project Male sure to get the cookies while in incognito and then close the browser, do not log out

Cookies still do not work as expected and only work locally. For non-local use, using a proxy is the most promising solution at this time.

Update: I am looking for proxies that can be used successfully. But there are very few of these, only about 10 at this time. (Proxies like 152.26.xxx.xx:9443 are competent because they are fast and work correctly.)

thind9xdev commented 3 months ago

I have try, and it working fine Step 1, Go to :https://chrome.google.com/webstore/detail/fngmhnnpilhplaeedifhccceomclgfbg and install it; Step 2, Go to Youtube, then login,next in icon EditCookie, choose export data ; Step 3 Paste cookie to file: cookies.json in root project NestJS Code:

import * as ytdl from '@distube/ytdl-core';
import axios from 'axios';
import * as fs from 'fs';
import * as path from 'path';

export class YouTubeService  implements OnModuleInit {
  constructor() {
    super();
  }
 }
  private agent: ytdl.Agent;

  onModuleInit() {
    this.initializeAgent();
  }
    private initializeAgent() {
    const cookiesPath = path.join(__dirname, '..', 'cookies.json');
    const cookiesContent = fs.readFileSync(cookiesPath, 'utf8');
    this.agent = ytdl.createAgent(JSON.parse(cookiesContent));
  }
  getAgent(): ytdl.Agent {
    return this.agent;
  }

   protected async downloadYoutube(youtubeLink: any, ipAddress: string) {
    try {
      if (!ytdl.validateURL(youtubeLink)) {
        throw new Error('Youtube url not invalid');
      }
      const agent = await this.getAgent();
      const info = await ytdl.getInfo(youtubeLink, { agent });
      const videoFormat = ytdl.chooseFormat(info.formats, {
        quality: 'highestvideo',
        filter: 'videoandaudio',
      });

      if (videoFormat && videoFormat.container === 'mp4') {
        return {
          title: info.videoDetails.title,
          channelId: info.videoDetails.channelId,
          artist: info.videoDetails.author.name,
          verified: info.videoDetails.author.verified,
          category: info.videoDetails.category,
          description: info.videoDetails.description,
          keywords: info.videoDetails.keywords,
          thumbnails: info.videoDetails.thumbnails

        };
      } else {
        throw new Error('Error');
      }
    } catch (err) {
      return {
        message: 'Server error',
        error: err.message,
      };
    }
  }
ybd-project commented 3 months ago

I have try, and it working fine Step 1, Go to :https://chrome.google.com/webstore/detail/fngmhnnpilhplaeedifhccceomclgfbg and install it; Step 2, Go to Youtube, then login,next in icon EditCookie, choose export data ; Step 3 Paste cookie to file: cookies.json in root project NestJS Code:

Thank you very much, I will try it. But using the cookie does not work in my environment (Glitch server). I got the cookie from EditThisCookie and pasted it as is without editing, but no luck.

MikeyA-yo commented 3 months ago

use cookies bro

doing this and not working, is there a specific way to do this?

ybd-project commented 3 months ago

use cookies bro

doing this and not working, is there a specific way to do this?

Cookies do not work well, so we use proxies instead.

thind9xdev commented 3 months ago

Glitch server)

I you no have mysql or sql server database, I think you should try use server vercel ^^

ybd-project commented 3 months ago

I you no have mysql or sql server database, I think you should try use server vercel ^^

I had deployed an app with ytdl-core to a serverless function in Vercel, but this error prevented it from working. I tried changing cookies, creating a new account, etc., but it did not work and now using a proxy is working.

MikeyA-yo commented 3 months ago

use cookies bro

doing this and not working, is there a specific way to do this?

Cookies do not work well, so we use proxies instead.

how do i use proxies?

Like how do i get a proxy url to use

MikeyA-yo commented 3 months ago

Glitch server)

I you no have mysql or sql server database, I think you should try use server vercel ^^

i was using vercel server all this while it was working, it stopped today

ybd-project commented 3 months ago

how do i use proxies?

Implement as follows Specify 152.26.229.66:9443 for the proxy IP.

const ytdl = require('@distube/ytdl-core');
const url = 'https://www.youtube.com/watch?v=' + videoId;

const agent = ytdl.createProxyAgent({
    uri: "http://" + proxyIp,
});
const info = await ytdl.getInfo(url, {
    agent,
});
thind9xdev commented 3 months ago

I you no have mysql or sql server database, I think you should try use server vercel ^^

I had deployed an app with ytdl-core to a serverless function in Vercel, but this error prevented it from working. I tried changing cookies, creating a new account, etc., but it did not work and now using a proxy is working.

You can have check my API at here : https://api.phuongmychi.vn/v3/video-stream?id=cSofAIqJ7mE ^^ This is API temp, I will delete it after 2 hour

MikeyA-yo commented 3 months ago

how do i use proxies?

Implement as follows Specify 152.26.229.66:9443 for the proxy IP.

const ytdl = require('@distube/ytdl-core');
const url = 'https://www.youtube.com/watch?v=' + videoId;

const agent = ytdl.createProxyAgent({
    uri: "http://" + proxyIp,
});
const info = await ytdl.getInfo(url, {
    agent,
});

thanks dude let me try it

ybd-project commented 3 months ago

I you no have mysql or sql server database, I think you should try use server vercel ^^

I had deployed an app with ytdl-core to a serverless function in Vercel, but this error prevented it from working. I tried changing cookies, creating a new account, etc., but it did not work and now using a proxy is working.

You can have check my API at here : https://api.phuongmychi.vn/v3/video-stream?id=cSofAIqJ7mE ^^

Very nice. I am curious how you implement it.

MikeyA-yo commented 3 months ago

how do i use proxies?

Implement as follows Specify 152.26.229.66:9443 for the proxy IP.

const ytdl = require('@distube/ytdl-core');
const url = 'https://www.youtube.com/watch?v=' + videoId;

const agent = ytdl.createProxyAgent({
    uri: "http://" + proxyIp,
});
const info = await ytdl.getInfo(url, {
    agent,
});

this proxy doesn't work locally i get connect timeout error

fsholehan commented 3 months ago

I you no have mysql or sql server database, I think you should try use server vercel ^^

I had deployed an app with ytdl-core to a serverless function in Vercel, but this error prevented it from working. I tried changing cookies, creating a new account, etc., but it did not work and now using a proxy is working.

You can have check my API at here : https://api.phuongmychi.vn/v3/video-stream?id=cSofAIqJ7mE ^^ This is API temp, I will delete it after 2 hour

But, still can't bypass 403 the url video/audio

thind9xdev commented 3 months ago

I you no have mysql or sql server database, I think you should try use server vercel ^^

I had deployed an app with ytdl-core to a serverless function in Vercel, but this error prevented it from working. I tried changing cookies, creating a new account, etc., but it did not work and now using a proxy is working.

You can have check my API at here : https://api.phuongmychi.vn/v3/video-stream?id=cSofAIqJ7mE ^^

Very nice. I am curious how you implement it.

As I have said above, I do steps bellow : Step 1, Go to :https://chrome.google.com/webstore/detail/fngmhnnpilhplaeedifhccceomclgfbg and install it; Step 2, Go to Youtube, then login,next in icon EditCookie, choose export data ; Step 3 Paste cookie to file: cookies.json in root project NestJS Code:

import * as ytdl from '@distube/ytdl-core';
import axios from 'axios';
import * as fs from 'fs';
import * as path from 'path';

export class YouTubeService  implements OnModuleInit {
  constructor() {
    super();
  }
 }
  private agent: ytdl.Agent;

  onModuleInit() {
    this.initializeAgent();
  }
    private initializeAgent() {
    const cookiesPath = path.join(__dirname, '..', 'cookies.json');
    const cookiesContent = fs.readFileSync(cookiesPath, 'utf8');
    this.agent = ytdl.createAgent(JSON.parse(cookiesContent));
  }
  getAgent(): ytdl.Agent {
    return this.agent;
  }

   protected async downloadYoutube(youtubeLink: any, ipAddress: string) {
    try {
      if (!ytdl.validateURL(youtubeLink)) {
        throw new Error('Youtube url not invalid');
      }
      const agent = await this.getAgent();
      const info = await ytdl.getInfo(youtubeLink, { agent });
      const videoFormat = ytdl.chooseFormat(info.formats, {
        quality: 'highestvideo',
        filter: 'videoandaudio',
      });

      if (videoFormat && videoFormat.container === 'mp4') {
        return {
          title: info.videoDetails.title,
          channelId: info.videoDetails.channelId,
          artist: info.videoDetails.author.name,
          verified: info.videoDetails.author.verified,
          category: info.videoDetails.category,
          description: info.videoDetails.description,
          keywords: info.videoDetails.keywords,
          thumbnails: info.videoDetails.thumbnails

        };
      } else {
        throw new Error('Error');
      }
    } catch (err) {
      return {
        message: 'Server error',
        error: err.message,
      };
    }
  }

My Server : VPS or Vercel

thind9xdev commented 3 months ago

I you no have mysql or sql server database, I think you should try use server vercel ^^

I had deployed an app with ytdl-core to a serverless function in Vercel, but this error prevented it from working. I tried changing cookies, creating a new account, etc., but it did not work and now using a proxy is working.

You can have check my API at here : https://api.phuongmychi.vn/v3/video-stream?id=cSofAIqJ7mE ^^ This is API temp, I will delete it after 2 hour

But, still can't bypass 403 the url video/audio

Can you have give me id youtube ?

ybd-project commented 3 months ago

this proxy doesn't work locally i get connect timeout error

Indeed, locally the proxy does not work... However, I don't know why, but it works when deployed to Glitch, etc.

thind9xdev commented 3 months ago

I you no have mysql or sql server database, I think you should try use server vercel ^^

I had deployed an app with ytdl-core to a serverless function in Vercel, but this error prevented it from working. I tried changing cookies, creating a new account, etc., but it did not work and now using a proxy is working.

You can have check my API at here : https://api.phuongmychi.vn/v3/video-stream?id=cSofAIqJ7mE ^^ This is API temp, I will delete it after 2 hour

But, still can't bypass 403 the url video/audio

oh let me check

fsholehan commented 3 months ago

I you no have mysql or sql server database, I think you should try use server vercel ^^

I had deployed an app with ytdl-core to a serverless function in Vercel, but this error prevented it from working. I tried changing cookies, creating a new account, etc., but it did not work and now using a proxy is working.

You can have check my API at here : https://api.phuongmychi.vn/v3/video-stream?id=cSofAIqJ7mE ^^ This is API temp, I will delete it after 2 hour

But, still can't bypass 403 the url video/audio

oh let me check

Try this one 11JI_2dQZqU

thind9xdev commented 3 months ago

image

thind9xdev commented 3 months ago

I you no have mysql or sql server database, I think you should try use server vercel ^^

I had deployed an app with ytdl-core to a serverless function in Vercel, but this error prevented it from working. I tried changing cookies, creating a new account, etc., but it did not work and now using a proxy is working.

You can have check my API at here : https://api.phuongmychi.vn/v3/video-stream?id=cSofAIqJ7mE ^^ This is API temp, I will delete it after 2 hour

But, still can't bypass 403 the url video/audio

oh let me check

Try this one 11JI_2dQZqU

image

fsholehan commented 3 months ago

I you no have mysql or sql server database, I think you should try use server vercel ^^

I had deployed an app with ytdl-core to a serverless function in Vercel, but this error prevented it from working. I tried changing cookies, creating a new account, etc., but it did not work and now using a proxy is working.

You can have check my API at here : https://api.phuongmychi.vn/v3/video-stream?id=cSofAIqJ7mE ^^ This is API temp, I will delete it after 2 hour

But, still can't bypass 403 the url video/audio

oh let me check

Try this one 11JI_2dQZqU

image

Local or server? I try before, 403

thind9xdev commented 3 months ago

I you no have mysql or sql server database, I think you should try use server vercel ^^

I had deployed an app with ytdl-core to a serverless function in Vercel, but this error prevented it from working. I tried changing cookies, creating a new account, etc., but it did not work and now using a proxy is working.

You can have check my API at here : https://api.phuongmychi.vn/v3/video-stream?id=cSofAIqJ7mE ^^ This is API temp, I will delete it after 2 hour

But, still can't bypass 403 the url video/audio

oh let me check

Try this one 11JI_2dQZqU

Oh some video HD, FULL HD url get error 403

yourshaxzod commented 3 months ago

image

fsholehan commented 3 months ago

I you no have mysql or sql server database, I think you should try use server vercel ^^

I had deployed an app with ytdl-core to a serverless function in Vercel, but this error prevented it from working. I tried changing cookies, creating a new account, etc., but it did not work and now using a proxy is working.

You can have check my API at here : https://api.phuongmychi.vn/v3/video-stream?id=cSofAIqJ7mE ^^ This is API temp, I will delete it after 2 hour

But, still can't bypass 403 the url video/audio

oh let me check

Try this one 11JI_2dQZqU

Oh some video HD, FULL HD url get error 403

Try the audio also

MikeyA-yo commented 3 months ago

this proxy doesn't work locally i get connect timeout error

Indeed, locally the proxy does not work... However, I don't know why, but it works when deployed to Glitch, etc.

ok, i wanna deploy to vercel and render i hope it works there if not i don't know what else to do

ybd-project commented 3 months ago

Try the audio also

I just got the URL for the video from my API, so please test if you can view it. (no audio) https://rr1---sn-hjoj-poul.googlevideo.com/videoplayback?expire=1723144579&ei=I8W0ZtrUJ-aCy_sPqpy88Ag&ip=152.22.51.22&id=o-AJkTdKbXVBPu1tlc-OecQ8ShH_iQhaeG_X6sNlCQBV7L&itag=137&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&mh=7c&mm=31%2C29&mn=sn-hjoj-poul%2Csn-5uaeznse&ms=au%2Crdu&mv=m&mvi=1&pl=19&initcwndbps=1771250&vprv=1&svpuc=1&mime=video%2Fmp4&rqh=1&gir=yes&clen=80170781&dur=212.040&lmt=1717051616612658&mt=1723122567&fvip=2&keepalive=yes&c=IOS&txp=4535434&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Cvprv%2Csvpuc%2Cmime%2Crqh%2Cgir%2Cclen%2Cdur%2Clmt&sig=AJfQdSswRQIhAKfzjJrSr4_mQml6_D10Wig_hTpolqnaKmGLakEloZS7AiBtdmmjfKfnsdTbcU8A2vB_W8eEa2vANxW_GZ6Gj4SI5Q%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AGtxev0wRgIhAMxjzYeIcwoVlH2w4Dt2gl1MBbQIxlUVzdHfwx-ZY7VbAiEAiU3klzsEZouZibrYiKhg-crZkra8vUWOQJPINiQ6Hto%3D

fsholehan commented 3 months ago

Try the audio also

I just got the URL for the video from my API, so please test if you can view it. (no audio) https://rr1---sn-hjoj-poul.googlevideo.com/videoplayback?expire=1723144579&ei=I8W0ZtrUJ-aCy_sPqpy88Ag&ip=152.22.51.22&id=o-AJkTdKbXVBPu1tlc-OecQ8ShH_iQhaeG_X6sNlCQBV7L&itag=137&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&mh=7c&mm=31%2C29&mn=sn-hjoj-poul%2Csn-5uaeznse&ms=au%2Crdu&mv=m&mvi=1&pl=19&initcwndbps=1771250&vprv=1&svpuc=1&mime=video%2Fmp4&rqh=1&gir=yes&clen=80170781&dur=212.040&lmt=1717051616612658&mt=1723122567&fvip=2&keepalive=yes&c=IOS&txp=4535434&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Cvprv%2Csvpuc%2Cmime%2Crqh%2Cgir%2Cclen%2Cdur%2Clmt&sig=AJfQdSswRQIhAKfzjJrSr4_mQml6_D10Wig_hTpolqnaKmGLakEloZS7AiBtdmmjfKfnsdTbcU8A2vB_W8eEa2vANxW_GZ6Gj4SI5Q%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AGtxev0wRgIhAMxjzYeIcwoVlH2w4Dt2gl1MBbQIxlUVzdHfwx-ZY7VbAiEAiU3klzsEZouZibrYiKhg-crZkra8vUWOQJPINiQ6Hto%3D

Screenshot_20240808_202503_Chrome

Yess, it works