From 62a29abd372a39a413e43a8f75146af823fe7bb3 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 4 Aug 2019 14:58:03 +0200 Subject: Add video seek, play next video on end file --- src/Youtube.cpp | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'src/Youtube.cpp') diff --git a/src/Youtube.cpp b/src/Youtube.cpp index 85969b9..4647887 100644 --- a/src/Youtube.cpp +++ b/src/Youtube.cpp @@ -21,9 +21,11 @@ namespace QuickMedia { 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"); + if(href && title) { auto item = std::make_unique(title); - item->url = std::string("https://www.youtube.com") + href; - result_items->push_back(std::move(item)); + item->url = std::string("https://www.youtube.com") + href; + result_items->push_back(std::move(item)); + } }, &result_items); cleanup: @@ -78,4 +80,33 @@ namespace QuickMedia { iterate_suggestion_result(json_root, text, result_items); return SuggestionResult::OK; } + + std::vector> Youtube::get_related_media(const std::string &url) { + std::vector> result_items; + + std::string website_data; + if(download_to_string(url, website_data) != DownloadResult::OK) + return result_items; + + 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, "//ul[class=\"video-list\"]//div[class=\"content-wrapper\"]/a", + [](QuickMediaHtmlNode *node, void *userdata) { + auto *result_items = (std::vector>*)userdata; + const char *href = quickmedia_html_node_get_attribute_value(node, "href"); + // TODO: Also add title for related media + if(href) { + auto item = std::make_unique(""); + item->url = std::string("https://www.youtube.com") + href; + result_items->push_back(std::move(item)); + } + }, &result_items); + + cleanup: + quickmedia_html_search_deinit(&html_search); + return result_items; + } } \ No newline at end of file -- cgit v1.2.3