aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/Manganelo.hpp2
-rw-r--r--plugins/Plugin.hpp2
-rw-r--r--plugins/Youtube.hpp2
-rw-r--r--src/QuickMedia.cpp4
-rw-r--r--src/plugins/Manganelo.cpp14
-rw-r--r--src/plugins/Youtube.cpp28
6 files changed, 32 insertions, 20 deletions
diff --git a/plugins/Manganelo.hpp b/plugins/Manganelo.hpp
index 0f6f421..01311e1 100644
--- a/plugins/Manganelo.hpp
+++ b/plugins/Manganelo.hpp
@@ -9,6 +9,8 @@ namespace QuickMedia {
SuggestionResult update_search_suggestions(const std::string &text, std::vector<std::unique_ptr<BodyItem>> &result_items) override;
ImageResult get_image_by_index(const std::string &url, int index, std::string &image_data);
ImageResult get_number_of_images(const std::string &url, int &num_images);
+ bool search_suggestions_has_thumbnails() const override { return true; }
+ bool search_results_has_thumbnails() const override { return true; }
private:
// Caches url. If the same url is requested multiple times then the cache is used
ImageResult get_image_urls_for_chapter(const std::string &url);
diff --git a/plugins/Plugin.hpp b/plugins/Plugin.hpp
index 6d5a986..3df53ca 100644
--- a/plugins/Plugin.hpp
+++ b/plugins/Plugin.hpp
@@ -47,6 +47,8 @@ namespace QuickMedia {
virtual SearchResult search(const std::string &text, std::vector<std::unique_ptr<BodyItem>> &result_items, Page &next_page) = 0;
virtual SuggestionResult update_search_suggestions(const std::string &text, std::vector<std::unique_ptr<BodyItem>> &result_items);
virtual std::vector<std::unique_ptr<BodyItem>> get_related_media(const std::string &url);
+ virtual bool search_suggestions_has_thumbnails() const = 0;
+ virtual bool search_results_has_thumbnails() const = 0;
protected:
std::string url_param_encode(const std::string &param) const;
};
diff --git a/plugins/Youtube.hpp b/plugins/Youtube.hpp
index c342a10..25a97c3 100644
--- a/plugins/Youtube.hpp
+++ b/plugins/Youtube.hpp
@@ -8,5 +8,7 @@ namespace QuickMedia {
SearchResult search(const std::string &text, std::vector<std::unique_ptr<BodyItem>> &result_items, Page &next_page) override;
SuggestionResult update_search_suggestions(const std::string &text, std::vector<std::unique_ptr<BodyItem>> &result_items) override;
std::vector<std::unique_ptr<BodyItem>> get_related_media(const std::string &url) override;
+ bool search_suggestions_has_thumbnails() const override { return false; }
+ bool search_results_has_thumbnails() const override { return false; }
};
} \ No newline at end of file
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 649b56c..7f7bb1c 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -89,11 +89,11 @@ namespace QuickMedia {
window.close();
break;
case Page::SEARCH_SUGGESTION:
- body->draw_thumbnails = true;
+ body->draw_thumbnails = current_plugin->search_suggestions_has_thumbnails();
search_suggestion_page();
break;
case Page::SEARCH_RESULT:
- body->draw_thumbnails = true;
+ body->draw_thumbnails = current_plugin->search_results_has_thumbnails();
search_result_page();
break;
case Page::VIDEO_CONTENT:
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;
}