1.2.3 • Published 4 years ago
yt-video v1.2.3
yt-video
A simple library for getting a video search from YouTube! Here's how it works:
Installation
Run the following command on the console:
> npm i yt-video --save
Usage
First, you need to get a YouTube API key on this page
Options
You can pass options to the search
method, such as to change result ordering, video duration, etc. They are all listed on this page
Code examples
JavaScript
const ytVideo = require('yt-video');
// Create options
let options = {
order: 'relevance',
safeSearch: 'moderate',
videoLicense: 'creativeCommon',
};
// Search for video "cute cats" with your API key
ytVideo('cute cats', process.env.API_KEY, options)
.then((result) => {
if (!result) {
console.log('No video was found');
} else {
console.log('Video found!');
console.log(`Video title: ${result.title}`);
}
})
.catch((err) => {
console.error(err);
});
TypeScript
import ytVideo, { SearchOptions } from './lib/index';
// Create options
let options: SearchOptions = {
order: 'relevance',
safeSearch: 'moderate',
videoLicense: 'creativeCommon',
};
// Search for video "cute cats" with your API key
search('cute cats', process.env.API_KEY, options)
.then((result) => {
if (!result) {
console.log('No video was found');
} else {
console.log('Video found!');
console.error(`Video title: ${result.title}`);
}
})
.catch((err) => {
console.error(err);
});