Simple package to make YouTube search.
- Easy
- Simple
- Fast
- Lightweight
- ✅ Regular YouTube Search (Video/Channel/Playlist) (~25 items)
- ✅ Get specific video
- ✅ Get homepage contents
- ✅ Get Playlist (including all videos)
- ✅ Get Mixes
- ✅ YouTube safe search
- ✅ YouTube Trending (~50 items)
$ npm i --save @oreobot/youtube # via npm
$ yarn add @oreobot/youtube # yarn
$ pnpm add @oreobot/youtube # pnpm
const YouTube = require('@oreobot/youtube').default;
const videos = await YouTube.search('karan aujla', { limit: 3 });
console.log(videos.map((m, i) => `[${++i}] ${m.title} (${m.url})`).join('\n'));
/*
[1] SOFTLY (Official Music Video) KARAN AUJLA | IKKY | LATEST PUNJABI SONGS 2023 (https://www.youtube.com/watch?v=cWMxCE2HTag)
[2] Winning Speech (Music Video) Karan Aujla | Mxrci | Latest Punjabi Songs 2024 (https://www.youtube.com/watch?v=vsWxs1tuwDk)
[3] Admirin' You (Official Video) Karan Aujla | Ikky | Making Memories | Latest Punjabi Songs 2023 (https://www.youtube.com/watch?v=k85UB5b6pJU)
*/
Used to search videos/channels/playlists. This works like a general YouTube search.
YouTube.search('Winning Speech Karan Aujla')
.then((vids) => console.log(vids.map((m) => m.url))) // ['https://www.youtube.com/watch?v=XXXXXXX', ...]
.catch(console.error);
Similar to search but makes single search.
YouTube.searchOne('Winning Speech Karan Aujla')
.then((res) => console.log(res.url)) // https://www.youtube.com/watch?v=XXXXXXX
.catch(console.error);
Returns playlist info.
Note: Data returned by
getPlaylist
is different from the playlist data obtained bysearch
. Usinglimit
inoptions
wont fetch all videos. They are for current chunk only! UsefetchAll: true
in order to fetch all videos. >limit
withfetchAll
will limit the videos for whole playlist. However,limit
may not be always accurate.
Basic
YouTube.getPlaylist('some_youtube_playlist')
.then(console.log) // max 100 items
.catch(console.error);
Fetch all videos immediately
YouTube.getPlaylist('some_youtube_playlist', { fetchAll: true }).then(console.log).catch(console.error);
Getting all videos from a playlist at once manually
YouTube.getPlaylist('some_youtube_playlist')
.then((playlist) => playlist.fetch()) // if your playlist has 500 videos, this makes additional 4 requests to get rest of the 400 videos. (100 videos = 1 request)
.then(console.log) // all parsable videos
.catch(console.error);
Lazily getting videos from a playlist
YouTube.getPlaylist('some_youtube_playlist')
.then((playlist) => playlist.next()) // fetches next 100 items
.then(console.log) // all parsable videos
.catch(console.error);
Returns basic video info by its url.
Note: Data returned by
getVideo
is different from thesearch
.shorts
property of the video object might not be 100% accurate.
YouTube.getVideo('Some_Video_URL')
.then(console.log) // Video info
.catch(console.error);
Returns videos from the YouTube homepage.
YouTube.homepage()
.then(console.log) // videos from youtube homepage
.catch(console.error);
Returns trending videos from the YouTube.
YouTube.trending()
.then(console.log) // trending videos from youtube
.catch(console.error);
Returns youtube search suggestions.
YouTube.getSuggestions('karan aujla').then(console.log);
/*
[
'karan aujla new song',
'karan aujla',
'karan aujla song',
'karan aujla all songs',
'karan aujla podcast',
'karan aujla kapil sharma show',
'karan aujla new song 2024',
'karan aujla old songs',
'karan aujla mashup',
'karan aujla interview',
'karan aujla concert',
'karan aujla new album',
'karan aujla sad song',
'karan aujla ringtone'
]
*/
Used to validate url/id.
[
Video {
nsfw: false,
shorts: false,
unlisted: false,
id: 'cWMxCE2HTag',
title: 'SOFTLY (Official Music Video) KARAN AUJLA | IKKY | LATEST PUNJABI SONGS 2023',
description: null,
durationFormatted: '2:51',
duration: 171000,
uploadedAt: '10 months ago',
views: 230357853,
thumbnail: Thumbnail {
id: 'cWMxCE2HTag',
width: 720,
height: 404,
url: 'https://i.ytimg.com/vi/cWMxCE2HTag/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDAmmxoV3Kiaeb8CslaL5CWowbcMA'
},
channel: Channel {
name: 'Karan Aujla',
verified: true,
id: 'UC3XBkDeCVXCoCofFgfUZXGw',
url: 'https://www.youtube.com/channel/UC3XBkDeCVXCoCofFgfUZXGw',
icon: [Object],
subscribers: null
},
likes: 0,
dislikes: 0,
upcoming: false,
live: false,
private: false,
tags: [],
music: undefined
},
]
Join my discord server https://discord.gg/GaczkwfgV9