From 1e4b221dd760253a0cda92c8e8fa6fd348f24f12 Mon Sep 17 00:00:00 2001 From: blankie Date: Wed, 5 Apr 2023 21:38:23 +0700 Subject: [PATCH] Try to fetch another cover image thumbnail --- pixivclient.cpp | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/pixivclient.cpp b/pixivclient.cpp index 5d836aa..2a057ae 100644 --- a/pixivclient.cpp +++ b/pixivclient.cpp @@ -2,15 +2,8 @@ #include "pixivclient.h" -static std::regex cover_image_thumbnail_regex( - "((?:https?://)?(?:i\\.pximg\\.net)?)" // optional scheme and host - "/c/[0-9a-z_-]+(/.+)_master\\d+(\\.\\w{3,4})" -); +static inline std::optional get_1920x960_cover_image(const std::string& thumbnail); static inline std::optional get_original_cover_image(const std::string& thumbnail); -static std::regex profile_picture_thumbnail_regex( - "((?:https?://)?(?:i\\.pximg\\.net)?)" // optional scheme and host - "(/.+)_\\d+(\\.\\w{3,4})" -); static inline std::optional get_original_profile_picture(const std::string& thumbnail); static inline uint64_t to_ull(const std::string& str); @@ -49,8 +42,12 @@ void from_json(const nlohmann::json& j, User& user) { 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 c_1920x960 = get_1920x960_cover_image(c_720x360); user.cover_images = {std::move(original), {std::move(c_720x360)}}; + if (c_1920x960) { + user.cover_images->thumbnails.push_back(std::move(*c_1920x960)); + } } nlohmann::json profile_img = j.at("profile_img"); @@ -84,14 +81,37 @@ void from_json(const nlohmann::json& j, User& user) { add_social_as_needed("pawoo"); } +static std::regex c1920x960_cover_image_thumbnail_regex( + "((?:https?://)?(?:i\\.pximg\\.net)?)" // optional scheme and host + "/c/(\\d+x\\d+)(.+)" +); +static inline std::optional get_1920x960_cover_image(const std::string& thumbnail) { + std::smatch sm; + if (!std::regex_match(thumbnail, sm, c1920x960_cover_image_thumbnail_regex)) { + return std::nullopt; + } + if (sm[2] == "1920x960") { + return std::nullopt; + } + return sm[1].str() + "/c/1920x960" + sm[3].str(); +} + +static std::regex original_cover_image_thumbnail_regex( + "((?:https?://)?(?:i\\.pximg\\.net)?)" // optional scheme and host + "/c/[0-9a-z_-]+(/.+)_master\\d+(\\.\\w{3,4})" +); static inline std::optional get_original_cover_image(const std::string& thumbnail) { std::smatch sm; - if (!std::regex_match(thumbnail, sm, cover_image_thumbnail_regex)) { + if (!std::regex_match(thumbnail, sm, original_cover_image_thumbnail_regex)) { return std::nullopt; } return sm[1].str() + sm[2].str() + sm[3].str(); } +static std::regex profile_picture_thumbnail_regex( + "((?:https?://)?(?:i\\.pximg\\.net)?)" // optional scheme and host + "(/.+)_\\d+(\\.\\w{3,4})" +); static inline std::optional get_original_profile_picture(const std::string& thumbnail) { std::smatch sm; if (!std::regex_match(thumbnail, sm, profile_picture_thumbnail_regex)) {