abhishek-ytsearch
v1.0.0
Published
A package for searching YouTube using @neeraj-x0/ytsearch
Downloads
15
Readme
node-ytsearch
Simple JS-only package to search for YouTube for Videos, Playlists, and many more. Does not require any login or Google-API-Key.
Usage
const ytsearch = require('abhishek-ytsearch');
const searchResults = await ytsearch('github');
API
ytsearch(searchString, [options])
Searches for the given string
- searchString: Search string or URL (from getFilters) to search from
- options: Object with options
- gl[String]: 2-Digit Code of a Country, defaults to US - Allows for localisation of the request
- hl[String]: 2-Digit Code for a Language, defaults to en - Allows for localisation of the request
- safeSearch[Boolean]: Pull items in YouTube restriction mode.
- limit[integer]: Limits the pulled items, defaults to 100, set to Infinity to get the whole list of search results - numbers <1 result in the default being used
- pages[Number]: Limits the pulled pages, pages contain 20-30 items, set to Infinity to get the whole list of search results - numbers <1 result in the default limit being used - overwrites limit
- requestOptions[Object]: Additional parameters to pass to miniget, which is used to do the HTTPS requests
- Returns a Promise
ytsearch.getFilters(searchString, options)
Pulls available filters for the given string or link
Usage
const ytsearch = require('abhishek-ytsearch');
const filters1 = await ytsearch.getFilters('github');
const filter1 = filters1.get('Type').get('Video');
const filters2 = await ytsearch.getFilters(filter1.url);
const filter2 = filters2.get('Features').get('Live');
const options = {
pages: 2,
}
const searchResults = await ytsearch(filter2.url, options);
- searchString: String to search for or previously obtained filter ref
- options:
- gl[String]: 2-Digit Code of a Country, defaults to US - Allows for localisation of the request
- hl[String]: 2-Digit Code for a Language, defaults to en - Allows for localisation of the request
- requestOptions[Object]: Additional parameters to pass to miniget, which is used to do the HTTPS requests
- Returns a Promise resulting in a Map<String, Map<String, Filter>>
ytsearch.continueReq(continuationData)
Continues a previous request by pulling yet another page. The previous request had to be done using pages limitation.
Usage
const ytsearch = require('abhishek-ytsearch');
const firstResultBatch = await ytsearch('github', { pages: 1 });
const secondResultBatch = ytsearch.continueReq(firstResultBatch.continuation);
const thirdResultBatch = ytsearch.continueReq(secondResultBatch.continuation);
// You can now use the .items property of all result batches e.g.:
console.log(firstResultBatch.items);
console.log(secondResultBatch.items);
console.log(thirdResultBatch.items);
- Returns a Promise resolving into
{ continuation, items }
Install
npm install --save abhishek-ytsearch