Try to fetch a much higher quality thumbnail for multi-page artworks
This commit is contained in:
parent
c4407d86e5
commit
36a750762b
|
@ -8,6 +8,7 @@
|
|||
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, 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_360x360_illust_thumbnail(blankie::murl::Url url);
|
||||
static Images get_profile_pictures(const nlohmann::json& j);
|
||||
static Images get_illust_image(const nlohmann::json& j);
|
||||
|
||||
|
@ -182,22 +183,49 @@ static Images get_profile_pictures(const nlohmann::json& j) {
|
|||
return images;
|
||||
}
|
||||
|
||||
static std::regex illust_360x360_thumbnail_path_regex(
|
||||
"(?:/c/[^/]+?/img-master|/img-original)?"
|
||||
"(/img/.*/\\d+_p\\d+)(?:_master1200|_square1200)?\\.\\w{3,4}"
|
||||
);
|
||||
static inline std::optional<std::string> get_360x360_illust_thumbnail(blankie::murl::Url url) {
|
||||
using namespace std::string_literals;
|
||||
|
||||
std::smatch sm;
|
||||
if (!std::regex_match(url.path, sm, illust_360x360_thumbnail_path_regex)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
url.path = "/c/360x360_10_webp/img-master"s + sm.str(1) + "_square1200.jpg";
|
||||
return url.to_string();
|
||||
}
|
||||
|
||||
static Images get_illust_image(const nlohmann::json& j) {
|
||||
Images images;
|
||||
ssize_t add_360x360_to = -1;
|
||||
|
||||
auto add_if_exists = [&](const char* key) {
|
||||
if (j.contains(key) && j[key].is_string()) {
|
||||
images.thumbnails.push_back(j[key].get<std::string>());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
add_if_exists("url_ss");
|
||||
add_if_exists("url_placeholder");
|
||||
add_if_exists("url_small");
|
||||
add_if_exists("url_s");
|
||||
if (!add_if_exists("url_s")) {
|
||||
add_360x360_to = static_cast<ssize_t>(images.thumbnails.size());
|
||||
}
|
||||
add_if_exists("url");
|
||||
if (j.contains("url_big") && j["url_big"].is_string()) {
|
||||
images.original = j["url_big"].get<std::string>();
|
||||
}
|
||||
|
||||
if (add_360x360_to >= 0) {
|
||||
std::optional<std::string> c_360x360 = get_360x360_illust_thumbnail(images.original_or_thumbnail());
|
||||
if (c_360x360) {
|
||||
images.thumbnails.insert(images.thumbnails.begin() + add_360x360_to, std::move(*c_360x360));
|
||||
}
|
||||
}
|
||||
|
||||
return images;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue