diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/HotExamples.cpp | 3 | ||||
-rw-r--r-- | src/plugins/Saucenao.cpp | 43 |
2 files changed, 31 insertions, 15 deletions
diff --git a/src/plugins/HotExamples.cpp b/src/plugins/HotExamples.cpp index a049101..043ddfd 100644 --- a/src/plugins/HotExamples.cpp +++ b/src/plugins/HotExamples.cpp @@ -100,7 +100,8 @@ namespace QuickMedia { if(text.data) { std::string title(text.data, text.size); html_unescape_sequences(title); - string_replace_all(title, "Project:", " Project:"); + string_replace_all(title, "File:", "File: "); + string_replace_all(title, "Project:", " Project: "); auto item = BodyItem::create(std::move(title)); //item->url.assign(href.data, href.size); diff --git a/src/plugins/Saucenao.cpp b/src/plugins/Saucenao.cpp index ccb01f9..b99c028 100644 --- a/src/plugins/Saucenao.cpp +++ b/src/plugins/Saucenao.cpp @@ -1,6 +1,7 @@ #include "../../plugins/Saucenao.hpp" #include "../../plugins/Info.hpp" #include "../../include/StringUtils.hpp" +#include "../../include/Theme.hpp" #include <quickmedia/HtmlSearch.h> namespace QuickMedia { @@ -34,7 +35,8 @@ namespace QuickMedia { static void match_node_get_urls(QuickMediaHtmlNode *node, std::vector<std::string> &urls) { if(node->is_tag && string_views_equal_case_insensitive(node->name, {"a", 1}) == 0) { QuickMediaHtmlAttribute *attr = get_attribute_by_name(node, {"href", 4}); - if(attr) + // Ignore saucenao info pages + if(attr && !memmem(attr->value.data, attr->value.size, "saucenao.com", 12)) urls.emplace_back(attr->value.data, attr->value.size); } @@ -45,14 +47,6 @@ namespace QuickMedia { } } - static std::string get_first_line(const std::string &str) { - const size_t line_end = str.find('\n'); - if(line_end == std::string::npos) - return str; - else - return str.substr(0, line_end); - } - PluginResult SaucenaoPage::submit(const std::string &title, const std::string&, std::vector<Tab> &result_tabs) { if(!submit_body_item) return PluginResult::OK; @@ -61,11 +55,9 @@ namespace QuickMedia { BodyItems body_items; for(const std::string &url : urls->urls) { - // Ignore saucenao info pages - if(url.find("saucenao.com") == std::string::npos) - body_items.push_back(InfoPage::add_url(url)); + body_items.push_back(InfoPage::add_url(url)); } - body_items.push_back(InfoPage::add_google_search(get_first_line(title))); + body_items.push_back(InfoPage::add_google_search(title)); auto body = create_body(); body->set_items(std::move(body_items)); @@ -100,9 +92,32 @@ namespace QuickMedia { if(p_index != std::string::npos) title = title.erase(0, p_index + 1); title = strip(title); - auto item = BodyItem::create(title); + + std::string description; + const size_t title_line_end = title.find('\n'); + if(title_line_end != std::string::npos) { + description = title.substr(title_line_end + 1); + title.erase(title_line_end); + } + auto urls = std::make_shared<SaucenaoBodyItemUrls>(); match_node_get_urls(node->node, urls->urls); + if(!urls->urls.empty()) { + if(!description.empty()) + description += "\n\n"; + + int index = 0; + for(const std::string &url : urls->urls) { + if(index > 0) + description += '\n'; + description += url; + ++index; + } + } + + auto item = BodyItem::create(std::move(title)); + item->set_description(std::move(description)); + item->set_description_color(get_theme().faded_text_color); item->extra = std::move(urls); item_data->push_back(std::move(item)); } |