sane-bt-search: add a --tracker parameter to query just a single tracker
This commit is contained in:
@@ -282,6 +282,7 @@ class Client:
|
|||||||
endpoint = ENDPOINTS[method]
|
endpoint = ENDPOINTS[method]
|
||||||
url = f"{SERVICE}/{endpoint}"
|
url = f"{SERVICE}/{endpoint}"
|
||||||
params = params.copy()
|
params = params.copy()
|
||||||
|
logger.debug(f"GET {url!r} with payload: {params}")
|
||||||
params.update(apikey=self.apikey, _=str(int(time.time())))
|
params.update(apikey=self.apikey, _=str(int(time.time())))
|
||||||
resp = requests.get(url, params=params)
|
resp = requests.get(url, params=params)
|
||||||
text = str(resp.text)
|
text = str(resp.text)
|
||||||
@@ -291,9 +292,13 @@ class Client:
|
|||||||
logger.error(f"failed to parse json API response from {url}: {text}")
|
logger.error(f"failed to parse json API response from {url}: {text}")
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def query(self, q: str) -> list[Torrent]:
|
def query(self, query: str, trackers: list[str] | None) -> list[Torrent]:
|
||||||
torrents = set()
|
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"]:
|
for r in api_res["Results"]:
|
||||||
t = Torrent.from_dict(r)
|
t = Torrent.from_dict(r)
|
||||||
if t is not None:
|
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('--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('--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')
|
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('--verbose', action='store_true')
|
||||||
parser.add_argument('--book', action='store_true', help='show only book (ebook or audiobook) results')
|
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)')
|
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)
|
logging.getLogger().setLevel(logging.DEBUG)
|
||||||
|
|
||||||
client = Client()
|
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)
|
filter = Filter(book=args.book, h265=args.h265, manga=args.manga, video=args.video)
|
||||||
filtered_results = filter.filter(all_results)
|
filtered_results = filter.filter(all_results)
|
||||||
|
Reference in New Issue
Block a user