From 9d4879215bb7b3b89122a930f86248cc405536a1 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 13 Sep 2020 17:47:51 +0200 Subject: Add description to mangadex search result, add youtube timestamp --- src/plugins/Mangadex.cpp | 13 +++++++++++++ src/plugins/Mangatown.cpp | 2 +- src/plugins/Youtube.cpp | 18 +++++++++++++----- 3 files changed, 27 insertions(+), 6 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Mangadex.cpp b/src/plugins/Mangadex.cpp index 853f501..7688355 100644 --- a/src/plugins/Mangadex.cpp +++ b/src/plugins/Mangadex.cpp @@ -213,6 +213,19 @@ namespace QuickMedia { } }, &body_item_image_context); + body_item_image_context.index = 0; + result = quickmedia_html_find_nodes_xpath(&html_search, "//div[class='pl-1']", + [](QuickMediaHtmlNode *node, void *userdata) { + auto *item_data = (BodyItemImageContext*)userdata; + const char *text = quickmedia_html_node_get_text(node); + if(text && item_data->index < item_data->body_items->size()) { + std::string desc = strip(text); + std::replace_if(desc.begin(), desc.end(), [](int c) { return c == '\n'; }, ' '); + (*item_data->body_items)[item_data->index]->set_description(std::move(desc)); + item_data->index++; + } + }, &body_item_image_context); + cleanup: quickmedia_html_search_deinit(&html_search); return result == 0 ? SuggestionResult::OK : SuggestionResult::ERR; diff --git a/src/plugins/Mangatown.cpp b/src/plugins/Mangatown.cpp index 8dcf8d3..cb3217b 100644 --- a/src/plugins/Mangatown.cpp +++ b/src/plugins/Mangatown.cpp @@ -33,7 +33,7 @@ namespace QuickMedia { int chapter_num = result_items.size(); for(auto &body_item : result_items) { - body_item->title = "Ch. " + std::to_string(chapter_num); + body_item->set_title("Ch. " + std::to_string(chapter_num)); chapter_num--; } diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 46128ec..3b4a752 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -62,11 +62,8 @@ namespace QuickMedia { auto body_item = std::make_unique(title); /* TODO: Make date a different color */ - /* TODO: Do not append to title, messes up history.. */ - /*if(date) { - body_item->title += '\n'; - body_item->title += date; - }*/ + if(date) + body_item->set_description(date); body_item->url = "https://www.youtube.com/watch?v=" + video_id_str; body_item->thumbnail_url = std::move(thumbnail_url); added_videos.insert(video_id_str); @@ -447,6 +444,14 @@ namespace QuickMedia { std::string thumbnail_url = "https://img.youtube.com/vi/" + video_id_str + "/hqdefault.jpg"; + const char *date = nullptr; + const Json::Value &published_time_text_json = compact_video_renderer_json["publishedTimeText"]; + if(published_time_text_json.isObject()) { + const Json::Value &text_json = published_time_text_json["simpleText"]; + if(text_json.isString()) + date = text_json.asCString(); + } + const char *title = nullptr; const Json::Value &title_json = compact_video_renderer_json["title"]; if(title_json.isObject()) { @@ -460,6 +465,9 @@ namespace QuickMedia { return nullptr; auto body_item = std::make_unique(title); + /* TODO: Make date a different color */ + if(date) + body_item->set_description(date); body_item->url = "https://www.youtube.com/watch?v=" + video_id_str; body_item->thumbnail_url = std::move(thumbnail_url); added_videos.insert(video_id_str); -- cgit v1.2.3