diff --git a/src/libdanbooru/utils.cpp b/src/libdanbooru/utils.cpp index 93ba9ac..27bc714 100644 --- a/src/libdanbooru/utils.cpp +++ b/src/libdanbooru/utils.cpp @@ -296,6 +296,33 @@ QVariantMap extractPoolData(const QVariant &data, ApiType type) { } +QVariantMap extractTagData(const QVariant &data, ApiType type) { + + auto mapped = data.toMap(); + int id = mapped.value("id").toInt(); + QString name = mapped.value("name").toString(); + int postCount; + int category; + + switch(type) { + case MoeBooru: + postCount = mapped.value("count").toInt(); + category = mapped.value("type").toInt(); + break; + default: + postCount = mapped.value("post_count").toInt(); + category = mapped.value("category").toInt(); + }; + + QVariantMap map = { + {QL1S("id"), id}, + {QL1S("name"), name}, {QL1S("postCount"), postCount}, + {QL1S("category"), category} + }; + + return map; +} + QVariantMap extractPostData(const QVariant &data, ApiType type) { auto mapped = data.toMap(); @@ -322,36 +349,16 @@ QVariantMap extractPostData(const QVariant &data, ApiType type) { rating = RATING_MAP.value(mapped.value("rating").toString()); fileSize = mapped.value("file_size").toInt(); break; - case Danbooru::Gelbooru: - id = 0; - tags = QSet(); - width = 0; - height = 0; - fileSize = 0; - url = QUrl(); - thumbnailUrl = QUrl(); - sampleUrl = QUrl(); - rating = Danbooru::Safe; - break; default: - auto tagKey = mapped.contains("tag_string") ? QL1S("tag_string"): QL1S("tag-string"); - auto widthKey = mapped.contains("image_width") ? QL1S("image_width"): QL1S("image-width"); - auto heightKey = mapped.contains("image_height") ? QL1S("image_height"): QL1S("image-height"); - auto fileSizeKey = mapped.contains("file_size") ? QL1S("file_size"): QL1S("file-size"); - auto fileUrlKey = mapped.contains("file_url") ? QL1S("file_url"): QL1S("file-url"); - auto thumbnailUrlKey = mapped.contains("preview_file_url") ? QL1S("preview_file_url"): QL1S("preview-file-url"); - auto sampleUrlKey = mapped.contains("large_file_url") ? QL1S("large_file_url"): QL1S("large-file-url"); - id = mapped.value("id").toString().toInt(); - tags = QSet::fromList(mapped.value(tagKey).toString().split(' ')); - width = mapped.value(widthKey).toString().toInt(); - height = mapped.value(heightKey).toString().toInt(); - url = mapped.value(fileUrlKey).toUrl(); - thumbnailUrl = mapped.value(thumbnailUrlKey).toUrl(); - fileSize = mapped.value(fileSizeKey).toInt(); + tags = QSet::fromList(mapped.value("tag_string_general").toString().split(' ')); + width = mapped.value("image_width").toString().toInt(); + height = mapped.value("image_height").toString().toInt(); + url = mapped.value("file_url").toUrl(); + thumbnailUrl = mapped.value("preview_file_url").toUrl(); + fileSize = mapped.value("file_size").toInt(); rating = RATING_MAP.value(mapped.value("rating").toString()); - sampleUrl = mapped.value(sampleUrlKey).toUrl(); - break; + sampleUrl = mapped.value("large_file_url").toUrl(); }; @@ -397,7 +404,7 @@ QList parseResult(const QByteArray &data, ApiType type, Danbooru::R qDebug() << "Reimplement"; break; case Tag: - qDebug() << "Reimplement"; + mapped = extractTagData(element, type); break; default: mapped = extractPostData(element, type); diff --git a/src/libdanbooru/utils.h b/src/libdanbooru/utils.h index a618317..59134ca 100644 --- a/src/libdanbooru/utils.h +++ b/src/libdanbooru/utils.h @@ -125,6 +125,7 @@ QList parseResult(const QXmlStreamAttributes &data, Danbooru::ApiTy QVariantMap extractPostData(const QVariant &data, ApiType type); QVariantMap extractPoolData(const QVariant &data, ApiType type); +QVariantMap extractTagData(const QVariant &data, ApiType type); const QMap< QString, Danbooru::Rating > initRatingMap();