aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-04-28 17:41:58 +0200
committerdec05eba <dec05eba@protonmail.com>2021-04-28 17:42:02 +0200
commit7d0d8a1bf0ffbaf073303efc7d7bfc58177277a6 (patch)
treebad9198e5800d4569a0941d3648723da4cbf263e /src/plugins
parent1b7abc7e819d055b3d0ea5be8967a1e381bb5d60 (diff)
Calculate subscription uploaded time difference correctly when taking timezone into consideration
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp3
-rw-r--r--src/plugins/Youtube.cpp17
2 files changed, 7 insertions, 13 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 4a414da..6af5e6e 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -3742,7 +3742,8 @@ namespace QuickMedia {
if(num_joined_members_json.IsInt()) {
if(!description.empty())
description += '\n';
- description += ("👤" + std::to_string(num_joined_members_json.GetInt()) + " users");
+ const int num_joined_numbers = num_joined_members_json.GetInt();
+ description += ("👤" + std::to_string(num_joined_numbers) + " user" + (num_joined_numbers == 1 ? "" : "s"));
}
room_body_item->set_description(std::move(description));
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index 9e07400..4c4372e 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -1230,7 +1230,9 @@ namespace QuickMedia {
}
// Returns relative time as a string (approximation)
- static std::string timestamp_to_relative_time_str(time_t seconds) {
+ static std::string seconds_to_relative_time_str(time_t seconds) {
+ seconds = std::max(0L, seconds);
+
time_t minutes = seconds / 60;
time_t hours = minutes / 60;
time_t days = hours / 24;
@@ -1322,22 +1324,13 @@ namespace QuickMedia {
time.tm_hour = hour;
time.tm_min = minute;
time.tm_sec = second;
- time_t unixtime = mktime(&time);
-
- struct tm entry_time;
- localtime_r(&unixtime, &entry_time);
- time_t unixtime_local = mktime(&entry_time);
- subscription_data_list.back().subscription_entry.published = unixtime_local;
+ subscription_data_list.back().subscription_entry.published = timegm(&time);
}
}, &subscription_data_list);
html_parser_parse(&html_parser);
html_parser_deinit(&html_parser);
- /*std::sort(subscription_data_list.begin(), subscription_data_list.end(), [](const SubscriptionData &sub_data1, const SubscriptionData &sub_data2) {
- return sub_data1.subscription_entry.published > sub_data2.subscription_entry.published;
- });*/
-
std::vector<YoutubeSubscriptionTaskResult> results;
for(SubscriptionData &subscription_data : subscription_data_list) {
if(subscription_data.subscription_entry.title.empty() || subscription_data.subscription_entry.video_id.empty() || subscription_data.subscription_entry.published == 0)
@@ -1345,7 +1338,7 @@ namespace QuickMedia {
html_unescape_sequences(subscription_data.subscription_entry.title);
auto body_item = BodyItem::create(std::move(subscription_data.subscription_entry.title));
- body_item->set_description("Uploaded " + timestamp_to_relative_time_str(time_now - subscription_data.subscription_entry.published));
+ body_item->set_description("Uploaded " + seconds_to_relative_time_str(time_now - subscription_data.subscription_entry.published));
body_item->set_description_color(sf::Color(179, 179, 179));
body_item->url = "https://www.youtube.com/watch?v=" + subscription_data.subscription_entry.video_id;
body_item->thumbnail_url = "https://img.youtube.com/vi/" + subscription_data.subscription_entry.video_id + "/hqdefault.jpg";