utubeapi-wrap

1.1.8 • Public • Published

YouTube API Wrapper (utubeapi-wrap)

utubeapi-wrap is a JavaScript library that provides a wrapper for the YouTube Data API v3, allowing users to easily interact with the YouTube API in their applications.

Installation

To install utubeapi-wrap, use npm or yarn:

npm install utubeapi-wrap
# or
yarn add utubeapi-wrap

Usage

To use the utubeapi-wrap library in your project, import the functions from the library and provide your YouTube Data API key.

Getting Video Information

By Video ID

import { getVideoById } from 'utubeapi-wrap';

const apiKey = 'YOUR_API_KEY';
const videoId = 'VIDEO_ID';

try {
  const videoInfo = await getVideoById(videoId, apiKey);
  console.log(videoInfo);
} catch (error) {
  console.error('Error getting video information by ID:', error);
}

By Video URL

import { getVideoByUrl } from 'utubeapi-wrap';

const apiKey = 'YOUR_API_KEY';
const videoUrl = 'VIDEO_URL';

try {
  const videoInfo = await getVideoByUrl(videoUrl, apiKey);
  console.log(videoInfo);
} catch (error) {
  console.error('Error getting video information by URL:', error);
}

By Video Title

import { getVideoByTitle } from 'utubeapi-wrap';

const apiKey = 'YOUR_API_KEY';
const videoTitle = 'VIDEO_TITLE';

try {
  const videoInfo = await getVideoByTitle(videoTitle, apiKey);
  console.log(videoInfo);
} catch (error) {
  console.error('Error getting video information by title:', error);
}

Searching Videos

import { searchVideo } from 'utubeapi-wrap';

const apiKey = 'YOUR_API_KEY';
const query = 'SEARCH_QUERY';

try {
  const searchResults = await searchVideo(query, apiKey);
  console.log(searchResults);
} catch (error) {
  console.error('Error searching for videos:', error);
}

Functions

getVideoById(videoId, apiKey)

Retrieves information about a YouTube video based on its ID.

Parameters:

videoId: The ID of the YouTube video, apiKey: Your YouTube Data API key

Returns:

A promise that resolves to an object containing video information, including title, description, thumbnail URL, and channel information.

getVideoByUrl(videoUrl, apiKey)

Retrieves information about a YouTube video based on its URL.

Parameters:

videoUrl: The URL of the YouTube video, apiKey: Your YouTube Data API key

Returns:

A promise that resolves to an object containing video information, including title, description, thumbnail URL, and channel information.

getVideoByTitle(videoTitle, apiKey)

Retrieves information about a YouTube video based on its title.

Parameters:

videoTitle: The title of the YouTube video, apiKey: Your YouTube Data API key

Returns:

A promise that resolves to an object containing video information, including title, description, thumbnail URL, and channel information, or null if no matching video is found.

searchVideo(query, apiKey)

Searches for YouTube videos based on a keyword or phrase.

Parameters:

query: The search query, apiKey: Your YouTube Data API key

Returns:

A promise that resolves to an array of objects containing information about the search results. Each object includes title, description, thumbnail URL, and channel information.

Readme

Keywords

none

Package Sidebar

Install

npm i utubeapi-wrap

Weekly Downloads

0

Version

1.1.8

License

ISC

Unpacked Size

7.77 kB

Total Files

4

Last publish

Collaborators

  • neche