diff options
-rw-r--r-- | include/Utils.hpp | 2 | ||||
-rw-r--r-- | src/Utils.cpp | 9 | ||||
-rw-r--r-- | src/plugins/Mangadex.cpp | 20 | ||||
-rw-r--r-- | src/plugins/Soundcloud.cpp | 8 |
4 files changed, 27 insertions, 12 deletions
diff --git a/include/Utils.hpp b/include/Utils.hpp index 206ee38..cdef844 100644 --- a/include/Utils.hpp +++ b/include/Utils.hpp @@ -1,6 +1,7 @@ #pragma once #include <time.h> +#include <string> namespace QuickMedia { float get_ui_scale(); @@ -9,4 +10,5 @@ namespace QuickMedia { bool is_touch_enabled(); bool is_running_wayland(); time_t iso_utc_to_unix_time(const char *time_str); + std::string unix_time_to_local_time_str(time_t unix_time); }
\ No newline at end of file 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 <json/writer.h> 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<std::string> 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<BodyItem> parse_collection_item(const Json::Value &item_json) { std::string title; |