aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-08-15 21:05:26 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-15 21:05:26 +0200
commitb81c8a0698a9421e315c97804652d974b5205c29 (patch)
tree0a79f2c73ddf345448c036a3f5a751e62282b3cd /src
parent356c5e185e947905b7da7ab36a2e77a95845074a (diff)
Limit storing of recommendations from related videos for watched video to 3
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp46
1 files changed, 28 insertions, 18 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index c1886f3..884f29f 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -456,6 +456,10 @@ namespace QuickMedia {
body_item->url = "https://www.youtube.com/watch?v=" + recommended_item_id;
body_item->thumbnail_url = "https://img.youtube.com/vi/" + recommended_item_id + "/hqdefault.jpg";
body_items.push_back(std::move(body_item));
+
+ // We dont want more than 30 recommendations
+ if(body_items.size() == 30)
+ break;
}
}
@@ -1025,6 +1029,26 @@ namespace QuickMedia {
save_json_to_file_atomic(video_history_filepath, video_history_json);
Json::Value recommended_json = load_recommended_json(current_plugin);
+
+ Json::Value &existing_recommended_json = recommended_json[video_id];
+ if(existing_recommended_json.isObject()) {
+ int64_t watched_count = 0;
+ Json::Value &watched_count_json = existing_recommended_json["watched_count"];
+ if(watched_count_json.isNumeric())
+ watched_count = watched_count_json.asInt64();
+ existing_recommended_json["watched_count"] = watched_count + 1;
+ existing_recommended_json["watched_timestamp"] = time_now;
+ } else {
+ Json::Value new_content_object(Json::objectValue);
+ new_content_object["title"] = content_title;
+ new_content_object["recommended_timestamp"] = time_now;
+ new_content_object["recommended_count"] = 1;
+ new_content_object["watched_count"] = 1;
+ new_content_object["watched_timestamp"] = time_now;
+ recommended_json[video_id] = std::move(new_content_object);
+ }
+
+ int saved_recommendation_count = 0;
for(const auto &body_item : related_media) {
std::string recommended_video_id;
if(youtube_url_extract_id(body_item->url, recommended_video_id)) {
@@ -1042,30 +1066,16 @@ namespace QuickMedia {
new_content_object["recommended_timestamp"] = time_now;
new_content_object["recommended_count"] = 1;
recommended_json[recommended_video_id] = std::move(new_content_object);
+ saved_recommendation_count++;
+ /* TODO: Save more than the first 3 video that hasn't been watched yet? */
+ if(saved_recommendation_count == 3)
+ break;
}
} else {
fprintf(stderr, "Failed to extract id of youtube url %s, video wont be saved in recommendations\n", content_url.c_str());
}
}
- Json::Value &existing_recommended_json = recommended_json[video_id];
- if(existing_recommended_json.isObject()) {
- int64_t watched_count = 0;
- Json::Value &watched_count_json = existing_recommended_json["watched_count"];
- if(watched_count_json.isNumeric())
- watched_count = watched_count_json.asInt64();
- existing_recommended_json["watched_count"] = watched_count + 1;
- existing_recommended_json["watched_timestamp"] = time_now;
- } else {
- Json::Value new_content_object(Json::objectValue);
- new_content_object["title"] = content_title;
- new_content_object["recommended_timestamp"] = time_now;
- new_content_object["recommended_count"] = 1;
- new_content_object["watched_count"] = 1;
- new_content_object["watched_timestamp"] = time_now;
- recommended_json[video_id] = std::move(new_content_object);
- }
-
save_json_to_file_atomic(get_recommended_filepath(current_plugin), recommended_json);
}
};