From 17e399bbcd811fda8b0f7f559e7902206bf9508d Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Thu, 27 Aug 2015 22:51:19 +0200 Subject: [PATCH] More fixes for Danbooru's braindead API results --- src/libdanbooru/danboorupost.cpp | 35 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/libdanbooru/danboorupost.cpp b/src/libdanbooru/danboorupost.cpp index 3f10720..2df2f1d 100644 --- a/src/libdanbooru/danboorupost.cpp +++ b/src/libdanbooru/danboorupost.cpp @@ -37,24 +37,27 @@ const QMap DanbooruPost::RATING_MAP = initRatingM void DanbooruPost::parseDanbooruDonmai(const QVariantMap &postData) { - m_tags = QSet::fromList(postData.value("tag_string").toString().split(' ')); - m_id = postData.value("id").toString().toInt(); - if (postData.contains("image_width")) { - m_width = postData.value("image_width").toString().toInt(); - } else if (postData.contains("image-width")) { - m_width = postData.value("image-width").toString().toInt(); - } - if (postData.contains("image_height")) { - m_height = postData.value("image_height").toString().toInt(); - } else if (postData.contains("image-height")) { - m_height = postData.value("image-height").toString().toInt(); - } + // HACK: Handle XML (foo-bar) versus JSON (foo_bar) for attributes - m_url = postData.value("file_url").toUrl(); - m_thumbnailUrl = postData.value("preview_file_url").toUrl(); - m_size = postData.value("file_size").toInt(); + auto tagString = postData.contains("tag_string") ? QLatin1String("tag_string"): QLatin1String("tag-string"); + auto width = postData.contains("image_width") ? QLatin1String("image_width"): QLatin1String("image-width"); + auto height = postData.contains("image_height") ? QLatin1String("image_height"): QLatin1String("image-height"); + auto fileSize = postData.contains("file_size") ? QLatin1String("file_size"): QLatin1String("file-size"); + auto fileUrl = postData.contains("file_url") ? QLatin1String("file_url"): QLatin1String("file-url"); + auto thumbnailUrl = postData.contains("preview_file_url") ? QLatin1String("preview_file_url"): QLatin1String("preview-file-url"); + auto sampleUrl = postData.contains("large_file_url") ? QLatin1String("large_file_url"): QLatin1String("large-file-url"); + + m_id = postData.value("id").toString().toInt(); + m_tags = QSet::fromList(postData.value(tagString).toString().split(' ')); + + m_width = postData.value(width).toString().toInt(); + m_height = postData.value(height).toString().toInt(); + + m_url = postData.value(fileUrl).toUrl(); + m_thumbnailUrl = postData.value(thumbnailUrl).toUrl(); + m_size = postData.value(fileSize).toInt(); m_rating = RATING_MAP.value(postData.value("rating").toString()); - m_sampleUrl = postData.value("large_file_url").toUrl(); + m_sampleUrl = postData.value(sampleUrl).toUrl(); } void DanbooruPost::parseDanbooruDonmai(const QXmlStreamAttributes &postData) {