A lightweight package for retrieving data from YouTube without needing an API key.
- Fetch search results for videos, playlists, or channels by keyword.
- Retrieve paginated results for extended searches.
- Access playlist details and video information.
- Fetch channel data by channel ID.
Install the package via npm:
npm install @forkprince/youtube-search-api
Fetch a list of items based on a keyword. You can specify whether to include playlists and set a limit on the number of results.
youtube.getListByKeyword(keyword: string, playlist?: boolean, limit?: number, options?: [{ type: "string" }]);
Example:
const search = await youtube.getListByKeyword("JavaScript tutorials", true, 5, [{ type: "video" }]);
console.log(search);
Continue retrieving results using pagination.
youtube.nextPage({ token, context, continuation }, playlist?: boolean, limit?: number);
Example:
const nextPage = await youtube.nextPage(results.next, true, 5);
console.log(nextPage);
Retrieve detailed information about a playlist, including videos in the playlist.
youtube.getPlaylistData(id: string, limit?: number);
Example:
const playlist = await youtube.getPlaylistData("RDCLAK5uy_lGZNsVQescoTzcvJkcEhSjpyn_98D4lq0");
console.log(playlist);
Fetch details about a channel using its channel ID.
youtube.getChannelById(id: string);
Example:
const channel = await youtube.getChannelById("UCj-Xm8j6WBgKY8OG7s9r2vQ");
console.log(channel);
Retrieve information about a specific video.
youtube.getVideoDetails(id: string);
Example:
const video = await youtube.getVideoDetails("cC2UqBuFAEY");
console.log(video);
Here’s a complete example demonstrating how to use the package:
const youtube = require("@forkprince/youtube-search-api");
async function test() {
// Search for videos
const videos = await youtube.getListByKeyword("JSDeveloper", true, 2, [{ type: "video" }]);
console.log("Videos:", videos);
// Get the next page of results
const page2 = await youtube.nextPage(videos.next, true, 2);
console.log("Page 2:", page2);
const page3 = await youtube.nextPage(page2.next, true, 2);
console.log("Page 3:", page3);
// Get playlist data
const playlist = await youtube.getPlaylistData("RDCLAK5uy_lGZNsVQescoTzcvJkcEhSjpyn_98D4lq0");
console.log("Playlist:", playlist);
// Get channel data
const channel = await youtube.getChannelById("UCj-Xm8j6WBgKY8OG7s9r2vQ");
console.log("Channel:", channel);
// Get video details
const video = await youtube.getVideoDetails("cC2UqBuFAEY");
console.log("Video Details:", video);
}
test();
This package is licensed under the MIT License.