Skip to content

Commit

Permalink
Add -r/--total-results to limit search results
Browse files Browse the repository at this point in the history
-r/--total-results allows the user to specify the number of links to return in the search. Because this option operates on the total search results, i.e. it's not the number of links to show per page, -p/--pages is ignored if --total-results is set. Perhaps in the future this option can be extended to operate by page.

Added total-results to config

total-results is set in the config to be 50 by default.
I also reverted the logic that only one page would be fetched if total-results is set. Now it has the original behavior: any number of pages can be requested, and total-results will filter the final result.

Minor wording update

Wording change also for cli parameter
  • Loading branch information
jabortell authored and rnhmjoj committed Dec 26, 2021
1 parent 3ad8620 commit 838a597
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ enabled = false
; path of the database
path = ~/downloads/pirate-get/db

[Search]
; maximum number of results to show
total-results = 50

[Misc]
; specify a custom command for opening the magnet
; ex. myprogram --open %s
Expand Down
13 changes: 13 additions & 0 deletions pirate/pirate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def parse_config_file(text):
config.set('LocalDB', 'enabled', 'false')
config.set('LocalDB', 'path', expanduser('~/downloads/pirate-get/db'))

config.add_section('Search')
config.set('Search', 'total-results', 50)

config.add_section('Misc')
# TODO: try to use configparser.BasicInterpolation
# for interpolating in the command
Expand Down Expand Up @@ -146,6 +149,9 @@ def parse_args(args_in):
default=1, type=int,
help='the number of pages to fetch. '
'(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',
help='a csv file containing the Pirate Bay database '
'downloaded from '
Expand Down Expand Up @@ -234,6 +240,10 @@ def combine_configs(config, args):
if not args.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']
if args.endpoint:
args.transmission_command.append(args.endpoint)
Expand Down Expand Up @@ -389,6 +399,9 @@ def pirate_main(args):
print(json.dumps(results))
return
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')

# number of results to pick
Expand Down

0 comments on commit 838a597

Please sign in to comment.