KanoopTorrentQt 0.1.0
Qt6 wrapper library for libtorrent-rasterbar
Loading...
Searching...
No Matches
torrentsearchresult.h
1#ifndef TORRENTSEARCHRESULT_H
2#define TORRENTSEARCHRESULT_H
3
4#include <Kanoop/torrent/kanooptorrent.h>
5#include <Kanoop/torrent/magnetlink.h>
6#include <QDateTime>
7#include <QJsonObject>
8#include <QString>
9
10/**
11 * @brief Metadata for a single torrent search result.
12 *
13 * Populated by TorrentSearcher from API responses. Use toMagnetLink()
14 * to convert a result into a MagnetLink suitable for TorrentClient::addTorrent().
15 */
16class LIBKANOOPTORRENT_EXPORT TorrentSearchResult
17{
18public:
20
21 /** @brief Torrent display name. */
22 QString name() const { return _name; }
23 /** @brief Hex-encoded info hash string. */
24 QString infoHash() const { return _infoHash; }
25 /** @brief Total content size in bytes. */
26 qint64 size() const { return _size; }
27 /** @brief Number of seeders reported by the tracker. */
28 int seeders() const { return _seeders; }
29 /** @brief Number of leechers reported by the tracker. */
30 int leechers() const { return _leechers; }
31 /** @brief Date/time the torrent was added to the index. */
32 QDateTime addedDate() const { return _addedDate; }
33 /** @brief Category string (e.g. "Audio", "Video"). */
34 QString category() const { return _category; }
35 /** @brief Name of the uploader. */
36 QString uploaderName() const { return _uploaderName; }
37
38 /**
39 * @brief Convert this result to a MagnetLink.
40 * @return A MagnetLink with the info hash and display name set.
41 */
43
44 /**
45 * @brief Parse a search result from a JSON object.
46 *
47 * Expected fields: @c name, @c info_hash, @c size, @c seeders,
48 * @c leechers, @c added, @c category, @c username.
49 * @param json The JSON object to parse.
50 * @return A populated TorrentSearchResult.
51 */
52 static TorrentSearchResult fromJson(const QJsonObject& json);
53
54 /**
55 * @brief Format a byte count as a human-readable string.
56 * @param bytes Raw byte count.
57 * @return Formatted string (e.g. "1.23 GB").
58 */
59 static QString formatSize(qint64 bytes);
60
61private:
62 QString _name;
63 QString _infoHash;
64 qint64 _size = 0;
65 int _seeders = 0;
66 int _leechers = 0;
67 QDateTime _addedDate;
68 QString _category;
69 QString _uploaderName;
70};
71
72#endif // TORRENTSEARCHRESULT_H
Metadata for a single torrent search result.
QString uploaderName() const
Name of the uploader.
int leechers() const
Number of leechers reported by the tracker.
QString infoHash() const
Hex-encoded info hash string.
static QString formatSize(qint64 bytes)
Format a byte count as a human-readable string.
MagnetLink toMagnetLink() const
Convert this result to a MagnetLink.
qint64 size() const
Total content size in bytes.
int seeders() const
Number of seeders reported by the tracker.
QString name() const
Torrent display name.
QString category() const
Category string (e.g.
QDateTime addedDate() const
Date/time the torrent was added to the index.
static TorrentSearchResult fromJson(const QJsonObject &json)
Parse a search result from a JSON object.