diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-01-21 17:49:27 -0600 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-01-21 17:49:27 -0600 |
| commit | cf49306ffb0a18984dc99066cc0bc7381fd2749c (patch) | |
| tree | ba92ef5af4e92e48d51ec5f414a38c4fa62606ea /src/helpers.cr | |
| parent | 1a4fbce5e5f3371785459270d1fd0a94761c31b8 (diff) | |
| download | invidious-cf49306ffb0a18984dc99066cc0bc7381fd2749c.tar.gz invidious-cf49306ffb0a18984dc99066cc0bc7381fd2749c.tar.bz2 invidious-cf49306ffb0a18984dc99066cc0bc7381fd2749c.zip | |
Fix index out of bounds error
Diffstat (limited to 'src/helpers.cr')
| -rw-r--r-- | src/helpers.cr | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/helpers.cr b/src/helpers.cr index d2186d6c..1a6037a5 100644 --- a/src/helpers.cr +++ b/src/helpers.cr @@ -64,3 +64,22 @@ def get_video(id, refresh = true) return video end + +def search(query) + client = get_client + + html = client.get("https://www.youtube.com/results?q=#{query}&sp=EgIQAVAU").body + html = XML.parse_html(html) + + html.xpath_nodes(%q(//ol[@class="item-section"]/li)).each do |item| + root = item.xpath_node(%q(div[contains(@class,"yt-lockup-video")]/div)) + if root + link = root.xpath_node(%q(div[contains(@class,"yt-lockup-thumbnail")]/a/@href)) + if link + yield link.content.split("=")[1] + end + end + end + + POOL << client +end |
