diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-08-02 20:08:27 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2019-08-02 20:08:27 +0200 |
commit | 65cf7681a04f2511db8c7829e9828b53a6676c88 (patch) | |
tree | 6e7db509cf2bce4a10fa6d8bc89a9eae88d893fa /src/Youtube.cpp | |
parent | 109c797d7c89223c9eed07dc322448b5c5fe3373 (diff) |
Convert to sfml, starting on manganelo and youtube
Diffstat (limited to 'src/Youtube.cpp')
-rw-r--r-- | src/Youtube.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
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 <quickmedia/HtmlSearch.h> + +namespace QuickMedia { + SearchResult Youtube::search(const std::string &text, std::vector<std::unique_ptr<BodyItem>> &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<std::unique_ptr<BodyItem>>*)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<BodyItem>(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 |