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 --- depends/mglpp | 2 +- src/plugins/ImageBoard.cpp | 2 +- src/plugins/Youtube.cpp | 24 ++++++++++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/depends/mglpp b/depends/mglpp index a2ac8b5..8b020f5 160000 --- a/depends/mglpp +++ b/depends/mglpp @@ -1 +1 @@ -Subproject commit a2ac8b537a61fb7a7be1a3e08635ffc88e17d966 +Subproject commit 8b020f5be8fbd3741085849fccd5c958cf260d2b diff --git a/src/plugins/ImageBoard.cpp b/src/plugins/ImageBoard.cpp index 3b7850b..b027b9e 100644 --- a/src/plugins/ImageBoard.cpp +++ b/src/plugins/ImageBoard.cpp @@ -2,7 +2,7 @@ namespace QuickMedia { void ImageBoardThreadPage::copy_to_clipboard(const BodyItem *body_item) { - set_clipboard(body_item->get_description()); + set_clipboard(body_item->get_title()); } PluginResult ImageBoardThreadPage::login(const std::string &token, const std::string &pin, std::string &response_msg) { 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