Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
ytdl-core
Advanced tools
The ytdl-core npm package is a YouTube video downloader that allows you to download videos from YouTube and extract information about them. It is commonly used for creating custom video downloaders, streamers, and other applications that require access to YouTube content.
Download a YouTube Video
This feature allows you to download a YouTube video by providing its URL. The video is saved to a file on your local system.
const ytdl = require('ytdl-core');
const fs = require('fs');
const videoUrl = 'https://www.youtube.com/watch?v=VIDEO_ID';
const output = 'video.mp4';
ytdl(videoUrl)
.pipe(fs.createWriteStream(output))
.on('finish', () => {
console.log('Download completed!');
});
Get Video Information
This feature allows you to retrieve detailed information about a YouTube video, such as its title, author, and view count.
const ytdl = require('ytdl-core');
const videoUrl = 'https://www.youtube.com/watch?v=VIDEO_ID';
ytdl.getInfo(videoUrl).then(info => {
console.log('Title:', info.videoDetails.title);
console.log('Author:', info.videoDetails.author.name);
console.log('Views:', info.videoDetails.viewCount);
}).catch(err => {
console.error('Error fetching video info:', err);
});
Download Audio Only
This feature allows you to download only the audio stream of a YouTube video, which is useful for creating audio files from video content.
const ytdl = require('ytdl-core');
const fs = require('fs');
const videoUrl = 'https://www.youtube.com/watch?v=VIDEO_ID';
const output = 'audio.mp3';
ytdl(videoUrl, { filter: 'audioonly' })
.pipe(fs.createWriteStream(output))
.on('finish', () => {
console.log('Audio download completed!');
});
youtube-dl is a command-line program to download videos from YouTube and other video sites. It is highly versatile and supports a wide range of video platforms. Compared to ytdl-core, youtube-dl is more feature-rich but requires a separate installation and is not a native Node.js package.
yt-dlp is a fork of youtube-dl with additional features and fixes. It offers similar functionality to youtube-dl but with more frequent updates and additional options. Like youtube-dl, it is not a native Node.js package and requires separate installation.
node-youtube-dl is a Node.js wrapper for youtube-dl. It allows you to use youtube-dl's functionality within a Node.js application. It provides similar capabilities to ytdl-core but relies on the external youtube-dl program.
Yet another youtube downloading module. This time written with only Javascript and a more node-friendly streaming interface.
For a CLI version of this, check out ytdl and pully.
var fs = require('fs');
var ytdl = require('ytdl-core');
ytdl('http://www.youtube.com/watch?v=A02s8omM_hI')
.pipe(fs.createWriteStream('video.flv'));
Attempts to download a video from the given url. Returns a readable stream. options
can have the following keys
quality
- Video quality to download. Can be an itag value value, or highest
/lowest
. Defaults to highest
.filter
- Can be video
to filter for formats that contain video, 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. Used to decide what format to download. This function is given the format
object as its first argument, and should return true if the format is preferable.format
- This can be a specific format
object returned from getInfo
. This is primarily used to download specific video or audio streams. Note: Supplying this option will ignore the filter
and quality
options since the format is explicitly provided.range
- A byte range in the form INT-INT
that specifies a part of the video to download. ie 10355705-12452856.// Example with `filter` option.
ytdl(url, { filter: function(format) { return format.container === 'mp4'; } })
.pipe(fs.createWriteStream('vide.mp4'));
The returned readable stream emits these additional events.
Object
- Info.Object
- Format.Emitted when the a video's info
hash is fetched. Along with the chosen format metadata to download. format.url
might be different if start
was given. format.size
will also be available.
Info and format may look like this.
Use this if you only want to get metainfo from a video.
options
gets passed to the request()
, it can also have a downloadURL
property set to true
if you want ytdl to include the download url instead of the regular one. In some cases, a signature needs to be deciphered, and will require ytdl to make additional requests.
Once you have received metadata from a video with the getInfo
function,
you may pass that info
, along with other options
to downloadFromInfo
.
Note: Be sure to set the downloadURL
option to true
when you call getInfo
or you will receive a 403 error when you call downloadFromInfo
.
The returned readable stream emits these additional events:
Object
- Format.Emitted when a format metadata has been chosen. format.size
will also be available.
Typically 1080p or better video does not have audio encoded with it. The audio must be downloaded separately and merged via an appropriate 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.
npm install ytdl-core
Tests are written with mocha
npm test
MIT
FAQs
YouTube video downloader in pure javascript.
The npm package ytdl-core receives a total of 103,678 weekly downloads. As such, ytdl-core popularity was classified as popular.
We found that ytdl-core demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.