Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download a private video youtube #1282

Open
kamalkech opened this issue Apr 3, 2024 · 4 comments
Open

Download a private video youtube #1282

kamalkech opened this issue Apr 3, 2024 · 4 comments

Comments

@kamalkech
Copy link

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
Copy link

twarped commented Apr 11, 2024

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
Copy link

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>

Screenshot 2024-06-26 120405

  • Copy the request headers (Just right-click it > Copy > Copy as fetch (Node.js) > then extract the headers object)
  • Now use this headers object for requestOptions.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));

@Achin-Aggarwal
Copy link

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

@twarped
Copy link

twarped commented Jul 11, 2024

Oh, that makes sense.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants