you-stream-js
v1.0.2
Published
A library to fetch YouTube video streams.
Downloads
197
Maintainers
Readme
You Stream
You Stream is a simple and efficient JavaScript library for fetching YouTube video streams. It allows you to retrieve audio and video formats, get the best quality streams, and manage adaptive formats with ease.
Table of Contents
Features
- Fetch the best audio and video streams from YouTube videos.
- Retrieve all available adaptive formats.
- Get specific format information using its
itag
. - Lightweight and easy to use.
Installation
You can install you-stream via npm:
npm install you-stream-js
Usage
Here's how to use the you-stream library to get the best audio and video streams from a YouTube video.
Import the Library
const { getBestAudio, getBestVideo, getAllAdaptiveFormats, getFormatInfoByItag } = require('you-stream-js');
API Methods
getBestAudio(videoID)
- Fetches the best available audio stream for the specified video ID.
- Parameters:
videoID
(string): The ID of the YouTube video. - Returns: An object containing the best audio stream URL and its
itag
.
getBestVideo(videoID)
- Fetches the best available video stream for the specified video ID.
- Parameters:
videoID
(string): The ID of the YouTube video. - Returns: An object containing the best video stream URL and its
itag
.
getAllAdaptiveFormats(videoID)
- Retrieves all adaptive formats available for the specified video.
- Parameters:
videoID
(string): The ID of the YouTube video. - Returns: An array of all adaptive formats.
getFormatInfoByItag(videoID, itag)
- Gets the format information based on the specified
itag
. - Parameters:
videoID
(string): The ID of the YouTube video.itag
(number): Theitag
of the desired format.
- Returns: The format information or a message indicating that the format was not found.
- Gets the format information based on the specified
Example
Here’s an example demonstrating how to use the library:
const { getBestAudio, getBestVideo, getAllAdaptiveFormats, getFormatInfoByItag } = require('you-stream-js');
const videoID = 'YOUR_VIDEO_ID_HERE'; // Replace with a valid YouTube video ID
async function example() {
try {
const bestAudio = await getBestAudio(videoID);
console.log('Best Audio:', bestAudio);
const bestVideo = await getBestVideo(videoID);
console.log('Best Video:', bestVideo);
const allFormats = await getAllAdaptiveFormats(videoID);
console.log('All Adaptive Formats:', allFormats);
const formatInfo = await getFormatInfoByItag(videoID, 140);
console.log('Format Info for itag 140:', formatInfo);
} catch (error) {
console.error('Error:', error);
}
}
example();
Testing
To run the tests provided in test.js
, you can execute the following command:
node test.js
Make sure to replace YOUR_VIDEO_ID_HERE
with a valid YouTube video ID in the test.js
file for testing.
Contributing
Contributions are welcome! If you have suggestions or improvements, please fork the repository and submit a pull request.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes.
- Commit your changes (
git commit -m 'Add new feature'
). - Push to the branch (
git push origin feature-branch
). - Open a pull request.
Acknowledgments
- Inspired by yt-dlp for extracting YouTube streams.
- Thanks to YouTube Data API for providing a way to interact with YouTube data.