From a35a344697c4ccdda0a87960d058f8ede2bb2cd2 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 7 Jun 2021 16:04:41 +0200 Subject: Add uploaded time to mangadex chapter description --- src/Utils.cpp | 9 +++++++++ src/plugins/Mangadex.cpp | 20 ++++++++++++++++---- src/plugins/Soundcloud.cpp | 8 -------- 3 files changed, 25 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Utils.cpp b/src/Utils.cpp index 3da045e..c73932b 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -104,6 +104,7 @@ namespace QuickMedia { int hour = 0; int minute = 0; int second = 0; + // TODO: Handle timezone sscanf(time_str, "%d-%d-%dT%d:%d:%d", &year, &month, &day, &hour, &minute, &second); if(year == 0) return 0; @@ -117,4 +118,12 @@ namespace QuickMedia { time.tm_sec = second; return timegm(&time); } + + std::string unix_time_to_local_time_str(time_t unix_time) { + struct tm time_tm; + localtime_r(&unix_time, &time_tm); + char time_str[128] = {0}; + strftime(time_str, sizeof(time_str) - 1, "%Y %b %d, %a %H:%M", &time_tm); + return time_str; + } } \ No newline at end of file diff --git a/src/plugins/Mangadex.cpp b/src/plugins/Mangadex.cpp index 4a10455..45e81cd 100644 --- a/src/plugins/Mangadex.cpp +++ b/src/plugins/Mangadex.cpp @@ -1,4 +1,5 @@ #include "../../plugins/Mangadex.hpp" +#include "../../include/Utils.hpp" #include namespace QuickMedia { @@ -248,22 +249,32 @@ namespace QuickMedia { if(prev_chapter && strcmp(prev_chapter, chapter_json.asCString()) == 0) continue; + const Json::Value &hash_json = attributes_json["hash"]; + if(!hash_json.isString()) + continue; + prev_chapter = chapter_json.asCString(); std::string title = "Ch. " + chapter_json.asString(); const Json::Value &title_json = attributes_json["title"]; if(title_json.isString() && title_json.asCString()[0] != '\0') title += " - " + title_json.asString(); - const Json::Value &hash_json = attributes_json["hash"]; - if(!hash_json.isString()) - continue; - const Json::Value &attributes_data_json = attributes_json["data"]; if(!attributes_data_json.isArray()) continue; auto body_item = BodyItem::create(std::move(title)); body_item->url = id_json.asString(); + + const Json::Value &publish_at_json = attributes_json["publishAt"]; + if(publish_at_json.isString()) { + time_t unix_time = iso_utc_to_unix_time(publish_at_json.asCString()); + if(unix_time != 0) { + body_item->set_description("Uploaded: " + unix_time_to_local_time_str(unix_time)); + body_item->set_description_color(sf::Color(179, 179, 179)); + } + } + std::vector image_urls; image_urls.reserve(attributes_data_json.size()); for(const Json::Value &data_item_json : attributes_data_json) { @@ -274,6 +285,7 @@ namespace QuickMedia { image_urls.push_back(std::move(url)); } chapter_image_urls[body_item->url] = std::move(image_urls); + result_items.push_back(std::move(body_item)); } diff --git a/src/plugins/Soundcloud.cpp b/src/plugins/Soundcloud.cpp index e66f1f4..01d12a8 100644 --- a/src/plugins/Soundcloud.cpp +++ b/src/plugins/Soundcloud.cpp @@ -65,14 +65,6 @@ namespace QuickMedia { return ""; } - static std::string unix_time_to_local_time_str(time_t unix_time) { - struct tm time_tm; - localtime_r(&unix_time, &time_tm); - char time_str[128] = {0}; - strftime(time_str, sizeof(time_str) - 1, "%Y %b %d, %a %H:%M", &time_tm); - return time_str; - } - static std::shared_ptr parse_collection_item(const Json::Value &item_json) { std::string title; -- cgit v1.2.3