Created
March 27, 2017 15:53
-
-
Save gngeorgiev/8b3523229eb042d7f06d0716a39ffc9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async search(substring) { | |
const url = `${SEARCH_URL}${encodeURIComponent(substring)}`; | |
const response = await fetch(url); | |
const $ = cheerio.load(await response.text()); | |
const videoElements = $(VIDEO_CLASS); | |
const getIdSelector = id => `${VIDEO_CLASS}[data-context-item-id=${id}]`; | |
return Array.from(videoElements).map((videoEl) => { | |
const id = videoEl.attribs['data-context-item-id']; | |
const idSelector = getIdSelector(id); | |
return { | |
id: id, | |
thumbnail: `https://i.ytimg.com/vi/${id}/hqdefault.jpg`, | |
title: $(idSelector).find('.yt-lockup-title > a').attr('title') | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment