1
0
mirror of https://github.com/vikstrous/pirate-get synced 2025-01-10 10:04:21 +01:00

More code cosmesis

This commit is contained in:
Rnhmjoj 2014-12-03 22:43:51 +01:00
parent c823f1564e
commit 9dd8960e36

View File

@ -372,7 +372,7 @@ def main():
# new ConfigParser # new ConfigParser
config = configparser.ConfigParser() config = configparser.ConfigParser()
# default options so we dont die later # default options so we don't die later
config.add_section('SaveToFile') config.add_section('SaveToFile')
config.set('SaveToFile', 'enabled', 'false') config.set('SaveToFile', 'enabled', 'false')
config.set('SaveToFile', 'directory', '~/downloads/pirate-get/') config.set('SaveToFile', 'directory', '~/downloads/pirate-get/')
@ -443,20 +443,22 @@ def main():
opener = request.build_opener(NoRedirection) opener = request.build_opener(NoRedirection)
f = opener.open("https://proxybay.info/list.txt") f = opener.open("https://proxybay.info/list.txt")
if f.getcode() != 200: if f.getcode() != 200:
raise Exception("The pirate bay responded with an error.") raise IOError("The pirate bay responded with an error.")
res = f.read().decode('utf8') res = f.read().decode('utf8')
mirrors.append(res.split("\n")[3:]) mirrors.append(res.split("\n")[3:])
except: except IOError:
print("Could not fetch additional mirrors", color="WARN") print("Could not fetch additional mirrors", color="WARN")
for mirror in mirrors: for mirror in mirrors:
try: try:
print("Trying " + mirror) print("Trying " + mirror)
mags, sizes, uploaded, identifiers = remote(args, mirror) mags, sizes, uploaded, identifiers = remote(args, mirror)
site = mirror
break break
except Exception as e: except Exception as e:
print(format(e)) print(format(e))
print("Could not contact", mirror, color="WARN") print("Could not contact", mirror, color="WARN")
if not mags or len(mags) == 0: if not mags or len(mags) == 0:
print("no results") print("no results")
return return
@ -464,20 +466,21 @@ def main():
print_search_results(mags, sizes, uploaded) print_search_results(mags, sizes, uploaded)
if args.first: if args.first:
print("Choosing first result"); print("Choosing first result")
choices = [0] choices = [0]
elif args.download_all: elif args.download_all:
print("Downloading all results"); print("Downloading all results")
choices = range(len(mags)) choices = range(len(mags))
else: else:
# New input loop to support different link options # New input loop to support different link options
while True: while True:
try: try:
l = input("\nSelect link(s) (Type 'h' for more options" print("\nSelect links (Type 'h' for more options"
"['q' to quit]): ") ", 'q' to quit)", end="", color="alt")
l=input(": ")
except KeyboardInterrupt : except KeyboardInterrupt :
print("\nCancelled.") print("\nCancelled.")
exit() sys.exit(0)
try: try:
# Very permissive handling # Very permissive handling
@ -487,14 +490,16 @@ def main():
code = cmd_code_match.group(0).lower() code = cmd_code_match.group(0).lower()
else: else:
code = None code = None
# Clean up command codes # Clean up command codes
l = re.sub(r"^[hdfp, ]*|[hdfp, ]*$", "", l)
# Substitute multiple consecutive spaces/commas for single comma # Substitute multiple consecutive spaces/commas for single comma
l = re.sub("[ ,]+", ",", l)
# Remove anything that isn't an integer or comma. # Remove anything that isn't an integer or comma.
l = re.sub("[^0-9,]", "", l)
# Turn into list # Turn into list
l = re.sub(r"^[hdfp, ]*|[hdfp, ]*$", "", l)
l = re.sub("[ ,]+", ",", l)
l = re.sub("[^0-9,]", "", l)
choices = l.split(",") choices = l.split(",")
# Act on option, if supplied # Act on option, if supplied
print("") print("")
if code == 'h': if code == 'h':