From 7f538cf8187ca8107696ec22406aef1d44fe04e3 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 18 Nov 2021 12:59:58 +0100 Subject: Fix crash when going to ctrl+r when first page is youtube video (starting quickmedia with a youtube url), better youtube video description --- src/plugins/Youtube.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/plugins/Youtube.cpp') diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 8dabd2d..8e08062 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -2167,18 +2167,38 @@ 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 std::shared_ptr video_details_to_body_item(const YoutubeVideoDetails &video_details) { auto body_item = BodyItem::create(video_details.title); std::string description; if(!video_details.views.empty()) { - description = video_details.views + " view" + (video_details.views == "1" ? "" : "s"); + description = views_separate_with_commas(video_details.views) + " view" + (video_details.views == "1" ? "" : "s"); } if(!video_details.rating.empty()) { if(!description.empty()) description += " • "; - description += "rated " + video_details.rating + "/5"; + description += "rated " + video_details.rating.substr(0, 4) + "/5"; } if(!video_details.author.empty()) { -- cgit v1.2.3