From 40693c88eba9d4bb86688b5b59c91308828830c1 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 2 Dec 2021 02:51:03 +0100 Subject: Youtube: better rating ratio for videos with rating disabled --- src/plugins/Youtube.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 3d10a4c..8ffaebf 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -2290,20 +2290,17 @@ namespace QuickMedia { if(!description.empty()) description += " • "; - fprintf(stderr, "like/dislike ratio: %s\n", video_details.rating.c_str()); + double average_rating = atof(video_details.rating.c_str()); + // Minimum rating for a video is 1.0, even if a video only has dislikes + average_rating -= 1.0; + if(average_rating < 0.00000001) + average_rating = 0.00000001; if(num_likes == -1) { - description += "rated " + video_details.rating.substr(0, 4) + "/5"; + description += "rated " + std::to_string(average_rating / 4.0 * 5.0).substr(0, 4) + "/5.0"; } else { - double average_rating = atof(video_details.rating.c_str()); - // Minimum rating for a video is 1.0, even if a video only has dislikes - average_rating -= 1.0; - if(average_rating < 0.00000001) - average_rating = 0.00000001; - const int64_t num_ratings = num_likes * (4.0 / average_rating); const int64_t num_dislikes = (num_ratings - num_likes); - description += "👍 " + number_separate_thousand_commas(std::to_string(num_likes)) + " 👎 " + number_separate_thousand_commas(std::to_string(num_dislikes)); } } -- cgit v1.2.3