Skip to content

Commit 608cb0a

Browse files
authored
Merge pull request #138 from jabortell/limit_results
Add -r/--total-results to limit search results
2 parents a366263 + c7eba63 commit 608cb0a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ enabled = false
4343
; path of the database
4444
path = ~/downloads/pirate-get/db
4545

46+
[Search]
47+
; maximum number of results to show
48+
total-results = 50
49+
4650
[Misc]
4751
; specify a custom command for opening the magnet
4852
; ex. myprogram --open %s

pirate/pirate.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def parse_config_file(text):
3131
config.add_section('LocalDB')
3232
config.set('LocalDB', 'enabled', 'false')
3333
config.set('LocalDB', 'path', expanduser('~/downloads/pirate-get/db'))
34+
35+
config.add_section('Search')
36+
config.set('Search', 'total-results', 50)
3437

3538
config.add_section('Misc')
3639
# TODO: try to use configparser.BasicInterpolation
@@ -146,6 +149,9 @@ def parse_args(args_in):
146149
default=1, type=int,
147150
help='the number of pages to fetch. '
148151
'(only used with --recent)')
152+
parser.add_argument('-r', '--total-results',
153+
type=int,
154+
help='maximum number of results to show')
149155
parser.add_argument('-L', '--local', dest='database',
150156
help='a csv file containing the Pirate Bay database '
151157
'downloaded from '
@@ -234,6 +240,10 @@ def combine_configs(config, args):
234240
if not args.timeout:
235241
args.timeout = int(config.get('Misc', 'timeout'))
236242

243+
config_total_results = int(config.get('Search', 'total-results'))
244+
if not args.total_results and config_total_results:
245+
args.total_results = config_total_results
246+
237247
args.transmission_command = ['transmission-remote']
238248
if args.endpoint:
239249
args.transmission_command.append(args.endpoint)
@@ -389,6 +399,9 @@ def pirate_main(args):
389399
print(json.dumps(results))
390400
return
391401
else:
402+
# Results are sorted on the request, so it's safe to remove results here.
403+
if args.total_results:
404+
results = results[0:args.total_results]
392405
printer.search_results(results, local=args.source == 'local_tpb')
393406

394407
# number of results to pick

0 commit comments

Comments
 (0)