1
0
mirror of https://github.com/vikstrous/pirate-get synced 2025-01-09 09:59:51 +01:00

implement browse mode

This commit is contained in:
Michele Guerini Rocco 2020-05-25 10:02:00 +02:00
parent 496b0f09b0
commit 9e7d00e0ce
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450
3 changed files with 13 additions and 4 deletions

View File

@ -320,6 +320,13 @@ def search_mirrors(printer, args):
def pirate_main(args):
printer = Printer(args.color)
# browse mode needs a specific category
if args.browse:
if args.category == 'All' or args.category == 0:
printer.print('You must select a specific category in browse mode.'
' ("All" is not valid)', color='ERROR')
sys.exit(1)
# print version
if args.version:
printer.print('pirate-get, version {}'.format(pirate.data.version))

View File

@ -102,7 +102,9 @@ def build_request_path(mode, category, terms):
elif mode == 'recent':
query = '/precompiled/data_top100_recent.json'
elif mode == 'browse':
raise NotImplementedError
if category == 0:
raise Exception('You must specify a category')
query = '/q.php?q=category:{}'.format(category)
else:
raise Exception('Invalid mode', mode)

View File

@ -77,11 +77,11 @@ class TestTorrent(unittest.TestCase):
(('search', 100, ['abc']), '/q.php?q=abc&cat=100'),
(('search', 100, ['abc', 'def']), '/q.php?q=abc%20def&cat=100'),
(('search', 100, ['\u1234']), '/q.php?q=%E1%88%B4&cat=100'),
(('browse', 100, []), '/q.php?q=category%3A100'),
]
fail = [
(('browse', 100, []), NotImplementedError),
(('browse', 0, []), NotImplementedError),
(('asdf', 100, []), Exception),
(('browse', 0, []), Exception),
(('asdf', 100, []), Exception)
]
for inp, out in succeed:
path = pirate.torrent.build_request_path(*inp)