A Node.js package for YouTube API videos.
Install the package using npm:
npm install kyle-yt
const KyleYT = require('kyle-yt');
const kyleYT = new KyleYT();
// Example usage: search for a video
kyleYT.search('The Weeknd - Save Your Tears (Official Music Video)').then(result => {
let video = result.items[0];
console.log('Id: ' + video.id);
console.log('Url: ' + video.url);
console.log('Name: ' + video.name);
console.log('Views: ' + video.views);
}).catch(error => {
console.error('Error:', error);
});
Searches YouTube for videos based on the given query.
-
query
: The search query string. -
options
: An optional object containing search options.-
limit
: The maximum number of videos to return (default is 1).
-
Returns a Promise that resolves to an object containing an array of video items. Each video item has a url
property representing the URL of the video.
Helper function to extract video information from the HTML response.
-
htmlBody
: The HTML body of the response from YouTube search. -
limit
: The maximum number of videos to extract.
Returns an array of video objects containing their URLs.
const KyleYT = require('kyle-yt');
const kyleYT = new KyleYT();
const videoURL = 'https://www.youtube.com/watch?v=jNQXAC9IVRw';
const filename = 'video.mp4';
kyleYT.download(videoURL, filename)
.then(() => {
console.log('Video downloaded successfully! 🎉');
})
.catch(error => {
console.error('An error occurred while downloading the video:', error);
});
const KyleYT = require('kyle-yt');
const kyleYT = new KyleYT();
kyleYT.search('The Weeknd - Save Your Tears (Official Music Video)').then(result => {
let video = result.items[0];
console.log('Id: ' + video.id);
console.log('Url: ' + video.url);
console.log('Name: ' + video.name);
console.log('Views: ' + video.views);
}).catch(error => {
console.error('Error:', error);
});