1
0
mirror of https://github.com/vikstrous/pirate-get synced 2025-01-10 10:04:21 +01:00

Merge pull request #138 from jabortell/limit_results

Add -r/--total-results to limit search results
This commit is contained in:
Michele Guerini Rocco 2020-09-28 20:01:14 +02:00 committed by GitHub
commit 608cb0a6a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -43,6 +43,10 @@ enabled = false
; path of the database ; path of the database
path = ~/downloads/pirate-get/db path = ~/downloads/pirate-get/db
[Search]
; maximum number of results to show
total-results = 50
[Misc] [Misc]
; specify a custom command for opening the magnet ; specify a custom command for opening the magnet
; ex. myprogram --open %s ; ex. myprogram --open %s

View File

@ -32,6 +32,9 @@ def parse_config_file(text):
config.set('LocalDB', 'enabled', 'false') config.set('LocalDB', 'enabled', 'false')
config.set('LocalDB', 'path', expanduser('~/downloads/pirate-get/db')) config.set('LocalDB', 'path', expanduser('~/downloads/pirate-get/db'))
config.add_section('Search')
config.set('Search', 'total-results', 50)
config.add_section('Misc') config.add_section('Misc')
# TODO: try to use configparser.BasicInterpolation # TODO: try to use configparser.BasicInterpolation
# for interpolating in the command # for interpolating in the command
@ -146,6 +149,9 @@ def parse_args(args_in):
default=1, type=int, default=1, type=int,
help='the number of pages to fetch. ' help='the number of pages to fetch. '
'(only used with --recent)') '(only used with --recent)')
parser.add_argument('-r', '--total-results',
type=int,
help='maximum number of results to show')
parser.add_argument('-L', '--local', dest='database', parser.add_argument('-L', '--local', dest='database',
help='a csv file containing the Pirate Bay database ' help='a csv file containing the Pirate Bay database '
'downloaded from ' 'downloaded from '
@ -234,6 +240,10 @@ def combine_configs(config, args):
if not args.timeout: if not args.timeout:
args.timeout = int(config.get('Misc', 'timeout')) args.timeout = int(config.get('Misc', 'timeout'))
config_total_results = int(config.get('Search', 'total-results'))
if not args.total_results and config_total_results:
args.total_results = config_total_results
args.transmission_command = ['transmission-remote'] args.transmission_command = ['transmission-remote']
if args.endpoint: if args.endpoint:
args.transmission_command.append(args.endpoint) args.transmission_command.append(args.endpoint)
@ -389,6 +399,9 @@ def pirate_main(args):
print(json.dumps(results)) print(json.dumps(results))
return return
else: else:
# Results are sorted on the request, so it's safe to remove results here.
if args.total_results:
results = results[0:args.total_results]
printer.search_results(results, local=args.source == 'local_tpb') printer.search_results(results, local=args.source == 'local_tpb')
# number of results to pick # number of results to pick