From 86749d3fbfc6103a74cb20666d2c915c3e7bd073 Mon Sep 17 00:00:00 2001 From: blankie Date: Sun, 9 Apr 2023 15:12:05 +0700 Subject: [PATCH] Fix fetching original cover images for some user Example user: 23605419 --- pixivmodels.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pixivmodels.cpp b/pixivmodels.cpp index 5e9eab1..4e0ae08 100644 --- a/pixivmodels.cpp +++ b/pixivmodels.cpp @@ -6,7 +6,7 @@ #include "numberhelper.h" static inline std::optional get_1920x960_cover_image(blankie::murl::Url url); -static inline std::optional get_original_cover_image(blankie::murl::Url url); +static inline std::optional get_original_cover_image(blankie::murl::Url url, const nlohmann::json& cover_image); static inline std::optional get_original_profile_picture(blankie::murl::Url url); static Images get_profile_pictures(const nlohmann::json& j); static Images get_illust_image(const nlohmann::json& j); @@ -39,7 +39,7 @@ void from_json(const nlohmann::json& j, User& user) { if (j.contains("cover_image") && j["cover_image"].is_object()) { nlohmann::json cover_image = j["cover_image"]; std::string c_720x360 = cover_image.at("profile_cover_image").at("720x360").get(); - std::optional original = get_original_cover_image(c_720x360); + std::optional original = get_original_cover_image(c_720x360, cover_image); std::optional c_1920x960 = get_1920x960_cover_image(c_720x360); user.cover_images = {std::move(original), {std::move(c_720x360)}}; @@ -141,12 +141,20 @@ static inline std::optional get_1920x960_cover_image(blankie::murl: } static std::regex thumbnail_path_regex("/c/[^/]+(/.+)_master\\d+(\\.\\w{3,4})?"); -static inline std::optional get_original_cover_image(blankie::murl::Url url) { +static inline std::optional get_original_cover_image(blankie::murl::Url url, const nlohmann::json& cover_image) { std::smatch sm; if (!std::regex_match(url.path, sm, thumbnail_path_regex)) { return std::nullopt; } - url.path = sm.str(1) + sm.str(2); + + url.path = sm.str(1); + if (cover_image.contains("profile_cover_ext") && cover_image["profile_cover_ext"].is_string() + && !cover_image["profile_cover_ext"].get_ref().empty()) { + url.path += '.'; + url.path += cover_image["profile_cover_ext"].get(); + } else { + url.path += sm.str(2); + } return url.to_string(); }