browserify-ytdl-core
browserify-ytdl-core is a TypeScript library designed to interact with the YT Data API and download video content from YT. The library is primarily intended for browser environments and features powerful functionalities such as retrieving basic information, video downloading, format selection, and more.
Installation
To use the library, you can install it via npm or yarn:
npm install browserify-ytdl-core
yarn add browserify-ytdl-core
Usage
Retrieve Basic Information
import ytdl from 'browserify-ytdl-core';
const videoUrl = 'https://www.youtube.com/watch?v=your_video_id';
ytdl.getBasicInfo(videoUrl)
.then((info) => {
console.log('Video Title:', info.videoDetails.title);
console.log('Author:', info.videoDetails.author);
console.log('Views:', info.videoDetails.viewCount);
})
.catch((error) => {
console.error('Error:', error.message);
});
Download Video
import ytdl from 'browserify-ytdl-core';
import fs from 'fs';
const videoUrl = 'https://www.youtube.com/watch?v=your_video_id';
const outputFilePath = 'path/to/save/video.mp4';
const options = {
quality: 'highest',
};
const videoStream = ytdl(videoUrl, options);
videoStream.pipe(fs.createWriteStream(outputFilePath));
videoStream.on('end', () => {
console.log('Download complete.');
});
videoStream.on('error', (error) => {
console.error('Download error:', error.message);
});
API
getBasicInfo(url: string, options?: ytdl.getInfoOptions): Promise<ytdl.videoInfo>
Retrieve basic information about a video from a YT URL.
ytdl(url: string, options?: ytdl.downloadOptions): Readable
Download a video from a YT URL with specified options. Returns a Readable stream.
chooseFormat(format: ytdl.videoFormat | ytdl.videoFormat[], options?: ytdl.chooseFormatOptions): ytdl.videoFormat | never
Choose a video format based on specified options.
filterFormats(formats: ytdl.videoFormat | ytdl.videoFormat[], filter?: ytdl.Filter): ytdl.videoFormat[]
Filter video formats based on the given filter.
validateID(string: string): boolean
Check the validity of a video ID.
validateURL(string: string): boolean
Check the validity of a video URL.
getURLVideoID(string: string): string | never
Get the video ID from a URL.
getVideoID(string: string): string | never
Get the video ID from a string.
version: number
The library version.
Additional Information
For more detailed information on usage and additional features, please refer to the official documentation of browserify-ytdl-core.
Contributions
If you encounter issues or have suggestions, please create an issue on GitHub. We welcome contributions from the community to enhance this library.