X-Git-Url: https://code.delx.au/webdl/blobdiff_plain/6ae0906ce5d89baf76d7e3e9476810cb0a62d383..8c1040ccbc3e3dd49a0b38f7517181052bcf9f8e:/grabber.py diff --git a/grabber.py b/grabber.py index 7d27ddb..90708e7 100755 --- a/grabber.py +++ b/grabber.py @@ -1,59 +1,58 @@ -#!/usr/bin/env python -# vim:ts=4:sts=4:sw=4:noet +#!/usr/bin/python2 from common import load_root_node, natural_sort import sys def choose(options, allow_multi): - reverse_map = {} - for i, (key, value) in enumerate(options): - print "%3d) %s" % (i+1, key) - reverse_map[i+1] = value - print " 0) Back" - while True: - try: - values = map(int, raw_input("Choose> ").split()) - if len(values) == 0: - continue - if 0 in values: - return - values = [reverse_map[value] for value in values if value in reverse_map] - if allow_multi: - return values - else: - if len(values) == 1: - return values[0] - except (ValueError, IndexError): - print >>sys.stderr, "Invalid input, please try again" - pass + reverse_map = {} + for i, (key, value) in enumerate(options): + print "%3d) %s" % (i+1, key) + reverse_map[i+1] = value + print " 0) Back" + while True: + try: + values = map(int, raw_input("Choose> ").split()) + if len(values) == 0: + continue + if 0 in values: + return + values = [reverse_map[value] for value in values if value in reverse_map] + if allow_multi: + return values + else: + if len(values) == 1: + return values[0] + except (ValueError, IndexError): + print >>sys.stderr, "Invalid input, please try again" + pass def main(): - node = load_root_node() + node = load_root_node() - while True: - options = [] - will_download = True - for n in node.get_children(): - options.append((n.title, n)) - if not n.can_download: - will_download = False - options = natural_sort(options, key=lambda x: x[0]) - result = choose(options, allow_multi=will_download) - if result is None: - if node.parent is not None: - node = node.parent - else: - break - elif will_download: - for n in result: - if not n.download(): - raw_input("Press return to continue...\n") - else: - node = result + while True: + options = [] + will_download = True + for n in node.get_children(): + options.append((n.title, n)) + if not n.can_download: + will_download = False + options = natural_sort(options, key=lambda x: x[0]) + result = choose(options, allow_multi=will_download) + if result is None: + if node.parent is not None: + node = node.parent + else: + break + elif will_download: + for n in result: + if not n.download(): + raw_input("Press return to continue...\n") + else: + node = result if __name__ == "__main__": - try: - main() - except (KeyboardInterrupt, EOFError): - print "\nExiting..." + try: + main() + except (KeyboardInterrupt, EOFError): + print "\nExiting..."