aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-25 20:33:16 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-25 20:33:16 +0100
commitf5d154c2d6ca848a526562bd6a678c311ee34e6b (patch)
tree86d5e5ee765a4ae118e84b812a8fe54cfbecae68 /src
parent3f0473c5aa472ac99d20a46bd7217ee9b6429f62 (diff)
Thousands comma for youtube likes/dislikes and peertube views
Diffstat (limited to 'src')
-rw-r--r--src/StringUtils.cpp20
-rw-r--r--src/plugins/Peertube.cpp2
-rw-r--r--src/plugins/Youtube.cpp24
3 files changed, 23 insertions, 23 deletions
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp
index 494e32f..8d8b62e 100644
--- a/src/StringUtils.cpp
+++ b/src/StringUtils.cpp
@@ -241,4 +241,24 @@ namespace QuickMedia {
return buffer;
}
+
+ std::string number_separate_thousand_commas(const std::string &number) {
+ const int num_commas = ((int)number.size() - 1) / 3;
+ std::string result;
+ result.resize(number.size() + num_commas);
+ int result_index = (int)number.size() + num_commas - 1;
+ int inc = 0;
+
+ for(int i = (int)number.size() - 1; i >= 0; --i, ++inc) {
+ if(inc > 0 && inc % 3 == 0) {
+ result[result_index] = ',';
+ --result_index;
+ }
+
+ result[result_index] = number[i];
+ --result_index;
+ }
+
+ return result;
+ }
} \ No newline at end of file
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));
}
}