1
0
mirror of https://github.com/vikstrous/pirate-get synced 2025-04-22 01:48:39 +02:00

Compare commits

...

6 Commits

Author SHA1 Message Date
f0cf30bd48
set version to 0.4.2 2022-03-15 17:34:52 +01:00
edc547428b
update proxybay url 2022-03-15 17:31:48 +01:00
c0ca18f2da
set version to 0.4.1 2021-12-26 12:15:40 +01:00
Jacob Bortell
838a5973b9
Add -r/--total-results to limit search results
-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
2021-12-26 12:11:06 +01:00
morhook
3ad8620fbd Fixed error handling
On my computer it's failing on the first request to https://thepiratebay.org/ . I think the properties this code is handling need an HTTPError according to the doc https://docs.python.org/3/library/urllib.error.html\#urllib.error.URLError
2020-06-20 17:16:16 -03:00
1e9b3142a2
fix missing data in release tarball 2020-05-28 13:48:19 +02:00
5 changed files with 21 additions and 4 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

@ -6,7 +6,7 @@ def get_resource(filename):
return pkgutil.get_data(__package__, 'data/' + filename) return pkgutil.get_data(__package__, 'data/' + filename)
version = '0.4.0' version = '0.4.2'
categories = json.loads(get_resource('categories.json').decode()) categories = json.loads(get_resource('categories.json').decode())
sorts = json.loads(get_resource('sorts.json').decode()) sorts = json.loads(get_resource('sorts.json').decode())
@ -16,4 +16,4 @@ default_headers = {'User-Agent': 'pirate get'}
default_timeout = 10 default_timeout = 10
default_mirror = 'https://apibay.org' default_mirror = 'https://apibay.org'
mirror_list = 'https://proxybay.bz/list.txt' mirror_list = 'https://proxy-bay.app/list.txt'

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

View File

@ -146,7 +146,7 @@ def find_api(mirror, timeout):
f = request.urlopen(req, timeout=timeout) f = request.urlopen(req, timeout=timeout)
if f.info().get_content_type() == 'application/json': if f.info().get_content_type() == 'application/json':
return mirror + path return mirror + path
except urllib.error.URLError as e: except urllib.error.HTTPError as e:
res = e.fp.read().decode() res = e.fp.read().decode()
if e.code == 503 and 'cf-browser-verification' in res: if e.code == 503 and 'cf-browser-verification' in res:
raise IOError('Cloudflare protected') raise IOError('Cloudflare protected')

View File

@ -18,7 +18,7 @@ if __name__ == '__main__':
author_email='me@viktorstanchev.com', author_email='me@viktorstanchev.com',
license='AGPL', license='AGPL',
packages=find_packages(), packages=find_packages(),
package_data={'': ["data/*.json", "tests/data/*"]}, package_data={'': ["data/*", "tests/data/*"]},
entry_points={ entry_points={
'console_scripts': ['pirate-get = pirate.pirate:main'] 'console_scripts': ['pirate-get = pirate.pirate:main']
}, },