Fix fetching original cover images for some user
Example user: 23605419
This commit is contained in:
parent
87cef0ced1
commit
86749d3fbf
|
@ -6,7 +6,7 @@
|
||||||
#include "numberhelper.h"
|
#include "numberhelper.h"
|
||||||
|
|
||||||
static inline std::optional<std::string> get_1920x960_cover_image(blankie::murl::Url url);
|
static inline std::optional<std::string> get_1920x960_cover_image(blankie::murl::Url url);
|
||||||
static inline std::optional<std::string> get_original_cover_image(blankie::murl::Url url);
|
static inline std::optional<std::string> get_original_cover_image(blankie::murl::Url url, const nlohmann::json& cover_image);
|
||||||
static inline std::optional<std::string> get_original_profile_picture(blankie::murl::Url url);
|
static inline std::optional<std::string> get_original_profile_picture(blankie::murl::Url url);
|
||||||
static Images get_profile_pictures(const nlohmann::json& j);
|
static Images get_profile_pictures(const nlohmann::json& j);
|
||||||
static Images get_illust_image(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()) {
|
if (j.contains("cover_image") && j["cover_image"].is_object()) {
|
||||||
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, cover_image);
|
||||||
std::optional<std::string> c_1920x960 = get_1920x960_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)}};
|
||||||
|
@ -141,12 +141,20 @@ static inline std::optional<std::string> get_1920x960_cover_image(blankie::murl:
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::regex thumbnail_path_regex("/c/[^/]+(/.+)_master\\d+(\\.\\w{3,4})?");
|
static std::regex thumbnail_path_regex("/c/[^/]+(/.+)_master\\d+(\\.\\w{3,4})?");
|
||||||
static inline std::optional<std::string> get_original_cover_image(blankie::murl::Url url) {
|
static inline std::optional<std::string> get_original_cover_image(blankie::murl::Url url, const nlohmann::json& cover_image) {
|
||||||
std::smatch sm;
|
std::smatch sm;
|
||||||
if (!std::regex_match(url.path, sm, thumbnail_path_regex)) {
|
if (!std::regex_match(url.path, sm, thumbnail_path_regex)) {
|
||||||
return std::nullopt;
|
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<const nlohmann::json::string_t&>().empty()) {
|
||||||
|
url.path += '.';
|
||||||
|
url.path += cover_image["profile_cover_ext"].get<std::string>();
|
||||||
|
} else {
|
||||||
|
url.path += sm.str(2);
|
||||||
|
}
|
||||||
return url.to_string();
|
return url.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue