From 08498f5ee2cf0f108c24b0e6de73d43aeb20e619 Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Sat, 22 Aug 2015 20:02:17 +0200 Subject: [PATCH] WIP, Konachan API implementation --- src/libdanbooru/konachan.cpp | 87 ++++++++++++++++++++++++++++++++++++ src/libdanbooru/konachan.h | 60 +++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 src/libdanbooru/konachan.cpp create mode 100644 src/libdanbooru/konachan.h diff --git a/src/libdanbooru/konachan.cpp b/src/libdanbooru/konachan.cpp new file mode 100644 index 0000000..812ef55 --- /dev/null +++ b/src/libdanbooru/konachan.cpp @@ -0,0 +1,87 @@ +/* + * Copyright 2015 Luca Beltrame + * + * This file is part of Danbooru Client. + * + * Danbooru Client is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Danbooru Client is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Danbooru Client. If not, see . + */ + +#include "konachan.h" +#include "danboorupost.h" +#include "danboorupool.h" +#include "danboorutag.h" +#include "utils.h" + +// KF5 + +#include +#include +#include + +namespace Danbooru { + +/////// +// URIs +/////// + +const QLatin1String KonachanDanbooruService::postUri() const { + return QLatin1String("post/index.json"); +} + +const QLatin1String KonachanDanbooruService::poolUri() const { + return QLatin1String("pool/index.json"); +} + +const QLatin1String KonachanDanbooruService::artistUri() const { + return QLatin1String("artist/index.json"); +} + +const QLatin1String KonachanDanbooruService::tagUri() const { + return QLatin1String("tag/index.xml"); +} + +const QLatin1String KonachanDanbooruService::poolDataUri() const { + return QLatin1String("pool/show.xml"); +} + +const QLatin1String KonachanDanbooruService::relatedTagUri() const { + return QLatin1String("tag/related.json"); +} + +void KonachanDanbooruService::getPostList() { + // We can't fetch more than 100 items, API limitation + + QMap parameters; + + parameters.insert("limit", QString::number(m_maxPosts)); + parameters.insert("page", QString::number(m_currentPage)); + + QUrl danbooruUrl = requestUrl(m_url, POST_URL, m_username, + m_password, parameters, m_tags); + + // qCDebug(LIBDANBOORU) << "Final constructed post URL" << danbooruUrl; + + KIO::StoredTransferJob *job = KIO::storedGet(danbooruUrl, KIO::NoReload, + KIO::HideProgressInfo); + + // This job can use JSON data + job->setProperty("needsXML", false); + + connect(job, &KIO::StoredTransferJob::result, this, &KonachanDanbooruService::processPostList); + +} + +} //namespace Danbooru + + diff --git a/src/libdanbooru/konachan.h b/src/libdanbooru/konachan.h new file mode 100644 index 0000000..1088777 --- /dev/null +++ b/src/libdanbooru/konachan.h @@ -0,0 +1,60 @@ +/* + * Copyright 2015 Luca Beltrame + * + * This file is part of Danbooru Client. + * + * Danbooru Client is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Danbooru Client is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Danbooru Client. If not, see . + */ + +#ifndef DANBOORU_KONACHAN_H +#define DANBOORU_KONACHAN_H + +#include "servicebase.h" +#include "danbooru.h" + +class KJob; + +namespace Danbooru { + +class KonachanDanbooruService: public DanbooruServiceBase { + +Q_OBJECT + +private: + const QLatin1String postUri() const override; + const QLatin1String poolUri() const override; + const QLatin1String artistUri() const override; + const QLatin1String tagUri() const override; + const QLatin1String poolDataUri() const override; + const QLatin1String relatedTagUri() const override; + +public: + + using DanbooruServiceBase::DanbooruServiceBase; // superclass constructor + ~KonachanDanbooruService() override; + + void getPostList() override; + void getPoolList() override; + +private Q_SLOTS: + void processPostList(KJob *job); + void processTagList(KJob *job); + void downloadAllTags(KJob *job); + + +}; + +} // namespace Danbooru + +#endif