foxygit / Torlinkc Log in
commits tags

/include/torlinkc/sources/types.hpp · 1.16 KB

raw
#pragma once

#include <cstdint>
#include <functional>
#include <optional>
#include <stop_token>
#include <string>
#include <vector>

namespace torlinkc {

struct TorrentResult {
  std::string infoHash;
  std::string name;
  std::int64_t sizeBytes = 0;
  int seeders = 0;
  int leechers = 0;
  std::optional<int> numFiles;
  std::string source;  // SourceId, e.g. "tpb-movies"
  std::string magnet;
  std::optional<std::int64_t> added;  // unix seconds
};

struct SearchOptions {
  // Default-constructed = never cancels, matching FetchOptions::stopToken.
  // SearchAggregator (Phase 3) passes each per-source thread's own token,
  // the same way the TS original threaded an AbortSignal through here.
  std::stop_token stopToken;
};

enum class SourceGroup { Games, Movies, TV, Anime };

struct Source {
  std::string id;
  std::string label;
  std::vector<SourceGroup> groups;
  std::string homepage;
  // True when the source returns real swarm counts. False when its feed has
  // none, so seeders == 0 means unknown, not dead.
  bool reportsHealth = true;
  std::function<std::vector<TorrentResult>(const std::string& query, const SearchOptions&)> search;
};

}  // namespace torlinkc