fent / node-ytdl-core

YouTube video downloader in javascript.
MIT License
4.49k stars 793 forks source link

Download a private video youtube #1282

Open kamalkech opened 6 months ago

kamalkech commented 6 months ago

ytdl-core: ^4.11.5

i try to use this example to download a private video youtube but not working. https://github.com/fent/node-ytdl-core/blob/master/example/cookies.js

on this example should inject cookie and x-youtube-identity-token so how can get cookie value ?

twarped commented 5 months ago

I think you have to go to YouTube.com when you're signed in then put this in the console to see your cookies:

console.log(document.cookie)

But, I'm on a phone right now... so who knows.

omar-ezeldin commented 3 months ago

I got it to work but not using the cookie approach, but using the headers directly I am using "ytdl-core": "^4.11.5" and "node":"20.11.0"

To get the headers using Chrome:

Screenshot 2024-06-26 120405

Hope this helped 😄, I'll add my code too, if this worked don't forget to close the issue Omar Ezeldin

This is my code:

const ytdl = require('ytdl-core');
const path = require('path');
const fs = require('fs');

const videoID = "YOUR VIDEO ID";
const HEADERS = "YOUR HEADERS OBJECT";

const outputName = 'video.mp4';
const outputPath = path.resolve(__dirname, outputName);

const video = ytdl(videoID, {
    requestOptions: {
        headers: HEADERS
    },
});

video.on('info', (info) => {
    console.log('title:', info.videoDetails.title);
    console.log('rating:', info.player_response.videoDetails.averageRating);
    console.log('uploaded by:', info.videoDetails.author.name);
});

video.on('progress', (chunkLength, downloaded, total) => {
    const percent = downloaded / total;
    console.log('downloading', `${(percent * 100).toFixed(1)}%`);
});

video.on('end', () => {
    console.log('saved to', outputName);
});

video.pipe(fs.createWriteStream(outputPath));
Achin-Aggarwal commented 2 months ago

bro can u explain it a bit more to how to find these as i unable to find them

twarped commented 2 months ago

Oh, that makes sense.

you have to go to the network tab in developer tools if you’re confused