Package Exports
- @ytdl/ytdl
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ytdl/ytdl) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ytdl
ytdl provides a library to integrate a Youtube Downloader for Node.js
projects, and a CLI to download content from Youtube.
Contents
Installation
Library
Via npm
npm install @ytdl/ytdl
CLI
Via npm
npm install @ytdl/ytdl -g
Via curl
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ytdl-node/ytdl/master/bin/install)"
Via wget
sh -c "$(wget -O- https://raw.githubusercontent.com/ytdl-node/ytdl/master/bin/install)"
Via commands
git clone https://github.com/ytdl-node/ytdl.git
cd ytdl
npm install
./bin/ytdl -h
API
Example
const ytdl = require('@ytdl/ytdl').default;
ytdl('https://www.youtube.com/watch?v=fJ9rUzIMcZQ', '480p', 'ytdl.mp4');
OR
const ytdl = require('@ytdl/ytdl');
ytdl.ytdl('https://www.youtube.com/watch?v=fJ9rUzIMcZQ', '480p', 'ytdl.mp4');
ytdl.ytdl(url, quality, path[, options])
Note:
ytdl.ytdl(...)
is also the default export (ytdl.default(...)
).
const ytdl = require('@ytdl/ytdl');
ytdl.ytdl('https://www.youtube.com/watch?v=fJ9rUzIMcZQ', '720p', 'video.mp4');
- This function first searches for a stream which has both audio and video in it. If it doesn't find it, it will search for a separate audio and video stream and combine it using ffmpeg.
Currently ytdl uses the fluent-ffmpeg package which requires ffmpeg to be installed on the computer.
options:
- audioOnly: true | false
- videoOnly: true | false
audioOnly (Download only audio stream)
const ytdl = require('@ytdl/ytdl');
ytdl.ytdl('https://www.youtube.com/watch?v=fJ9rUzIMcZQ', 'medium', 'audio.mp3', { audioOnly: true });
// quality: 'low', 'medium', 'high', 'any'
videoOnly (Download only video stream)
Note: There will be no sound in the video.
const ytdl = require('@ytdl/ytdl');
ytdl.ytdl('https://www.youtube.com/watch?v=fJ9rUzIMcZQ', '360p', 'video.mp4', { videoOnly: true });
// quality: '144p', '360p', '480p', '720p', '1080p'
ytdl.downloadByItag(url, itag, path)
const ytdl = require('@ytdl/ytdl');
ytdl.downloadByItag('https://www.youtube.com/watch?v=fJ9rUzIMcZQ', 396, 'video.mp4');
ytdl.info(link)
const ytdl = require('@ytdl/ytdl');
async function getInfo (link) {
const {
videoDescription,
videoId,
videoTime,
videoTitle,
videoInfo,
} = await ytdl.info(link);
// To log the time
console.log(`Video time is: ${videoTime}`);
}
getInfo('https://www.youtube.com/watch?v=fJ9rUzIMcZQ');
- This may be written without using async-await:
const ytdl = require('@ytdl/ytdl');
ytdl.info('https://www.youtube.com/watch?v=fJ9rUzIMcZQ')
.then((info) => {
const {
videoDescription,
videoId,
videoTime,
videoTitle,
videoInfo,
} = info;
// To log the time
console.log(`Video time is: ${videoTime}`);
});
CLI (ytdl)
Example
ytdl -d https://www.youtube.com/watch?v=fJ9rUzIMcZQ -fn rhapsody.mp3 -ao
Usage
Usage: ytdl [options]
Options:
-V, --version output the version number
-i, --info <url> info about YouTube link
-d, --download <url> download from YouTube link
-fn, --filename <filename> filename of downloaded content
-q, --quality <quality> quality of downloaded content
-dj, --dump-json <url> dump json into file
-ao, --audio-only download only audio stream
-vo, --video-only download only video stream
-h, --help display help for command
Contributing
Contributing guidelines have been established here.