mirror of
https://github.com/vikstrous/pirate-get
synced 2025-01-10 10:04:21 +01:00
Enhanced output
Column titles, column alignment, exception handling, S/L ratio and file size display
This commit is contained in:
parent
3affc9171d
commit
43444db191
@ -60,67 +60,44 @@ def main():
|
|||||||
except Exception:
|
except Exception:
|
||||||
raise Exception("Please provide an integer greater than 0 for the number of pages to fetch.")
|
raise Exception("Please provide an integer greater than 0 for the number of pages to fetch.")
|
||||||
|
|
||||||
# Catch the Ctrl-C exception and exit cleanly
|
for page in xrange(pages):
|
||||||
try:
|
f = urllib2.urlopen('http://thepiratebay.se/search/' + args.q.replace(" ", "+") + '/' + str(page) + '/7/0')
|
||||||
for page in xrange(pages):
|
res = f.read()
|
||||||
f = urllib2.urlopen('http://thepiratebay.se/search/' + args.q.replace(" ", "+") + '/' + str(page) + '/7/0')
|
found = re.findall(""""(magnet\:\?xt=[^"]*)|<td align="right">([^<]+)</td>""", res)
|
||||||
res = f.read()
|
state = "seeds"
|
||||||
found = re.findall(""""(magnet\:\?xt=[^"]*)|<td align="right">([^<]+)</td>""", res)
|
curr = ['',0,0] #magnet, seeds, leeches
|
||||||
|
for f in found:
|
||||||
# get sizes as well and substitute the character
|
if f[1] == '':
|
||||||
sizes = [ match.replace(" ", " ") for match in re.findall("(?<=Size )[0-9]+\.[0-9]+\ \;[KMGT]iB",res) ]
|
curr[0] = f[0]
|
||||||
|
else:
|
||||||
state = "seeds"
|
if state == 'seeds':
|
||||||
curr = ['',0,0] #magnet, seeds, leeches
|
curr[1] = f[1]
|
||||||
for f in found:
|
state = 'leeches'
|
||||||
if f[1] == '':
|
|
||||||
curr[0] = f[0]
|
|
||||||
else:
|
else:
|
||||||
if state == 'seeds':
|
curr[2] = f[1]
|
||||||
curr[1] = f[1]
|
state = 'seeds'
|
||||||
state = 'leeches'
|
res_l.append(curr)
|
||||||
else:
|
curr = ['', 0, 0]
|
||||||
curr[2] = f[1]
|
return res_l
|
||||||
state = 'seeds'
|
|
||||||
res_l.append(curr)
|
|
||||||
curr = ['', 0, 0]
|
|
||||||
except KeyboardInterrupt :
|
|
||||||
print "\nCancelled."
|
|
||||||
exit()
|
|
||||||
|
|
||||||
# return the sizes in a spearate list
|
|
||||||
return res_l, sizes
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.database:
|
if args.database:
|
||||||
mags = local(args)
|
mags = local(args)
|
||||||
else:
|
else:
|
||||||
mags, sizes = remote(args)
|
mags = remote(args)
|
||||||
|
|
||||||
if mags and len(mags) > 0:
|
if mags and len(mags) > 0:
|
||||||
# enhanced print output with column titles
|
print "S=seeders"
|
||||||
print "\n%-5s %-6s %-6s %-5s %-11s %s" % ( "LINK", "SEED", "LEECH", "RATIO", "SIZE", "NAME")
|
print "L=leechers"
|
||||||
for m in range(len(mags)):
|
for m in range(len(mags)):
|
||||||
magnet = mags[m]
|
magnet = mags[m]
|
||||||
name = re.search("dn=([^\&]*)", magnet[0])
|
name = re.search("dn=([^\&]*)", magnet[0])
|
||||||
|
print str(m) + '. S:' + str(magnet[1]) + ' L:' + str(magnet[2]) + ' ', urllib.unquote(name.group(1).encode('ascii')).decode('utf-8').replace("+", " ")
|
||||||
# compute the S/L ratio (Higher is better)
|
l = raw_input("Select a link: ")
|
||||||
ratio = float(magnet[1])/float(magnet[2])
|
|
||||||
|
|
||||||
# enhanced print output with justified columns
|
|
||||||
print "%-5s %-6s %-6s %5.1f %-11s %s" % (m, magnet[1], magnet[2], ratio ,sizes[m], urllib.unquote(name.group(1).encode('ascii')).decode('utf-8').replace("+", " ") )
|
|
||||||
|
|
||||||
try:
|
|
||||||
l = raw_input("Select a link: ")
|
|
||||||
except KeyboardInterrupt :
|
|
||||||
print "\nCancelled."
|
|
||||||
exit()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
choice = int(l)
|
choice = int(l)
|
||||||
except Exception:
|
except Exception:
|
||||||
choice = None
|
choice = None
|
||||||
|
|
||||||
if not choice == None:
|
if not choice == None:
|
||||||
webbrowser.open(mags[choice][0])
|
webbrowser.open(mags[choice][0])
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user