From 5c72463c029804c85479d2c4426397d932c88ee1 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 20 Sep 2020 18:59:04 +0200 Subject: Add comments and trusted/remake colors to nyaa.si torrents --- src/Body.cpp | 27 ++++++++++++++++++++++++++- src/plugins/NyaaSi.cpp | 15 ++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Body.cpp b/src/Body.cpp index 2579d64..73c3932 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -11,6 +11,31 @@ const sf::Color front_color(43, 45, 47); const sf::Color back_color(33, 35, 37); namespace QuickMedia { + BodyItem::BodyItem(std::string _title): visible(true), dirty(true), background_color(front_color) { + set_title(std::move(_title)); + } + + BodyItem::BodyItem(const BodyItem &other) { + title = other.title; + description = other.description; + url = other.url; + thumbnail_url = other.thumbnail_url; + attached_content_url = other.attached_content_url; + author = other.author; + visible = other.visible; + dirty = other.dirty; + if(other.title_text) + title_text = std::make_unique(*other.title_text); + else + title_text = nullptr; + if(other.description_text) + description_text = std::make_unique(*other.description_text); + else + description_text = nullptr; + replies = other.replies; + post_number = other.post_number; + } + Body::Body(Program *program, sf::Font *font, sf::Font *bold_font) : program(program), font(font), @@ -305,7 +330,7 @@ namespace QuickMedia { //item_pos.x += selected_border_width; item_background.setFillColor(sf::Color(0, 85, 119)); } else { - item_background.setFillColor(front_color); + item_background.setFillColor(item->background_color); } item_pos.x = std::floor(item_pos.x); diff --git a/src/plugins/NyaaSi.cpp b/src/plugins/NyaaSi.cpp index 0d43810..2ecf0d3 100644 --- a/src/plugins/NyaaSi.cpp +++ b/src/plugins/NyaaSi.cpp @@ -84,6 +84,12 @@ namespace QuickMedia { const std::string category_id_tag_end = ""; const std::string size_tag_begin = ""; const std::string size_tag_end = ""; + const std::string comments_tag_begin = ""; + const std::string comments_tag_end = ""; + const std::string trusted_tag_begin = ""; + const std::string trusted_tag_end = ""; + const std::string remake_tag_begin = ""; + const std::string remake_tag_end = ""; size_t index = 0; while(index < website_data.size()) { @@ -105,6 +111,9 @@ namespace QuickMedia { std::string downloads = get_rss_item_text(website_data, index, item_end, downloads_tag_begin, downloads_tag_end); std::string category_id = get_rss_item_text(website_data, index, item_end, category_id_tag_begin, category_id_tag_end); std::string size = get_rss_item_text(website_data, index, item_end, size_tag_begin, size_tag_end); + std::string comments = get_rss_item_text(website_data, index, item_end, comments_tag_begin, comments_tag_end); + std::string trusted = get_rss_item_text(website_data, index, item_end, trusted_tag_begin, trusted_tag_end); + std::string remake = get_rss_item_text(website_data, index, item_end, remake_tag_begin, remake_tag_end); if(title.empty() || link.empty() || pub_date.empty() || seeders.empty() || leechers.empty() || downloads.empty() || category_id.empty() || size.empty()) { fprintf(stderr, "Error: failed to parse nyaa.si rss items\n"); @@ -114,7 +123,11 @@ namespace QuickMedia { auto body_item = std::make_unique(std::move(title)); body_item->url = std::move(link); body_item->thumbnail_url = "https://nyaa.si/static/img/icons/nyaa/" + category_id + ".png"; - body_item->set_description("Published: " + pub_date + "\nSeeders: " + seeders + "\nLeechers: " + leechers + "\nDownloads: " + downloads + "\nSize: " + size); + body_item->set_description("Published: " + pub_date + "\nSeeders: " + seeders + "\nLeechers: " + leechers + "\nDownloads: " + downloads + "\nSize: " + size + "\nComments: " + comments); + if(trusted == "Yes") + body_item->background_color = sf::Color(43, 95, 47); + else if(remake == "Yes") + body_item->background_color = sf::Color(93, 45, 47); result_items.push_back(std::move(body_item)); index = item_end + 7; -- cgit v1.2.3