{"id":13447519,"url":"https://github.com/przemyslawpluta/node-youtube-dl","last_synced_at":"2025-10-02T17:30:42.095Z","repository":{"id":53100860,"uuid":"2135514","full_name":"przemyslawpluta/node-youtube-dl","owner":"przemyslawpluta","description":"youtube-dl driver for node","archived":true,"fork":false,"pushed_at":"2021-04-06T18:54:36.000Z","size":2079,"stargazers_count":1706,"open_issues_count":43,"forks_count":368,"subscribers_count":56,"default_branch":"master","last_synced_at":"2024-09-24T08:21:56.731Z","etag":null,"topics":["node","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/przemyslawpluta.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-08-01T07:19:22.000Z","updated_at":"2024-09-12T13:19:01.000Z","dependencies_parsed_at":"2022-08-31T08:11:28.015Z","dependency_job_id":null,"html_url":"https://github.com/przemyslawpluta/node-youtube-dl","commit_stats":null,"previous_names":["fent/node-youtube-dl"],"tags_count":75,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/przemyslawpluta%2Fnode-youtube-dl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/przemyslawpluta%2Fnode-youtube-dl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/przemyslawpluta%2Fnode-youtube-dl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/przemyslawpluta%2Fnode-youtube-dl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/przemyslawpluta","download_url":"https://codeload.github.com/przemyslawpluta/node-youtube-dl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219875833,"owners_count":16554706,"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","video-downloader","youtube","youtube-downloader"],"created_at":"2024-07-31T05:01:19.877Z","updated_at":"2025-10-02T17:30:36.743Z","avatar_url":"https://github.com/przemyslawpluta.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","youtube-downloader"],"sub_categories":[],"readme":"# youtube-dl \n# **Deprecate notice**: use [youtube-dl-exec](https://github.com/microlinkhq/youtube-dl-exec) instead.\n\n[![Build Status](https://travis-ci.org/przemyslawpluta/node-youtube-dl.svg?branch=master)](https://travis-ci.org/przemyslawpluta/node-youtube-dl) [![npm version](https://badge.fury.io/js/youtube-dl.svg)](https://badge.fury.io/js/youtube-dl)\n\nDownload videos from youtube in node.js using [youtube-dl](http://rg3.github.com/youtube-dl/).\n\nIf you're only interested in downloading only from youtube, you should consider using [pure Javascript youtube downloading module](https://github.com/fent/node-ytdl).\n\n## Installation\n\nWith [npm](https://www.npmjs.com/) do:\n\n``` sh\nnpm install youtube-dl\n```\n\n## Usage\n\n### Downloading videos\n\n``` js\nconst fs = require('fs')\nconst youtubedl = require('youtube-dl')\n\nconst video = youtubedl('http://www.youtube.com/watch?v=90AiXO1pAiA',\n  // Optional arguments passed to youtube-dl.\n  ['--format=18'],\n  // Additional options can be given for calling `child_process.execFile()`.\n  { cwd: __dirname })\n\n// Will be called when the download starts.\nvideo.on('info', function(info) {\n  console.log('Download started')\n  console.log('filename: ' + info._filename)\n  console.log('size: ' + info.size)\n})\n\nvideo.pipe(fs.createWriteStream('myvideo.mp4'))\n```\n\nIt will produce an output that looks like the following when ran.\n\n```bash\nGot video info\nsaving to T-ara - Number Nine - MV - 티아라-Seku9G1kT0c.mp4\n100.00%\n```\n\n### Resuming partially downloaded videos\n\n``` js\nconst youtubedl = require('youtube-dl')\nconst fs = require('fs')\nconst output = 'myvideo.mp4'\n\nlet downloaded = 0\n\nif (fs.existsSync(output)) {\n  downloaded = fs.statSync(output).size\n}\n\nconst video = youtubedl('https://www.youtube.com/watch?v=179MiZSibco',\n\n  // Optional arguments passed to youtube-dl.\n  ['--format=18'],\n\n  // start will be sent as a range header\n  { start: downloaded, cwd: __dirname })\n\n// Will be called when the download starts.\nvideo.on('info', function(info) {\n  console.log('Download started')\n  console.log('filename: ' + info._filename)\n\n  // info.size will be the amount to download, add\n  let total = info.size + downloaded\n  console.log('size: ' + total)\n\n  if (downloaded \u003e 0) {\n    // size will be the amount already downloaded\n    console.log('resuming from: ' + downloaded)\n\n    // display the remaining bytes to download\n    console.log('remaining bytes: ' + info.size)\n  }\n})\n\nvideo.pipe(fs.createWriteStream(output, { flags: 'a' }))\n\n// Will be called if download was already completed and there is nothing more to download.\nvideo.on('complete', function complete(info) {\n  'use strict'\n  console.log('filename: ' + info._filename + ' already downloaded.')\n})\n\nvideo.on('end', function() {\n  console.log('finished downloading!')\n})\n```\n\nIt will produce an output that looks like the following when ran.\n\n**Output:**\n\n``` sh\n[~/nodejs/node-youtube-dl/example]$ node resume.js\nDownload started\nfilename: 1 1 1-179MiZSibco.mp4\nsize: 5109213\n^C\n```\n\n``` sh\n[~/nodejs/node-youtube-dl/example]$ node resume.js\nDownload started\nfilename: 1 1 1-179MiZSibco.mp4\nsize: 5109213\nresuming from: 917504\nremaining bytes: 4191709\nfinished downloading\n```\n\n### Getting video information\n\n``` js\nconst youtubedl = require('youtube-dl')\n\nconst url = 'http://www.youtube.com/watch?v=WKsjaOqDXgg'\n// Optional arguments passed to youtube-dl.\nconst options = ['--username=user', '--password=hunter2']\n\nyoutubedl.getInfo(url, options, function(err, info) {\n  if (err) throw err\n\n  console.log('id:', info.id)\n  console.log('title:', info.title)\n  console.log('url:', info.url)\n  console.log('thumbnail:', info.thumbnail)\n  console.log('description:', info.description)\n  console.log('filename:', info._filename)\n  console.log('format id:', info.format_id)\n})\n```\n\nRunning that will produce something like\n\n``` sh\nid: WKsjaOqDXgg\ntitle: Ace Rimmer to the Rescue\nurl: http://r5---sn-p5qlsn7e.c.youtube.com/videoplayback?ms=au\u0026ip=160.79.125.18\u0026cp=U0hWTFVQVl9FTENONl9NSlpDOjgtU1VsODlkVmRH\u0026id=58ab2368ea835e08\u0026source=youtube\u0026expire=1377558202\u0026factor=1.25\u0026key=yt1\u0026ipbits=8\u0026mt=1377534150\u0026itag=34\u0026sver=3\u0026upn=-rGWz2vYpN4\u0026fexp=912306%2C927900%2C919395%2C926518%2C936203%2C913819%2C929117%2C929121%2C929906%2C929907%2C929922%2C929127%2C929129%2C929131%2C929930%2C925726%2C925720%2C925722%2C925718%2C929917%2C906945%2C929919%2C929933%2C912521%2C932306%2C913428%2C904830%2C919373%2C930803%2C908536%2C904122%2C938701%2C936308%2C909549%2C900816%2C912711%2C904494%2C904497%2C900375%2C906001\u0026sparams=algorithm%2Cburst%2Ccp%2Cfactor%2Cid%2Cip%2Cipbits%2Citag%2Csource%2Cupn%2Cexpire\u0026mv=m\u0026burst=40\u0026algorithm=throttle-factor\u0026signature=ABD3A847684AD9B39331E567568D3FA0DCFA4776.7895521E130A042FB3625A17242CE3C02A4460B7\u0026ratebypass=yes\nthumbnail: https://i1.ytimg.com/vi/WKsjaOqDXgg/hqdefault.jpg\ndescription: An old Red Dwarf eposide where Ace Rimmer saves the Princess Bonjella.\nfilename: Ace Rimmer to the Rescue-WKsjaOqDXgg.flv\nformat id: 34\n```\n\nYou can use an array of urls to produce an array of response objects with matching array index (e.g. the 1st response object will match the first url etc...)\n\n``` js\nconst youtubedl = require('youtube-dl')\n\nconst url1 = 'http://www.youtube.com/watch?v=WKsjaOqDXgg'\nconst url2 = 'https://vimeo.com/6586873'\n\nyoutubedl.getInfo([url1, url2], function(err, info) {\n  if (err) throw err\n\n  console.log('title for the url1:', info[0].title)\n  console.log('title for the url2:', info[1].title)\n})\n```\n\n### Using a proxy\n\n``` js\nconst youtubedl = require('youtube-dl')\n\nconst video = youtubedl('http://www.youtube.com/watch?v=90AiXO1pAiA',\n  // Optional arguments passed to youtube-dl.\n  ['--proxy', 'http://ip:port'],\n```\n\n### Downloading subtitles\n\n``` js\nconst youtubedl = require('youtube-dl')\nconst url = 'https://youtu.be/PizwcirYuGY'\n\nconst options = {\n  // Write automatic subtitle file (youtube only)\n  auto: false,\n  // Downloads all the available subtitles.\n  all: false,\n  // Subtitle format. YouTube generated subtitles\n  // are available ttml or vtt.\n  format: 'ttml',\n  // Languages of subtitles to download, separated by commas.\n  lang: 'en',\n  // The directory to save the downloaded files in.\n  cwd: __dirname,\n}\n\nyoutubedl.getSubs(url, options, function(err, files) {\n  if (err) throw err\n\n  console.log('subtitle files downloaded:', files)\n})\n```\n\n### Downloading thumbnails\n\n``` js\nconst youtubedl = require('youtube-dl')\nconst url = 'https://youtu.be/PizwcirYuGY'\n\nconst options = {\n  // Downloads available thumbnail.\n  all: false,\n  // The directory to save the downloaded files in.\n  cwd: __dirname,\n}\n\nyoutubedl.getThumbs(url, options, function(err, files) {\n  if (err) throw err\n\n  console.log('thumbnail file downloaded:', files)\n})\n```\n\nFor more usage info on youtube-dl and the arguments you can pass to it, do `youtube-dl -h` or go to the [youtube-dl documentation][].\n\n### Downloading playlists\n\n``` js\n\nconst path = require('path')\nconst fs   = require('fs')\nconst youtubedl = require('youtube-dl')\n\nfunction playlist(url) {\n\n  'use strict'\n  const video = youtubedl(url)\n\n  video.on('error', function error(err) {\n    console.log('error 2:', err)\n  })\n\n  let size = 0\n  video.on('info', function(info) {\n    size = info.size\n    let output = path.join(__dirname + '/', size + '.mp4')\n    video.pipe(fs.createWriteStream(output))\n  })\n\n  let pos = 0\n  video.on('data', function data(chunk) {\n    pos += chunk.length\n    // `size` should not be 0 here.\n    if (size) {\n      let percent = (pos / size * 100).toFixed(2)\n      process.stdout.cursorTo(0)\n      process.stdout.clearLine(1)\n      process.stdout.write(percent + '%')\n    }\n  })\n\n  video.on('next', playlist)\n}\n\nplaylist('https://www.youtube.com/playlist?list=PLEFA9E9D96CB7F807')\n\n```\n\nNote node-youtube-dl does not currently support playlist urls with the \"list\" format:\n```\nhttps://www.youtube.com/watch?v=\u003cvideo-id\u003e\u0026list=\u003cplaylist id\u003e\n```\nPlease use instead the equivalent \"playlist\" format as the example below:\n```\nhttps://www.youtube.com/playlist?list=\u003cplaylist id\u003e\n```\nThe following snippet could be of use when making this format conversion.\n```\nfunction toSupportedFormat(url) {\n    if (url.includes(\"list=\")) {\n        var playlistId = url.substring(url.indexOf('list=') + 5);\n        return \"https://www.youtube.com/playlist?list=\" + playlistId;\n    }\n    return url;\n}\n\nvar url = \"https://www.youtube.com/watch?v=shF8Sv-OswM\u0026list=PLzIUZKHPb1HbqsPMIFdE0My54iektZrNU\"\nurl = toSupportedFormat(url);\nconsole.log(url) // \"https://www.youtube.com/playlist?list=PLzIUZKHPb1HbqsPMIFdE0My54iektZrNU\"\n```\n\n### Getting the list of extractors\n\n``` js\nconst youtubedl = require('youtube-dl')\n\nyoutubedl.getExtractors(true, function(err, list) {\n  console.log('Found ' + list.length + ' extractors')\n\n  for (let i = 0 i \u003c list.length i++) {\n    console.log(list[i])\n  }\n})\n```\n\nWill print something like\n\n``` sh\nFound 521 extractors\n1up.com\n220.ro\n24video\n3sat\n```\n\n### Getting the binary path\n\n``` js\nconst youtubedl = require('youtube-dl')\n\nconsole.log(youtubedl.getYtdlBinary())\n```\n\n### Changing the binary path\n\n```js\nconst path = require('path')\nconst youtubedl = require('youtube-dl')\n\nconst customBinaryPath = path.resolve('custom/path/to-binary')\n\nyoutubedl.setYtdlBinary(customBinaryPath)\n```\n\n### Call the `youtube-dl` binary directly\n\nThis module doesn't have `youtube-dl` download the video. Instead, it uses the `url` key from the `--dump-json` CLI option to create a node stream. That way, it can be used like any other node stream.\n\nIf that, or none of the above support your use case, you can use `youtubedl.exec()` to call `youtube-dl` however you like.\n\n``` js\nconst youtubedl = require('youtube-dl')\n\nyoutubedl.exec(url, ['-x', '--audio-format', 'mp3'], {}, function(err, output) {\n  if (err) throw err\n\n  console.log(output.join('\\n'))\n})\n```\n\n### Update\n\nSince the youtube-dl binary is updated regularly, you can run `npm run update` to check for and download any updates for it. You can also require `youtube-dl/lib/downloader` in your app if you'd like to place `youtube-dl` binary in a specific directory and control when it gets updates.\n\n``` js\nconst downloader = require('youtube-dl/lib/downloader')\n\ndownloader('path/to-binary', function error(err, done) {\n  'use strict'\n  if (err) throw err\n\n  console.log(done)\n})\n```\n\nThis script parses a couple of flags from `argv`:\n\n* `--platform=windows` forces downloading the Windows version of youtube-dl.\n* `--overwrite` overwrites the existing youtube-dl executable if it exists.\n\n\n### Update (promise version)\n\nIf you are using promises there's now a promise version, if you don't pass a function as second argument:\n\n``` js\nconst downloader = require('youtube-dl/lib/downloader')\n\ndownloader('path/to-binary')\n.then((message) =\u003e {\n    console.log(message);\n}).catch((err) =\u003e {\n    console.log(\"err\", err);\n    exit(1);\n});\n\n```\n\n\n### Environment Variables\n\nYoutube-dl looks for certain environment variables to aid its operations. If Youtube-dl doesn't find them in the environment during the installation step, a lowercased variant of these variables will be used from the [npm config](https://docs.npmjs.com/cli/config) or [yarn config](https://yarnpkg.com/lang/en/docs/cli/config/).\n\n- **YOUTUBE\\_DL\\_DOWNLOAD\\_HOST** - overwrite URL prefix that is used to download the binary file of Youtube-dl. Note: this includes protocol and might even include path prefix. Defaults to `https://yt-dl.org/downloads/latest/youtube-dl`.\n\n### Tests\n\nTests are written with [vows](http://vowsjs.org/)\n\n``` sh\nnpm test\n```\n\n## License\n\nMIT\n\n[youtube-dl]: http://rg3.github.com/youtube-dl/\n[youtube-dl documentation]: http://rg3.github.com/youtube-dl/documentation.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprzemyslawpluta%2Fnode-youtube-dl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprzemyslawpluta%2Fnode-youtube-dl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprzemyslawpluta%2Fnode-youtube-dl/lists"}