]> code.delx.au - webdl/blobdiff - grabber.py
autograbber: implement .excludes.txt (fixes #75)
[webdl] / grabber.py
index 90708e72259fba92c92040b3c66677baa15ec1d3..d887472483634cb6dfd0280762c2b98d20f100fa 100755 (executable)
@@ -1,21 +1,28 @@
-#!/usr/bin/python2
+#!/usr/bin/env python3
 
 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)
+        print("%3d) %s" % (i+1, key))
         reverse_map[i+1] = value
-    print "  0) Back"
+    print("  0) Back")
     while True:
         try:
-            values = map(int, raw_input("Choose> ").split())
-            if len(values) == 0:
+            str_values = input("Choose> ").split()
+            if len(str_values) == 0:
                 continue
-            if 0 in values:
+            if "0" in str_values:
                 return
+            values = []
+            for s in str_values:
+                if s.isdigit():
+                    values.append(int(s))
+                else:
+                    low, high = s.split("-", 1)
+                    values.extend(range(int(low), int(high) + 1))
             values = [reverse_map[value] for value in values if value in reverse_map]
             if allow_multi:
                 return values
@@ -23,7 +30,7 @@ def choose(options, allow_multi):
                 if len(values) == 1:
                     return values[0]
         except (ValueError, IndexError):
-            print >>sys.stderr, "Invalid input, please try again"
+            print("Invalid input, please try again")
             pass
 
 def main():
@@ -46,7 +53,7 @@ def main():
         elif will_download:
             for n in result:
                 if not n.download():
-                    raw_input("Press return to continue...\n")
+                    input("Press return to continue...\n")
         else:
             node = result
 
@@ -54,5 +61,5 @@ if __name__ == "__main__":
     try:
         main()
     except (KeyboardInterrupt, EOFError):
-        print "\nExiting..."
+        print("\nExiting...")