
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
@nuclearplayer/ytdl-core
Advanced tools
Nuclear fork of ytdl-core. YouTube video downloader in pure javascript.
Nuclear Player fork of ytdl-core. This fork is dedicated to fixing bugs and adding features that are not merged into the original repo as soon as possible.
npm install @nuclearplayer/ytdl-core@latest
Make sure you're installing the latest version of @nuclearplayer/ytdl-core to keep up with the latest fixes.
const ytdl = require("@nuclearplayer/ytdl-core");
// TypeScript: import ytdl from '@nuclearplayer/ytdl-core'; with --esModuleInterop
// TypeScript: import * as ytdl from '@nuclearplayer/ytdl-core'; with --allowSyntheticDefaultImports
// TypeScript: import ytdl = require('@nuclearplayer/ytdl-core'); with neither of the above
// Download a video
ytdl("http://www.youtube.com/watch?v=aqz-KE-bpKQ").pipe(require("fs").createWriteStream("video.mp4"));
// Get video info
ytdl.getBasicInfo("http://www.youtube.com/watch?v=aqz-KE-bpKQ").then(info => {
console.log(info.videoDetails.title);
});
// Get video info with download formats
ytdl.getInfo("http://www.youtube.com/watch?v=aqz-KE-bpKQ").then(info => {
console.log(info.formats);
});
const ytdl = require("@nuclearplayer/ytdl-core");
// (Optional) Below are examples, NOT the recommended options
const cookies = [
{ name: "cookie1", value: "COOKIE1_HERE" },
{ name: "cookie2", value: "COOKIE2_HERE" },
];
// (Optional) http-cookie-agent / undici agent options
// Below are examples, NOT the recommended options
const agentOptions = {
pipelining: 5,
maxRedirections: 0,
localAddress: "127.0.0.1",
};
// agent should be created once if you don't want to change your cookie
const agent = ytdl.createAgent(cookies, agentOptions);
ytdl.getBasicInfo("http://www.youtube.com/watch?v=aqz-KE-bpKQ", { agent });
ytdl.getInfo("http://www.youtube.com/watch?v=aqz-KE-bpKQ", { agent });
[!WARNING] Don't logout it by clicking logout button on youtube/google account manager, it will expire your cookies. You can delete your browser's cookies to log it out on your browser. Or use incognito mode to get your cookies then close it.
[!WARNING] Paste all the cookies array from clipboard into
createAgentfunction. Don't remove/edit any cookies if you don't know what you're doing.
[!WARNING] Make sure your account, which logged in when you getting your cookies, use 1 IP at the same time only. It will make your cookies alive longer.
const ytdl = require("@nuclearplayer/ytdl-core");
const agent = ytdl.createAgent([
{
domain: ".youtube.com",
expirationDate: 1234567890,
hostOnly: false,
httpOnly: true,
name: "---xxx---",
path: "/",
sameSite: "no_restriction",
secure: true,
session: false,
value: "---xxx---",
},
{
"...": "...",
},
]);
fs.readFileSync to read it.const ytdl = require("@nuclearplayer/ytdl-core");
const fs = require("fs");
const agent = ytdl.createAgent(JSON.parse(fs.readFileSync("cookies.json")));
const ytdl = require("@nuclearplayer/ytdl-core");
const agent = ytdl.createProxyAgent({ uri: "my.proxy.server" });
ytdl.getBasicInfo("http://www.youtube.com/watch?v=aqz-KE-bpKQ", { agent });
ytdl.getInfo("http://www.youtube.com/watch?v=aqz-KE-bpKQ", { agent });
Use both proxy and cookies:
const ytdl = require("@nuclearplayer/ytdl-core");
const agent = ytdl.createProxyAgent({ uri: "my.proxy.server" }, [{ name: "cookie", value: "COOKIE_HERE" }]);
ytdl.getBasicInfo("http://www.youtube.com/watch?v=aqz-KE-bpKQ", { agent });
ytdl.getInfo("http://www.youtube.com/watch?v=aqz-KE-bpKQ", { agent });
Built-in ip rotation (getRandomIPv6) won't be updated and will be removed in the future, create your own ip rotation instead.
To implement IP rotation, you need to assign the desired IP address to the localAddress property within undici.Agent.Options.
Therefore, you'll need to use a different ytdl.Agent for each IP address you want to use.
const ytdl = require("@nuclearplayer/ytdl-core");
const { getRandomIPv6 } = require("@nuclearplayer/ytdl-core/lib/utils");
const agentForARandomIP = ytdl.createAgent(undefined, {
localAddress: getRandomIPv6("2001:2::/48"),
});
ytdl.getBasicInfo("http://www.youtube.com/watch?v=aqz-KE-bpKQ", { agent: agentForARandomIP });
const agentForAnotherRandomIP = ytdl.createAgent(undefined, {
localAddress: getRandomIPv6("2001:2::/48"),
});
ytdl.getInfo("http://www.youtube.com/watch?v=aqz-KE-bpKQ", { agent: agentForAnotherRandomIP });
You can find the API documentation in the original repo. Except a few changes:
ytdl.getInfoOptionsrequestOptions is now undici's RequestOptions.agent: ytdl.AgentplayerClients: An array of player clients to use. Accepts WEB, WEB_EMBEDDED, TV, IOS, and ANDROID. Defaults to ["WEB_EMBEDDED", "IOS", "ANDROID","TV"].fetch: Custom fetch implementation. Defaults to undici's request.ytdl.createAgent([cookies]): ytdl.Agentcookies: an array of json cookies exported with EditThisCookie.
ytdl.createProxyAgent(proxy[, cookies]): ytdl.Agentproxy: ProxyAgentOptions contains your proxy server information.
ytdl.Agent with your own DispatcherYou can find the example here
ytdl cannot download videos that fall into the following
Generated download links are valid for 6 hours, and may only be downloadable from the same IP address.
When doing too many requests YouTube might block. This will result in your requests getting denied with HTTP-StatusCode 429. The following steps might help you:
@nuclearplayer/ytdl-core to the latest versionThe issue of using an outdated version of ytdl-core became so prevalent, that ytdl-core now checks for updates at run time, and every 12 hours. If it finds an update, it will print a warning to the console advising you to update. Due to the nature of this library, it is important to always use the latest version as YouTube continues to update.
If you'd like to disable this update check, you can do so by providing the YTDL_NO_UPDATE env variable.
env YTDL_NO_UPDATE=1 node myapp.js
FAQs
Nuclear fork of ytdl-core. YouTube video downloader in pure javascript.
We found that @nuclearplayer/ytdl-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.