UNPKG

oto-scraper

Version:

multi scraper

25 lines (22 loc) 921 B
const axios = require('axios'); const { youtube } = require('../src/Constants') async function yt_search_fetch(query, searchType = 'VIDEO', requestedLang) { if(requestedLang && typeof requestedLang !== 'string') { throw new TypeError("The request language property was not a string while a valid IANA language subtag is expected."); } youtube.YouTubeURL.pathname = "results" youtube.YouTubeURL.search = new URLSearchParams({ search_query: query, sp: youtube.SearchTypes[searchType.toUpperCase()] || youtube.SearchTypes["VIDEO"] }); return new Promise((resolve, reject) => { axios({ method: 'get', url: youtube.YouTubeURL.href, headers: { 'Accept-Language': requestedLang } }).then((response) => resolve(response.data)).catch((e) => reject(e)); }) } module.exports = yt_search_fetch;