node-ytdl-core
node-ytdl-core copied to clipboard
Download a private video youtube
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 ?
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.
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:
- Go to the specified private video
- Open the Developer Tools
- Go to the Network Tab (Refresh the page if needed)
- Toggle the
Doc
Filter - You should find a request named
watch?v=<VIDEO_ID>
- Copy the request headers (Just right-click it > Copy > Copy as fetch (Node.js) > then extract the
headers
object) - Now use this
headers
object forrequestOptions.header
in option
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));
bro can u explain it a bit more to how to find these as i unable to find them
Oh, that makes sense.
you have to go to the network tab in developer tools if you’re confused