{"id":13430506,"url":"https://github.com/fent/node-ytdl-core","last_synced_at":"2025-05-13T00:19:38.735Z","repository":{"id":38382349,"uuid":"21333232","full_name":"fent/node-ytdl-core","owner":"fent","description":"YouTube video downloader in javascript.","archived":false,"fork":false,"pushed_at":"2024-08-13T19:21:25.000Z","size":23123,"stargazers_count":4648,"open_issues_count":126,"forks_count":849,"subscribers_count":91,"default_branch":"master","last_synced_at":"2025-05-09T10:55:12.930Z","etag":null,"topics":["node","scraper","video-downloader","youtube","youtube-downloader"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-06-29T22:06:35.000Z","updated_at":"2025-05-07T13:54:43.000Z","dependencies_parsed_at":"2024-09-22T20:33:40.644Z","dependency_job_id":"3004b8cd-0b4e-4e27-a95b-06bea5993746","html_url":"https://github.com/fent/node-ytdl-core","commit_stats":{"total_commits":1022,"total_committers":89,"mean_commits":11.48314606741573,"dds":"0.19667318982387472","last_synced_commit":"0d3f91b424e81aa79fc2ec021d921d4d21f3e6ef"},"previous_names":[],"tags_count":187,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fent%2Fnode-ytdl-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fent%2Fnode-ytdl-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fent%2Fnode-ytdl-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fent%2Fnode-ytdl-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fent","download_url":"https://codeload.github.com/fent/node-ytdl-core/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253843545,"owners_count":21972930,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["node","scraper","video-downloader","youtube","youtube-downloader"],"created_at":"2024-07-31T02:00:54.680Z","updated_at":"2025-05-13T00:19:38.694Z","avatar_url":"https://github.com/fent.png","language":"JavaScript","funding_links":[],"categories":["HTML","JavaScript"],"sub_categories":[],"readme":"\u003e [!IMPORTANT]  \n\u003e 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!  \n\u003e Best Regards TFAN, 2024-08-13\n\n# node-ytdl-core\n\n![Depfu](https://img.shields.io/depfu/fent/node-ytdl-core)\n[![codecov](https://codecov.io/gh/fent/node-ytdl-core/branch/master/graph/badge.svg)](https://codecov.io/gh/fent/node-ytdl-core)\n[![Discord](https://img.shields.io/discord/484464227067887645.svg)](https://discord.gg/V3vSCs7)\n\nYet another YouTube downloading module. Written with only Javascript and a node-friendly streaming interface.\n\n# Support\nYou can contact us for support on our [chat server](https://discord.gg/V3vSCs7)\n\n# Usage\n\n```js\nconst fs = require('fs');\nconst ytdl = require('ytdl-core');\n// TypeScript: import ytdl from 'ytdl-core'; with --esModuleInterop\n// TypeScript: import * as ytdl from 'ytdl-core'; with --allowSyntheticDefaultImports\n// TypeScript: import ytdl = require('ytdl-core'); with neither of the above\n\nytdl('http://www.youtube.com/watch?v=aqz-KE-bpKQ')\n  .pipe(fs.createWriteStream('video.mp4'));\n```\n\n\n# API\n### ytdl(url, [options])\n\nAttempts to download a video from the given url. Returns a [readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable). `options` can have the following, in addition to any [`getInfo()` option](#async-ytdlgetinfourl-options) and [`chooseFormat()` option](#ytdlchooseformatformats-options).\n\n* `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.\n  * This downloads a portion of the file, and not a separately spliced video.\n* `begin` - What time in the video to begin. Supports formats `00:00:00.000`, `0ms, 0s, 0m, 0h`, or number of milliseconds. Example: `1:30`, `05:10.123`, `10m30s`.\n  * For live videos, this also accepts a unix timestamp or Date object, and defaults to `Date.now()`.\n  * This option is not very reliable for non-live videos, see [#129](https://github.com/fent/node-ytdl-core/issues/129) and [#219](https://github.com/fent/node-ytdl-core/issues/219).\n* `liveBuffer` - How much time buffer to use for live videos in milliseconds. Default is `20000`.\n* `highWaterMark` - How much of the video download to buffer into memory. See [node's docs](https://nodejs.org/api/stream.html#stream_constructor_new_stream_writable_options) for more. Defaults to 512KB.\n* `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.\n* `IPv6Block` - IPv6 block to rotate through, an alternative to using a proxy. [Read more](#how-does-using-an-ipv6-block-help). Defaults to `undefined`.\n\n#### Event: info\n* [`ytdl.videoInfo`](typings/index.d.ts#L235) - Info.\n* [`ytdl.videoFormat`](typings/index.d.ts#L32) - Video Format.\n\nEmitted when the video's `info` is fetched, along with the chosen format to download.\n\n#### Event: progress\n* `number` - Chunk length in bytes or segment number.\n* `number` - Total bytes or segments downloaded.\n* `number` - Total bytes or segments.\n\nEmitted whenever a new chunk is received. Passes values describing the download progress.\n\n#### miniget events\n\nAll [miniget events](https://github.com/fent/node-miniget#event-redirect) are forwarded and can be listened to from the returned stream.\n\n### Stream#destroy()\n\nCall to abort and stop downloading a video.\n\n### async ytdl.getBasicInfo(url, [options])\n\nUse this if you only want to get metainfo from a video.\n\n### async ytdl.getInfo(url, [options])\n\nGets metainfo from a video. Includes additional formats, and ready to download deciphered URL. This is what the `ytdl()` function uses internally.\n\n`options` can have the following\n\n* `requestOptions` - Anything to merge into the request options which [miniget](https://github.com/fent/node-miniget) is called with, such as `headers`.\n* `requestCallback` - Provide a callback function that receives miniget request stream objects used while fetching metainfo.\n* `lang` - The 2 character symbol of a language. Default is `en`.\n\n### ytdl.downloadFromInfo(info, options)\n\nOnce you have received metadata from a video with the `ytdl.getInfo` function, you may pass that information along with other options to this function.\n\n### ytdl.chooseFormat(formats, options)\n\nCan be used if you'd like to choose a format yourself. Throws an Error if it fails to find any matching format.\n\n`options` can have the following\n\n* `quality` - Video quality to download. Can be an [itag value](http://en.wikipedia.org/wiki/YouTube#Quality_and_formats), 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 while `highestvideo`/`lowestvideo` try to minimize audio respectively. Defaults to `highest`, which prefers formats with both video and audio.\n\n  A typical video's formats will be sorted in the following way using `quality: 'highest'`\n  ```\n  itag container quality codecs                 bitrate  audio bitrate\n  18   mp4       360p    avc1.42001E, mp4a.40.2 696.66KB 96KB\n  137  mp4       1080p   avc1.640028            4.53MB\n  248  webm      1080p   vp9                    2.52MB\n  136  mp4       720p    avc1.4d4016            2.2MB\n  247  webm      720p    vp9                    1.44MB\n  135  mp4       480p    avc1.4d4014            1.1MB\n  134  mp4       360p    avc1.4d401e            593.26KB\n  140  mp4               mp4a.40.2                       128KB\n  ```\n  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](#handling-separate-streams).\n* `filter` - Used to filter the list of formats to choose from. Can be `audioandvideo` or `videoandaudio` to filter formats that contain both video and audio, `video` to filter for formats that contain video, or `videoonly` for formats that contain video and no additional audio track. Can also be `audio` or `audioonly`. You can give a filtering function that gets called with each format available. This function is given the `format` object as its first argument, and should return true if the format is preferable.\n  ```js\n  // Example with custom function.\n  ytdl(url, { filter: format =\u003e format.container === 'mp4' })\n  ```\n* `format` - Primarily used to download specific video or audio streams. This can be a specific `format` object returned from `getInfo`.\n  * Supplying this option will ignore the `filter` and `quality` options since the format is explicitly provided.\n\n```js\n// Example of choosing a video format.\nlet info = await ytdl.getInfo(videoID);\nlet format = ytdl.chooseFormat(info.formats, { quality: '134' });\nconsole.log('Format found!', format);\n```\n\n### ytdl.filterFormats(formats, filter)\n\nIf you'd like to work with only some formats, you can use the [`filter` option above](#ytdlurl-options).\n\n```js\n// Example of filtering the formats to audio only.\nlet info = await ytdl.getInfo(videoID);\nlet audioFormats = ytdl.filterFormats(info.formats, 'audioonly');\nconsole.log('Formats with only audio: ' + audioFormats.length);\n```\n\n### ytdl.validateID(id)\n\nReturns true if the given string satisfies YouTube's ID format.\n\n### ytdl.validateURL(url)\n\nReturns true if able to parse out a valid video ID.\n\n### ytdl.getURLVideoID(url)\n\nReturns a video ID from a YouTube URL.\nThrows an Error if it fails to parse an ID.\n\n### ytdl.getVideoID(str)\n\nSame 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.\nThrows an Error if it fails to parse an ID.\n\n### ytdl.version\n\nThe version string taken directly from the package.json.\n\n## Limitations\n\nytdl cannot download videos that fall into the following\n* Regionally restricted (requires a [proxy](example/proxy.js))\n* Private (if you have access, requires [cookies](example/cookies.js))\n* Rentals (if you have access, requires [cookies](example/cookies.js))\n* YouTube Premium content (if you have access, requires [cookies](example/cookies.js))\n* Only [HLS Livestreams](https://en.wikipedia.org/wiki/HTTP_Live_Streaming) are currently supported. Other formats will get filtered out in ytdl.chooseFormats\n\nGenerated download links are valid for 6 hours, and may only be downloadable from the same IP address.\n\n### Ratelimits\nWhen 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:\n* Update ytdl-core to the latest version\n* Use proxies (you can find an example [here](https://github.com/fent/node-ytdl-core/blob/master/example/proxy.js))\n* Extend on the Proxy Idea by rotating (IPv6-)Addresses\n  * read [this](#How-does-using-an-IPv6-block-help?) for more information about this\n* Use cookies (you can find an example [here](https://github.com/fent/node-ytdl-core/blob/master/example/cookies.js))\n  * for this to take effect you have to FIRST wait for the current ratelimit to expire\n* Wait it out (it usually goes away within a few days)\n\n#### How does using an IPv6 block help?\n\nFor 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.\n\nUsing 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.\n\nEven 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.\n\n## Handling Separate Streams\n\nTypically 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](https://www.npmjs.com/search?q=ffmpeg). Use the `format` objects returned from `ytdl.getInfo` to download specific streams to combine to fit your needs. Look at [example/ffmpeg.js](example/ffmpeg.js) for an example on doing this.\n\n## What if it stops working?\n\nYouTube 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.\n\nRun the tests at `test/irl-test.js` to make sure this is really an issue with ytdl-core.\n\n    npm run test:irl\n\nThese 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`.\n\n# Install\n\n```bash\nnpm install ytdl-core@latest\n```\n\nOr for Yarn users:\n```bash\nyarn add ytdl-core@latest\n```\n\nMake sure you're installing the latest version of ytdl-core to keep up with the latest fixes.\n\nIf you're using a bot or app that uses ytdl-core such as [ytdl-core-discord](https://github.com/amishshah/ytdl-core-discord) or [discord-player](https://github.com/Androz2091/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.\n\nLook 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.\n\nWhile you wait for the pull reques to merge, you can point to its branch in your `package.json`\n\n```json\n  \"ytdl-core-discord\": \"amishshah/ytdl-core-discord#dependabot/npm_and_yarn/ytdl-core-2.0.1\"\n```\n\n## Update Checks\n\nThe 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.\n\nIf you'd like to disable this update check, you can do so by providing the `YTDL_NO_UPDATE` env variable.\n\n```\nenv YTDL_NO_UPDATE=1 node myapp.js\n```\n\n# Related Projects\n\n- [ytdl](https://github.com/fent/node-ytdl) - A cli wrapper of this.\n- [pully](https://github.com/JimmyBoh/pully) - Another cli wrapper of this aimed at high quality formats.\n- [ytsr](https://github.com/TimeForANinja/node-ytsr) - YouTube video search results.\n- [ytpl](https://github.com/TimeForANinja/node-ytpl) - YouTube playlist and channel resolver.\n\n\n# Tests\nTests are written with [mocha](https://mochajs.org)\n\n```bash\nnpm test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffent%2Fnode-ytdl-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffent%2Fnode-ytdl-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffent%2Fnode-ytdl-core/lists"}