Try to fetch another cover image thumbnail
This commit is contained in:
parent
b864b3d290
commit
1e4b221dd7
|
@ -2,15 +2,8 @@
|
||||||
|
|
||||||
#include "pixivclient.h"
|
#include "pixivclient.h"
|
||||||
|
|
||||||
static std::regex cover_image_thumbnail_regex(
|
static inline std::optional<std::string> get_1920x960_cover_image(const std::string& thumbnail);
|
||||||
"((?:https?://)?(?:i\\.pximg\\.net)?)" // optional scheme and host
|
|
||||||
"/c/[0-9a-z_-]+(/.+)_master\\d+(\\.\\w{3,4})"
|
|
||||||
);
|
|
||||||
static inline std::optional<std::string> get_original_cover_image(const std::string& thumbnail);
|
static inline std::optional<std::string> 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<std::string> get_original_profile_picture(const std::string& thumbnail);
|
static inline std::optional<std::string> get_original_profile_picture(const std::string& thumbnail);
|
||||||
static inline uint64_t to_ull(const std::string& str);
|
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"];
|
nlohmann::json cover_image = j["cover_image"];
|
||||||
std::string c_720x360 = cover_image.at("profile_cover_image").at("720x360").get<std::string>();
|
std::string c_720x360 = cover_image.at("profile_cover_image").at("720x360").get<std::string>();
|
||||||
std::optional<std::string> original = get_original_cover_image(c_720x360);
|
std::optional<std::string> original = get_original_cover_image(c_720x360);
|
||||||
|
std::optional<std::string> c_1920x960 = get_1920x960_cover_image(c_720x360);
|
||||||
|
|
||||||
user.cover_images = {std::move(original), {std::move(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");
|
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");
|
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<std::string> 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<std::string> get_original_cover_image(const std::string& thumbnail) {
|
static inline std::optional<std::string> get_original_cover_image(const std::string& thumbnail) {
|
||||||
std::smatch sm;
|
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 std::nullopt;
|
||||||
}
|
}
|
||||||
return sm[1].str() + sm[2].str() + sm[3].str();
|
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<std::string> get_original_profile_picture(const std::string& thumbnail) {
|
static inline std::optional<std::string> get_original_profile_picture(const std::string& thumbnail) {
|
||||||
std::smatch sm;
|
std::smatch sm;
|
||||||
if (!std::regex_match(thumbnail, sm, profile_picture_thumbnail_regex)) {
|
if (!std::regex_match(thumbnail, sm, profile_picture_thumbnail_regex)) {
|
||||||
|
|
Loading…
Reference in New Issue