From cc8f50a2244256a1d619a8064b9e7f8b682a997e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 7 Aug 2019 00:29:38 +0200 Subject: Improve youtube search results --- src/plugins/Manganelo.cpp | 14 ++++++-------- src/plugins/Youtube.cpp | 28 ++++++++++++++++++---------- 2 files changed, 24 insertions(+), 18 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Manganelo.cpp b/src/plugins/Manganelo.cpp index 1989a37..3c6dd5b 100644 --- a/src/plugins/Manganelo.cpp +++ b/src/plugins/Manganelo.cpp @@ -82,14 +82,12 @@ namespace QuickMedia { if(name.isString() && name.asCString()[0] != '\0' && nameunsigned.isString() && nameunsigned.asCString()[0] != '\0') { std::string name_str = name.asString(); while(remove_html_span(name_str)) {} - if(name_str != text) { - auto item = std::make_unique(strip(name_str)); - item->url = "https://manganelo.com/manga/" + url_param_encode(nameunsigned.asString()); - Json::Value image = child.get("image", ""); - if(image.isString() && image.asCString()[0] != '\0') - item->thumbnail_url = image.asString(); - result_items.push_back(std::move(item)); - } + auto item = std::make_unique(strip(name_str)); + item->url = "https://manganelo.com/manga/" + url_param_encode(nameunsigned.asString()); + Json::Value image = child.get("image", ""); + if(image.isString() && image.asCString()[0] != '\0') + item->thumbnail_url = image.asString(); + result_items.push_back(std::move(item)); } } } diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 4ee3933..67a47e4 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -40,23 +40,21 @@ namespace QuickMedia { return result == 0 ? SearchResult::OK : SearchResult::ERR; } - static void iterate_suggestion_result(const Json::Value &value, const std::string &search_text, std::vector> &result_items) { + static void iterate_suggestion_result(const Json::Value &value, std::vector> &result_items, int &iterate_count) { + ++iterate_count; if(value.isArray()) { for(const Json::Value &child : value) { - iterate_suggestion_result(child, search_text, result_items); + iterate_suggestion_result(child, result_items, iterate_count); } - } else if(value.isString()) { + } else if(value.isString() && iterate_count > 2) { std::string title = value.asString(); - if(title != search_text) { - auto item = std::make_unique(title); - result_items.push_back(std::move(item)); - } + auto item = std::make_unique(title); + result_items.push_back(std::move(item)); } } SuggestionResult Youtube::update_search_suggestions(const std::string &text, std::vector> &result_items) { - result_items.push_back(std::make_unique(text)); - std::string url = "https://clients1.google.com/complete/search?client=youtube&hl=en&gl=us&q="; + std::string url = "https://clients1.google.com/complete/search?client=youtube&hl=en&gs_rn=64&gs_ri=youtube&ds=yt&cp=7&gs_id=x&q="; url += url_param_encode(text); std::string server_response; @@ -85,7 +83,17 @@ namespace QuickMedia { return SuggestionResult::ERR; } - iterate_suggestion_result(json_root, text, result_items); + int iterate_count = 0; + iterate_suggestion_result(json_root, result_items, iterate_count); + bool found_search_text = false; + for(auto &item : result_items) { + if(item->title == text) { + found_search_text = true; + break; + } + } + if(!found_search_text) + result_items.insert(result_items.begin(), std::make_unique(text)); return SuggestionResult::OK; } -- cgit v1.2.3