From 65cf7681a04f2511db8c7829e9828b53a6676c88 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 2 Aug 2019 20:08:27 +0200 Subject: Convert to sfml, starting on manganelo and youtube --- src/Youtube.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/Youtube.cpp (limited to 'src/Youtube.cpp') diff --git a/src/Youtube.cpp b/src/Youtube.cpp new file mode 100644 index 0000000..d8b046f --- /dev/null +++ b/src/Youtube.cpp @@ -0,0 +1,34 @@ +#include "../plugins/Youtube.hpp" +#include + +namespace QuickMedia { + SearchResult Youtube::search(const std::string &text, std::vector> &result_items) { + std::string url = "https://youtube.com/results?search_query="; + // TODO: Escape @text + url += text; + + std::string website_data; + if(download_to_string(url, website_data) != DownloadResult::OK) + return SearchResult::NET_ERR; + + QuickMediaHtmlSearch html_search; + int result = quickmedia_html_search_init(&html_search, website_data.c_str()); + if(result != 0) + goto cleanup; + + result = quickmedia_html_find_nodes_xpath(&html_search, "//h3[class=\"yt-lockup-title\"]/a", + [](QuickMediaHtmlNode *node, void *userdata) { + auto *result_items = (std::vector>*)userdata; + const char *href = quickmedia_html_node_get_attribute_value(node, "href"); + const char *title = quickmedia_html_node_get_attribute_value(node, "title"); + printf("a href: %s, title: %s\n", href, title); + + auto item = std::make_unique(title); + result_items->push_back(std::move(item)); + }, &result_items); + + cleanup: + quickmedia_html_search_deinit(&html_search); + return result == 0 ? SearchResult::OK : SearchResult::ERR; + } +} \ No newline at end of file -- cgit v1.2.3