root/src/gelbooruclient.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "gelbooruclient.h"
#include "filedownloadthread.h"

namespace Gelbooru {

Client::Client(QString baseUrl, int limit, Rating ratingFilter) :
    WallpaperDownload::Client(baseUrl, limit, ratingFilter)
{
}

Entry Client::parseEntry(nw::Describer *de) {
    Entry entry;
    NwUtils::describe(*de, "file_url", entry.fileUrl);
    NwUtils::describe(*de, "sample_url", entry.sampleUrl);
    NwUtils::describe(*de, "preview_url", entry.previewUrl);
    NwUtils::describe(*de, "rating", entry.rating);
    NwUtils::describe(*de, "id", entry.id);
    NwUtils::describe(*de, "tags", entry.tags, ' ');
    NwUtils::describe(*de, "height", entry.height);
    NwUtils::describe(*de, "width", entry.width);
    NwUtils::describe(*de, "score", entry.score);
    return entry;
}

SearchResult Client::parseSearchResult(std::stringstream &ss, int limit) {
    int count = 0;
    int offset = 0;

    SearchResult sr(limit);
    nw::XmlReader xr(ss);
    xr.describe("count", count);
    xr.describe("offset", offset);

    xr.describeArray("","post", 0);
    for (int i=0; xr.enterNextElement(i); ++i) {
        sr.entries.push_back(parseEntry(&xr));
    }
    return sr;
}

CURL *Client::curlClient(QString tag, CurlResult& userdata, const unsigned int page) {
    QString pageStr = QString::number(page);
    QString url = QString("%1/index.php?page=dapi&s=post&q=index&pid=%2&tags=%3").arg(baseUrl, pageStr, tag);
    CURL* handle = userdata.curlClient(url);
    return handle;
}

};