From 25aa82b03823ffc9c4b4fa951ceb17e56569db6c Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 7 Jul 2025 21:41:47 +0000 Subject: [PATCH] sane-bt-search: add a --tracker parameter to query just a single tracker --- pkgs/by-name/sane-scripts/src/sane-bt-search | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkgs/by-name/sane-scripts/src/sane-bt-search b/pkgs/by-name/sane-scripts/src/sane-bt-search index 3ac15cd40..3c77d2b42 100755 --- a/pkgs/by-name/sane-scripts/src/sane-bt-search +++ b/pkgs/by-name/sane-scripts/src/sane-bt-search @@ -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)