aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-06-07 16:04:41 +0200
committerdec05eba <dec05eba@protonmail.com>2021-06-07 16:04:41 +0200
commita35a344697c4ccdda0a87960d058f8ede2bb2cd2 (patch)
tree682e251c57ba9079db54ee528dfa98e49f362782 /src
parentb207d812582368fea47bf87becc645fbcaf07b61 (diff)
Add uploaded time to mangadex chapter description
Diffstat (limited to 'src')
-rw-r--r--src/Utils.cpp9
-rw-r--r--src/plugins/Mangadex.cpp20
-rw-r--r--src/plugins/Soundcloud.cpp8
3 files changed, 25 insertions, 12 deletions
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;