diff --git a/pirate/pirate.py b/pirate/pirate.py index 53d44af..6aebd8f 100755 --- a/pirate/pirate.py +++ b/pirate/pirate.py @@ -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)) diff --git a/pirate/torrent.py b/pirate/torrent.py index 7d49eda..aa13780 100644 --- a/pirate/torrent.py +++ b/pirate/torrent.py @@ -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) diff --git a/tests/test_torrent.py b/tests/test_torrent.py index 0915963..fd6ecce 100755 --- a/tests/test_torrent.py +++ b/tests/test_torrent.py @@ -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)