From f5d154c2d6ca848a526562bd6a678c311ee34e6b Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 25 Nov 2021 20:33:16 +0100 Subject: Thousands comma for youtube likes/dislikes and peertube views --- src/plugins/Peertube.cpp | 2 +- src/plugins/Youtube.cpp | 24 ++---------------------- 2 files changed, 3 insertions(+), 23 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Peertube.cpp b/src/plugins/Peertube.cpp index 2e7fec4..3e23807 100644 --- a/src/plugins/Peertube.cpp +++ b/src/plugins/Peertube.cpp @@ -101,7 +101,7 @@ namespace QuickMedia { const Json::Value &views_json = data_json["views"]; if(views_json.isInt()) - description += std::to_string(views_json.asInt()) + " view" + (views_json.asInt() == 1 ? "" : "s"); + description += number_separate_thousand_commas(std::to_string(views_json.asInt())) + " view" + (views_json.asInt() == 1 ? "" : "s"); const Json::Value published_at_json = data_json["publishedAt"]; if(published_at_json.isString()) { diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 42659b7..46b2376 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -2274,26 +2274,6 @@ namespace QuickMedia { return result_items; } - static std::string views_separate_with_commas(const std::string &views) { - const int num_commas = ((int)views.size() - 1) / 3; - std::string result; - result.resize(views.size() + num_commas); - int result_index = (int)views.size() + num_commas - 1; - int inc = 0; - - for(int i = (int)views.size() - 1; i >= 0; --i, ++inc) { - if(inc > 0 && inc % 3 == 0) { - result[result_index] = ','; - --result_index; - } - - result[result_index] = views[i]; - --result_index; - } - - return result; - } - static int64_t round_double(double value) { return value + 0.5; } @@ -2303,7 +2283,7 @@ namespace QuickMedia { std::string description; if(!video_details.views.empty()) { - description = views_separate_with_commas(video_details.views) + " view" + (video_details.views == "1" ? "" : "s"); + description = number_separate_thousand_commas(video_details.views) + " view" + (video_details.views == "1" ? "" : "s"); } if(!video_details.rating.empty()) { @@ -2315,7 +2295,7 @@ namespace QuickMedia { } else { fprintf(stderr, "video rating: %s\n", video_details.rating.c_str()); int64_t num_dislikes = round_double((double)likes * ((5.0 - atof(video_details.rating.c_str())) / 5.0)); - description += "👍 " + std::to_string(likes) + " 👎 " + std::to_string(num_dislikes); + description += "👍 " + number_separate_thousand_commas(std::to_string(likes)) + " 👎 " + number_separate_thousand_commas(std::to_string(num_dislikes)); } } -- cgit v1.2.3