- Implement related tags in the Danbooru interface;
- Fix return types due to utils change
This commit is contained in:
parent
a2c1f6d46f
commit
aeba76cd06
2 changed files with 98 additions and 18 deletions
|
@ -103,6 +103,7 @@ namespace Danbooru {
|
||||||
if (!name.isEmpty()) {
|
if (!name.isEmpty()) {
|
||||||
parameters.insert("name", name);
|
parameters.insert("name", name);
|
||||||
}
|
}
|
||||||
|
parameters.insert("order", "date");
|
||||||
|
|
||||||
KUrl danbooruUrl = requestUrl(m_url, TAG_URL, m_username, m_password,
|
KUrl danbooruUrl = requestUrl(m_url, TAG_URL, m_username, m_password,
|
||||||
parameters);
|
parameters);
|
||||||
|
@ -171,9 +172,47 @@ namespace Danbooru {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DanbooruService::getRelatedTags(QStringList tags, Danbooru::TagType tagType)
|
void DanbooruService::getRelatedTags(const QStringList& tags,
|
||||||
|
Danbooru::TagType tagType)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
qDebug() << "We start with these" << tags;
|
||||||
|
|
||||||
|
QString type;
|
||||||
|
switch(tagType) {
|
||||||
|
case Danbooru::General:
|
||||||
|
type = "general";
|
||||||
|
break;
|
||||||
|
case Danbooru::Artist:
|
||||||
|
type = "artist";
|
||||||
|
break;
|
||||||
|
case Danbooru::Copyright:
|
||||||
|
type = "copyright";
|
||||||
|
break;
|
||||||
|
case Danbooru::Character:
|
||||||
|
type = "character";
|
||||||
|
break;
|
||||||
|
case Danbooru::Unknown:
|
||||||
|
type = "unknown";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, QString> parameters;
|
||||||
|
parameters.insert("type", type);
|
||||||
|
|
||||||
|
KUrl danbooruUrl = requestUrl(m_url, RELATED_TAG_URL, m_username,
|
||||||
|
m_password, parameters, tags );
|
||||||
|
|
||||||
|
qDebug() << "Final constructed URL" << danbooruUrl.url();
|
||||||
|
|
||||||
|
StoredTransferJob* job = KIO::storedGet(
|
||||||
|
danbooruUrl, KIO::NoReload,
|
||||||
|
KIO::HideProgressInfo
|
||||||
|
);
|
||||||
|
|
||||||
|
connect(job, SIGNAL(result(KJob*)), this,
|
||||||
|
SLOT(processRelatedTagList(KJob*)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters / setters
|
// Getters / setters
|
||||||
|
@ -271,9 +310,9 @@ namespace Danbooru {
|
||||||
|
|
||||||
if (needsXML) {
|
if (needsXML) {
|
||||||
// Special cases for pools
|
// Special cases for pools
|
||||||
postList = parseDanbooruResult(data, QString("pool"), &ok);
|
postList = parseDanbooruResult(data, QString("post"), &ok);
|
||||||
} else {
|
} else {
|
||||||
postList = parseDanbooruResult(data, &ok);
|
postList = parseDanbooruResult(data, &ok).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
@ -291,13 +330,13 @@ namespace Danbooru {
|
||||||
|
|
||||||
DanbooruPost* post = new DanbooruPost(map);
|
DanbooruPost* post = new DanbooruPost(map);
|
||||||
|
|
||||||
// qDebug() << "Got rating" << post->rating();
|
// qDebug() << "Got rating" << post->rating();
|
||||||
|
|
||||||
// First check, for rating
|
// First check, for rating
|
||||||
|
|
||||||
if (post->rating() > m_maxRating) {
|
if (post->rating() > m_maxRating) {
|
||||||
qDebug() << "Skipping " << post->fileUrl();
|
// qDebug() << "Skipping " << post->fileUrl();
|
||||||
qDebug() << "Rating was " << post->rating();
|
// qDebug() << "Rating was " << post->rating();
|
||||||
m_currentPosts--;
|
m_currentPosts--;
|
||||||
delete post;
|
delete post;
|
||||||
continue;
|
continue;
|
||||||
|
@ -309,13 +348,13 @@ namespace Danbooru {
|
||||||
|
|
||||||
QSet<QString> temp = m_blacklist;
|
QSet<QString> temp = m_blacklist;
|
||||||
|
|
||||||
QSet<QString> overlap = temp.intersect(post->tags());
|
temp = temp.intersect(post->tags());
|
||||||
|
|
||||||
if (!overlap.isEmpty()) {
|
if (!temp.isEmpty()) {
|
||||||
|
|
||||||
// Blacklisted tags are present, do not use this post
|
// Blacklisted tags are present, do not use this post
|
||||||
qDebug() << "Skipping " << post->fileUrl();
|
// qDebug() << "Skipping " << post->fileUrl();
|
||||||
qDebug() << "Blacklisted tags " << overlap;
|
// qDebug() << "Blacklisted tags " << overlap;
|
||||||
m_currentPosts--;
|
m_currentPosts--;
|
||||||
delete post;
|
delete post;
|
||||||
continue;
|
continue;
|
||||||
|
@ -347,8 +386,8 @@ namespace Danbooru {
|
||||||
qDebug() << "Got tag data OK";
|
qDebug() << "Got tag data OK";
|
||||||
|
|
||||||
if (job->error()) {
|
if (job->error()) {
|
||||||
qDebug() << "Something went wrong";
|
|
||||||
Q_EMIT(downloadError(job->errorString()));
|
Q_EMIT(downloadError(job->errorString()));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
||||||
|
@ -367,13 +406,10 @@ namespace Danbooru {
|
||||||
QList<QVariant> tagList = parseDanbooruResult(data, "tag", &ok);
|
QList<QVariant> tagList = parseDanbooruResult(data, "tag", &ok);
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
qDebug() << "Something went wrong";
|
|
||||||
Q_EMIT(downloadError(QString("Unable to decode data")));
|
Q_EMIT(downloadError(QString("Unable to decode data")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Populating tag list, length" << tagList.length();
|
|
||||||
|
|
||||||
Q_FOREACH(const QVariant& element, tagList) {
|
Q_FOREACH(const QVariant& element, tagList) {
|
||||||
QVariantMap map = element.toMap();
|
QVariantMap map = element.toMap();
|
||||||
DanbooruTag* tag = new DanbooruTag(map);
|
DanbooruTag* tag = new DanbooruTag(map);
|
||||||
|
@ -384,7 +420,52 @@ namespace Danbooru {
|
||||||
|
|
||||||
void DanbooruService::processRelatedTagList(KJob* job)
|
void DanbooruService::processRelatedTagList(KJob* job)
|
||||||
{
|
{
|
||||||
Q_UNUSED(job)
|
qDebug() << "Got related tag data OK";
|
||||||
|
|
||||||
|
if (job->error()) {
|
||||||
|
Q_EMIT(downloadError(job->errorString()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
||||||
|
|
||||||
|
if (jobResult == 0) {
|
||||||
|
Q_EMIT(downloadError(QString("Internal error")));
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray data = jobResult->data();
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
QVariantMap tagList = parseDanbooruResult(data, &ok).toMap();
|
||||||
|
|
||||||
|
if (!ok) {
|
||||||
|
Q_EMIT(downloadError(QString("Unable to decode data")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantMap::const_iterator iter;
|
||||||
|
|
||||||
|
// The service returns a list of key-related tag list pair,
|
||||||
|
// we iterate through them and remove the empty (not found) ones, then
|
||||||
|
// we call getTagList. Unfortunately Danbooru doesn't have a method to
|
||||||
|
// fetch all tags in batch, so this is done one by one.
|
||||||
|
|
||||||
|
for (iter=tagList.constBegin(); iter!=tagList.constEnd(); ++iter) {
|
||||||
|
|
||||||
|
QList<QVariant> tags = iter.value().toList();
|
||||||
|
|
||||||
|
if (tags.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_FOREACH(const QVariant& tag, tags) {
|
||||||
|
QString interest = tag.toList()[0].toString();
|
||||||
|
getTagList(1, interest);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DanbooruService::processPoolList(KJob* job)
|
void DanbooruService::processPoolList(KJob* job)
|
||||||
|
@ -408,7 +489,7 @@ namespace Danbooru {
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
|
|
||||||
QList<QVariant> poolList = parseDanbooruResult(data, &ok);
|
QList<QVariant> poolList = parseDanbooruResult(data, &ok).toList();
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
Q_EMIT(downloadError(QString("Unable to decode data")));
|
Q_EMIT(downloadError(QString("Unable to decode data")));
|
||||||
|
|
|
@ -165,8 +165,7 @@ namespace Danbooru {
|
||||||
* @param tags The tags to query for related terms
|
* @param tags The tags to query for related terms
|
||||||
* @param tagType The type of tag to query for
|
* @param tagType The type of tag to query for
|
||||||
**/
|
**/
|
||||||
void getRelatedTags(QStringList tags=QStringList(),
|
void getRelatedTags(const QStringList& tags, Danbooru::TagType tagType = General);
|
||||||
Danbooru::TagType tagType=General);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The currently allowed ratings when downloading posts.
|
* @return The currently allowed ratings when downloading posts.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue