1
0
mirror of https://github.com/vikstrous/pirate-get synced 2025-01-25 12:24:20 +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) mags, sizes, uploaded = remote(args, mirror)
break break
except Exception, e: except Exception, e:
print(format(e))
print("Could not contact " + mirror, color="WARN") 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 # enhanced print output with column titles
print("%5s %6s %6s %-5s %-11s %-11s %s" \ print("%5s %6s %6s %-5s %-11s %-11s %s" \
% ( "LINK", "SEED", "LEECH", "RATIO", "SIZE", "UPLOAD", "NAME"), % ( "LINK", "SEED", "LEECH", "RATIO", "SIZE", "UPLOAD", "NAME"),
color="header") color="header")
cur_color = "zebra_0" cur_color = "zebra_0"
for i in range(len(mags)): for m in range(len(mags)):
magnet = mags[i] magnet = mags[m]
no_seeders = int(magnet[1]) no_seeders = int(magnet[1])
no_leechers = int(magnet[2]) no_leechers = int(magnet[2])
name = re.search("dn=([^\&]*)", magnet[0]) name = re.search("dn=([^\&]*)", magnet[0])
@ -184,39 +187,39 @@ def main():
.decode('utf-8').replace("+", " ") .decode('utf-8').replace("+", " ")
# enhanced print output with justified columns # enhanced print output with justified columns
print ("%5d %6d %6d %5.1f %-11s %-11s %s" % ( print ("%5d %6d %6d %5.1f %-11s %-11s %s" % (
i, no_seeders, no_leechers, ratio ,sizes[i], m, no_seeders, no_leechers, ratio ,sizes[m],
uploaded[i], torrent_name), color=cur_color) uploaded[m], torrent_name), color=cur_color)
if args.first: if args.first:
print("Choosing first result"); print("Choosing first result");
choice = 0 choice = (0)
else: else:
try: try:
l = raw_input("Select a link: ") l = raw_input("Select link(s): ")
except KeyboardInterrupt : except KeyboardInterrupt :
print("\nCancelled.") print("\nCancelled.")
exit() exit()
try: 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: except Exception:
choice = None choices = ()
if not choice == None: for choice in choices:
choice = int(choice)
url = mags[choice][0] url = mags[choice][0]
print
print("url:")
print(url) print(url)
if args.transmission: if args.transmission:
os.system("""transmission-remote --add "%s" """ % (url)) os.system("""transmission-remote --add "%s" """ % (url))
os.system("transmission-remote -l") os.system("transmission-remote -l")
else: else:
webbrowser.open(url) webbrowser.open(url)
else:
print("Cancelled.")
else:
print("no results")
if __name__ == "__main__": if __name__ == "__main__":
main() main()