aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-08-07 00:29:38 +0200
committerdec05eba <dec05eba@protonmail.com>2019-08-07 00:29:40 +0200
commitcc8f50a2244256a1d619a8064b9e7f8b682a997e (patch)
tree88049d3b346f64fd2c0faa8fc70bb861015b948e /src/plugins
parent2ef70224b6db20cd9916063cbd720fa544f3820b (diff)
Improve youtube search results
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Manganelo.cpp14
-rw-r--r--src/plugins/Youtube.cpp28
2 files changed, 24 insertions, 18 deletions
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<BodyItem>(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<BodyItem>(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<std::unique_ptr<BodyItem>> &result_items) {
+ static void iterate_suggestion_result(const Json::Value &value, std::vector<std::unique_ptr<BodyItem>> &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<BodyItem>(title);
- result_items.push_back(std::move(item));
- }
+ auto item = std::make_unique<BodyItem>(title);
+ result_items.push_back(std::move(item));
}
}
SuggestionResult Youtube::update_search_suggestions(const std::string &text, std::vector<std::unique_ptr<BodyItem>> &result_items) {
- result_items.push_back(std::make_unique<BodyItem>(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<BodyItem>(text));
return SuggestionResult::OK;
}