sane-bt-search: add a --tracker parameter to query just a single tracker

This commit is contained in:
2025-07-07 21:41:47 +00:00
parent fbce38a47a
commit 25aa82b038

View File

@@ -282,6 +282,7 @@ class Client:
endpoint = ENDPOINTS[method]
url = f"{SERVICE}/{endpoint}"
params = params.copy()
logger.debug(f"GET {url!r} with payload: {params}")
params.update(apikey=self.apikey, _=str(int(time.time())))
resp = requests.get(url, params=params)
text = str(resp.text)
@@ -291,9 +292,13 @@ class Client:
logger.error(f"failed to parse json API response from {url}: {text}")
raise e
def query(self, q: str) -> list[Torrent]:
def query(self, query: str, trackers: list[str] | None) -> list[Torrent]:
torrents = set()
api_res = self.api_call("results", dict(Query=q))
params = {}
params["Query"] = query
if trackers is not None:
params["Tracker[]"] = trackers
api_res = self.api_call("results", params)
for r in api_res["Results"]:
t = Torrent.from_dict(r)
if t is not None:
@@ -332,6 +337,8 @@ def main(args: list[str]):
parser.add_argument('--top', help=f'how many results to show (default: {DEFAULT_RESULT_COUNT})')
parser.add_argument('--sort-by', default=SortMethod.Balanced, type=SortMethod, help='how to rank matches (seeders, tracker)')
parser.add_argument('--json', action='store_true', help='output results in json')
# TODO: add `choices`, populated from the API name of each KNOWN_TRACKERS.
parser.add_argument('--tracker', type=str, action='append', help='query only this tracker(s) e.g. "bitmagnet" or "bakabt"')
parser.add_argument('--verbose', action='store_true')
parser.add_argument('--book', action='store_true', help='show only book (ebook or audiobook) results')
parser.add_argument('--h265', action='store_true', help='show only H.265/HEVC results (might cause false negatives)')
@@ -345,7 +352,7 @@ def main(args: list[str]):
logging.getLogger().setLevel(logging.DEBUG)
client = Client()
all_results = client.query(args.query)
all_results = client.query(args.query, args.tracker)
filter = Filter(book=args.book, h265=args.h265, manga=args.manga, video=args.video)
filtered_results = filter.filter(all_results)