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

Merge pull request #10 from fredefox/multiple-choices

Enable the selection of multiple torrents in one go
This commit is contained in:
Viktor Stanchev 2014-02-16 13:10:54 -05:00
commit ececf0c5ad

View File

@ -157,16 +157,19 @@ def main():
mags, sizes, uploaded = remote(args, mirror)
break
except Exception, e:
print(format(e))
print("Could not contact " + mirror, color="WARN")
if mags and len(mags) > 0:
if not mags or len(mags) == 0:
print("no results")
return
# enhanced print output with column titles
print("%5s %6s %6s %-5s %-11s %-11s %s" \
% ( "LINK", "SEED", "LEECH", "RATIO", "SIZE", "UPLOAD", "NAME"),
color="header")
cur_color = "zebra_0"
for i in range(len(mags)):
magnet = mags[i]
for m in range(len(mags)):
magnet = mags[m]
no_seeders = int(magnet[1])
no_leechers = int(magnet[2])
name = re.search("dn=([^\&]*)", magnet[0])
@ -184,39 +187,39 @@ def main():
.decode('utf-8').replace("+", " ")
# enhanced print output with justified columns
print ("%5d %6d %6d %5.1f %-11s %-11s %s" % (
i, no_seeders, no_leechers, ratio ,sizes[i],
uploaded[i], torrent_name), color=cur_color)
m, no_seeders, no_leechers, ratio ,sizes[m],
uploaded[m], torrent_name), color=cur_color)
if args.first:
print("Choosing first result");
choice = 0
choice = (0)
else:
try:
l = raw_input("Select a link: ")
l = raw_input("Select link(s): ")
except KeyboardInterrupt :
print("\nCancelled.")
exit()
try:
choice = int(l)
# Very permissive handling
# Substitute multiple consecutive spaces or commas for single comma
l = re.sub("[ ,]+", ",", l)
# Remove anything that isn't an integer or comma.
l = re.sub("[^0-9,]", "", l)
# Turn into list
choices = l.split(",")
except Exception:
choice = None
choices = ()
if not choice == None:
for choice in choices:
choice = int(choice)
url = mags[choice][0]
print
print("url:")
print(url)
if args.transmission:
os.system("""transmission-remote --add "%s" """ % (url))
os.system("transmission-remote -l")
else:
webbrowser.open(url)
else:
print("Cancelled.")
else:
print("no results")
if __name__ == "__main__":
main()