Installations
npm install ytdl-core
Score
98.8
Supply Chain
99.2
Quality
76.1
Maintenance
100
Vulnerability
99.6
License
Releases
Contributors
Developer
fent
Developer Guide
Module System
CommonJS
Min. Node Version
>=12
Typescript Support
Yes
Node Version
18.16.1
NPM Version
9.5.1
Statistics
4,535 Stars
1,058 Commits
803 Forks
92 Watching
2 Branches
82 Contributors
Updated on 25 Nov 2024
Bundle Size
65.73 kB
Minified
21.83 kB
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
25,931,797
Last day
6.6%
23,195
Compared to previous day
Last week
13.4%
166,541
Compared to previous week
Last month
3.7%
612,636
Compared to previous month
Last year
93.6%
5,464,882
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
[!IMPORTANT]
Active development on this repository has been paused since 2023-07-14. While it may still function for some scenarios, please be aware that support is now handled solely by the community, and PRs are currently not merged to the repo. For ongoing updates, we encourage you to explore forks like @distube/ytdl-core. We may revisit development in the future. Thank you for your interest and long-lasting support!
Best Regards TFAN, 2024-08-13
node-ytdl-core
Yet another YouTube downloading module. Written with only Javascript and a node-friendly streaming interface.
Support
You can contact us for support on our chat server
Usage
1const fs = require('fs'); 2const ytdl = require('ytdl-core'); 3// TypeScript: import ytdl from 'ytdl-core'; with --esModuleInterop 4// TypeScript: import * as ytdl from 'ytdl-core'; with --allowSyntheticDefaultImports 5// TypeScript: import ytdl = require('ytdl-core'); with neither of the above 6 7ytdl('http://www.youtube.com/watch?v=aqz-KE-bpKQ') 8 .pipe(fs.createWriteStream('video.mp4'));
API
ytdl(url, [options])
Attempts to download a video from the given url. Returns a readable stream. options
can have the following, in addition to any getInfo()
option and chooseFormat()
option.
range
- A byte range in the form{start: INT, end: INT}
that specifies part of the file to download, ie {start: 10355705, end: 12452856}. Not supported on segmented (DASH MPD, m3u8) formats.- This downloads a portion of the file, and not a separately spliced video.
begin
- What time in the video to begin. Supports formats00:00:00.000
,0ms, 0s, 0m, 0h
, or number of milliseconds. Example:1:30
,05:10.123
,10m30s
.liveBuffer
- How much time buffer to use for live videos in milliseconds. Default is20000
.highWaterMark
- How much of the video download to buffer into memory. See node's docs for more. Defaults to 512KB.dlChunkSize
- When the chosen format is video only or audio only, the download is separated into multiple chunks to avoid throttling. This option specifies the size of each chunk in bytes. Setting it to 0 disables chunking. Defaults to 10MB.IPv6Block
- IPv6 block to rotate through, an alternative to using a proxy. Read more. Defaults toundefined
.
Event: info
ytdl.videoInfo
- Info.ytdl.videoFormat
- Video Format.
Emitted when the video's info
is fetched, along with the chosen format to download.
Event: progress
number
- Chunk length in bytes or segment number.number
- Total bytes or segments downloaded.number
- Total bytes or segments.
Emitted whenever a new chunk is received. Passes values describing the download progress.
miniget events
All miniget events are forwarded and can be listened to from the returned stream.
Stream#destroy()
Call to abort and stop downloading a video.
async ytdl.getBasicInfo(url, [options])
Use this if you only want to get metainfo from a video.
async ytdl.getInfo(url, [options])
Gets metainfo from a video. Includes additional formats, and ready to download deciphered URL. This is what the ytdl()
function uses internally.
options
can have the following
requestOptions
- Anything to merge into the request options which miniget is called with, such asheaders
.requestCallback
- Provide a callback function that receives miniget request stream objects used while fetching metainfo.lang
- The 2 character symbol of a language. Default isen
.
ytdl.downloadFromInfo(info, options)
Once you have received metadata from a video with the ytdl.getInfo
function, you may pass that information along with other options to this function.
ytdl.chooseFormat(formats, options)
Can be used if you'd like to choose a format yourself. Throws an Error if it fails to find any matching format.
options
can have the following
-
quality
- Video quality to download. Can be an itag value, a list of itag values, or one of these strings:highest
/lowest
/highestaudio
/lowestaudio
/highestvideo
/lowestvideo
.highestaudio
/lowestaudio
try to minimize video bitrate for equally good audio formats whilehighestvideo
/lowestvideo
try to minimize audio respectively. Defaults tohighest
, which prefers formats with both video and audio.A typical video's formats will be sorted in the following way using
quality: 'highest'
itag container quality codecs bitrate audio bitrate 18 mp4 360p avc1.42001E, mp4a.40.2 696.66KB 96KB 137 mp4 1080p avc1.640028 4.53MB 248 webm 1080p vp9 2.52MB 136 mp4 720p avc1.4d4016 2.2MB 247 webm 720p vp9 1.44MB 135 mp4 480p avc1.4d4014 1.1MB 134 mp4 360p avc1.4d401e 593.26KB 140 mp4 mp4a.40.2 128KB
format 18 at 360p will be chosen first since it's the highest quality format with both video and audio. If you'd like a higher quality format with both video and audio, see the section on handling separate streams.
-
filter
- Used to filter the list of formats to choose from. Can beaudioandvideo
orvideoandaudio
to filter formats that contain both video and audio,video
to filter for formats that contain video, orvideoonly
for formats that contain video and no additional audio track. Can also beaudio
oraudioonly
. You can give a filtering function that gets called with each format available. This function is given theformat
object as its first argument, and should return true if the format is preferable.1// Example with custom function. 2ytdl(url, { filter: format => format.container === 'mp4' })
-
format
- Primarily used to download specific video or audio streams. This can be a specificformat
object returned fromgetInfo
.- Supplying this option will ignore the
filter
andquality
options since the format is explicitly provided.
- Supplying this option will ignore the
1// Example of choosing a video format.
2let info = await ytdl.getInfo(videoID);
3let format = ytdl.chooseFormat(info.formats, { quality: '134' });
4console.log('Format found!', format);
ytdl.filterFormats(formats, filter)
If you'd like to work with only some formats, you can use the filter
option above.
1// Example of filtering the formats to audio only.
2let info = await ytdl.getInfo(videoID);
3let audioFormats = ytdl.filterFormats(info.formats, 'audioonly');
4console.log('Formats with only audio: ' + audioFormats.length);
ytdl.validateID(id)
Returns true if the given string satisfies YouTube's ID format.
ytdl.validateURL(url)
Returns true if able to parse out a valid video ID.
ytdl.getURLVideoID(url)
Returns a video ID from a YouTube URL. Throws an Error if it fails to parse an ID.
ytdl.getVideoID(str)
Same as the above ytdl.getURLVideoID()
, but can be called with the video ID directly, in which case it returns it. This is what ytdl uses internally.
Throws an Error if it fails to parse an ID.
ytdl.version
The version string taken directly from the package.json.
Limitations
ytdl cannot download videos that fall into the following
- Regionally restricted (requires a proxy)
- Private (if you have access, requires cookies)
- Rentals (if you have access, requires cookies)
- YouTube Premium content (if you have access, requires cookies)
- Only HLS Livestreams are currently supported. Other formats will get filtered out in ytdl.chooseFormats
Generated download links are valid for 6 hours, and may only be downloadable from the same IP address.
Ratelimits
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:
- Update ytdl-core to the latest version
- Use proxies (you can find an example here)
- Extend on the Proxy Idea by rotating (IPv6-)Addresses
- read this for more information about this
- Use cookies (you can find an example here)
- for this to take effect you have to FIRST wait for the current ratelimit to expire
- Wait it out (it usually goes away within a few days)
How does using an IPv6 block help?
For request-intensive tasks it might be useful to spread your requests across multiple source IP-Addresses. Changing the source IP that you use is similar to using a proxy, except without bypassing restrictions such as a region lock. More IP-Addresses result in less requests per IP and therefor increase your ratelimit. Since IPv4 Addresses are a limited Resource we advise to use IPv6.
Using an IPv6 block is essentially having millions of IPv6 addresses at your request. In a /64 IPv6 block (which is usually the Block given to a single Household), there are 18,446,744,073,709,551,616 unique IPv6 addresses. This would allow you to make each request with a different IPv6 address.
Even though using an IP-Block does help against ratelimits it requires you to setup your host system to accept http traffic from every message in an IP-Block. We can not help you with the setup for any specific host / hosting provider but searching the internet most likely can.
Handling Separate Streams
Typically 1080p or better videos do not have audio encoded with it. The audio must be downloaded separately and merged via an encoding library. ffmpeg
is the most widely used tool, with many Node.js modules available. Use the format
objects returned from ytdl.getInfo
to download specific streams to combine to fit your needs. Look at example/ffmpeg.js for an example on doing this.
What if it stops working?
YouTube updates their website all the time, it's not that rare for this to stop working. If it doesn't work for you and you're using the latest version, feel free to open up an issue. Make sure to check if there isn't one already with the same error.
Run the tests at test/irl-test.js
to make sure this is really an issue with ytdl-core.
npm run test:irl
These tests are not mocked, they try to start downloading a few videos. If these fail, then it's time to debug. If the error you're getting is signature deciphering, check lib/sig.js
. Otherwise, the error is likely within lib/info.js
.
Install
1npm install ytdl-core@latest
Or for Yarn users:
1yarn add ytdl-core@latest
Make sure you're installing the latest version of ytdl-core to keep up with the latest fixes.
If you're using a bot or app that uses ytdl-core such as ytdl-core-discord or discord-player, it may be dependent on an older version. To update its ytdl-core version, that library has to update its package.json
file, you can't simply change the version on your project's package.json
, the app will still use its own older version of ytdl-core.
Look in their repo to see if they already have an active pull request that updates ytdl-core. If they don't, open an issue asking them to update ytdl-core, or better yet, fork the project and submit a pull request with the updated version.
While you wait for the pull reques to merge, you can point to its branch in your package.json
1 "ytdl-core-discord": "amishshah/ytdl-core-discord#dependabot/npm_and_yarn/ytdl-core-2.0.1"
Update Checks
The 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
Related Projects
- ytdl - A cli wrapper of this.
- pully - Another cli wrapper of this aimed at high quality formats.
- ytsr - YouTube video search results.
- ytpl - YouTube playlist and channel resolver.
Tests
Tests are written with mocha
1npm test
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 17/26 approved changesets -- score normalized to 6
Reason
dependency not pinned by hash detected -- score normalized to 1
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/daily-test.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/fent/node-ytdl-core/daily-test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/daily-test.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/fent/node-ytdl-core/daily-test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/lint.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/fent/node-ytdl-core/lint.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/lint.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/fent/node-ytdl-core/lint.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/fent/node-ytdl-core/nodejs.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/fent/node-ytdl-core/nodejs.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/nodejs.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/fent/node-ytdl-core/nodejs.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/fent/node-ytdl-core/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/fent/node-ytdl-core/release.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/daily-test.yml:26
- Warn: npmCommand not pinned by hash: .github/workflows/lint.yml:16
- Warn: npmCommand not pinned by hash: .github/workflows/nodejs.yml:24
- Info: 0 out of 8 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 1 out of 4 npmCommand dependencies pinned
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/daily-test.yml:1
- Warn: no topLevel permission defined: .github/workflows/lint.yml:1
- Warn: no topLevel permission defined: .github/workflows/nodejs.yml:1
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 28 are checked with a SAST tool
Reason
18 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
Score
3.1
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to ytdl-core
@distube/ytdl-core
DisTube fork of ytdl-core. YouTube video downloader in pure javascript.
@rafateoli/discord-ytdl-core
Simple ytdl wrapper for discord bots with custom ffmpeg args support.
ytdl-core-red1ul
YouTube video downloader in pure javascript.
@spacepumpkin/ytdl-core
YouTube video downloader in pure javascript.