X-Git-Url: https://code.delx.au/webdl/blobdiff_plain/e186988703355dfa8df1822d712d78fba40ec00f..e6d5a3c8de985424a760dccc8d00c2160cac1b0a:/grabber.py diff --git a/grabber.py b/grabber.py index 9fa546f..165d5ea 100755 --- a/grabber.py +++ b/grabber.py @@ -1,14 +1,15 @@ #!/usr/bin/env python # vim:ts=4:sts=4:sw=4:noet -from common import load_root_node +from common import load_root_node, natural_sort import sys def choose(options, allow_multi): - skeys = sorted(options.keys()) - for i, key in enumerate(skeys): - print " %d) %s" % (i+1, key) - print " 0) Back" + 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()) @@ -16,7 +17,7 @@ def choose(options, allow_multi): continue if 0 in values: return - values = [options[skeys[value-1]] for value in values] + values = [reverse_map[value] for value in values] if allow_multi: return values else: @@ -30,12 +31,14 @@ def main(): node = load_root_node() while True: - options = {} + options = [] will_download = True for n in node.get_children(): - options[n.title] = n + options.append((n.title, n)) if not n.can_download: will_download = False + if node.sort_children: + 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: