foxygit / Torlinkc Log in
commits tags

/src/sources/registry.cpp · 1.85 KB

raw
#include "torlinkc/sources/registry.hpp"

#include <algorithm>

#include "torlinkc/sources/bittorrented.hpp"
#include "torlinkc/sources/eztv.hpp"
#include "torlinkc/sources/fitgirl.hpp"
#include "torlinkc/sources/nyaa.hpp"
#include "torlinkc/sources/piratebay.hpp"
#include "torlinkc/sources/subsplease.hpp"
#include "torlinkc/sources/x1337.hpp"
#include "torlinkc/sources/yts.hpp"

namespace torlinkc {

std::vector<Source> allSources() {
  // Order matches registry.ts::SOURCES, which the default results ordering
  // and UI source-status list are built to expect.
  return {
      fitgirlSource(), ytsSource(),    tpbMoviesSource(), x1337MoviesSource(), eztvSource(),
      tpbTvSource(),    x1337TvSource(), nyaaSource(),    subspleaseSource(),  bittorrentedSource(),
  };
}

std::unordered_map<std::string, Source> sourceById() {
  std::unordered_map<std::string, Source> out;
  for (auto& s : allSources()) {
    const std::string id = s.id;
    out.emplace(id, std::move(s));
  }
  return out;
}

std::string categoryLabel(Category c) {
  switch (c) {
    case Category::All:
      return "All";
    case Category::Games:
      return "Games";
    case Category::Movies:
      return "Movies";
    case Category::TV:
      return "TV";
    case Category::Anime:
      return "Anime";
  }
  return "All";
}

bool sourceInCategory(const Source& source, Category c) {
  if (c == Category::All) return true;
  SourceGroup group;
  switch (c) {
    case Category::Games:
      group = SourceGroup::Games;
      break;
    case Category::Movies:
      group = SourceGroup::Movies;
      break;
    case Category::TV:
      group = SourceGroup::TV;
      break;
    case Category::Anime:
      group = SourceGroup::Anime;
      break;
    default:
      return true;
  }
  return std::find(source.groups.begin(), source.groups.end(), group) != source.groups.end();
}

}  // namespace torlinkc