mirror of
https://github.com/vikstrous/pirate-get
synced 2025-01-10 10:04:21 +01:00
Clean up whitespaces (tabs to 4 spaces)
Damn you vim and your odd defaults.
This commit is contained in:
parent
f6d1b5f806
commit
22011038b6
102
pirate-get.py
102
pirate-get.py
@ -234,31 +234,31 @@ def main():
|
|||||||
return
|
return
|
||||||
# enhanced print output with column titles
|
# enhanced print output with column titles
|
||||||
def print_search_results():
|
def print_search_results():
|
||||||
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 m in range(len(mags)):
|
for m in range(len(mags)):
|
||||||
magnet = mags[m]
|
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])
|
||||||
|
|
||||||
# compute the S/L ratio (Higher is better)
|
# compute the S/L ratio (Higher is better)
|
||||||
try:
|
try:
|
||||||
ratio = no_seeders/no_leechers
|
ratio = no_seeders/no_leechers
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
ratio = -1
|
ratio = -1
|
||||||
|
|
||||||
# Alternate between colors
|
# Alternate between colors
|
||||||
cur_color = "zebra_0" if (cur_color == "zebra_1") else "zebra_1"
|
cur_color = "zebra_0" if (cur_color == "zebra_1") else "zebra_1"
|
||||||
|
|
||||||
torrent_name = urllib.unquote(name.group(1).encode('ascii')) \
|
torrent_name = urllib.unquote(name.group(1).encode('ascii')) \
|
||||||
.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" % (
|
||||||
m, no_seeders, no_leechers, ratio ,sizes[m],
|
m, no_seeders, no_leechers, ratio ,sizes[m],
|
||||||
uploaded[m], torrent_name), color=cur_color)
|
uploaded[m], torrent_name), color=cur_color)
|
||||||
def print_descriptions(chosen_links):
|
def print_descriptions(chosen_links):
|
||||||
for link in chosen_links:
|
for link in chosen_links:
|
||||||
path = '/torrent/' + identifiers[int(link)] + '/'
|
path = '/torrent/' + identifiers[int(link)] + '/'
|
||||||
@ -269,9 +269,9 @@ def main():
|
|||||||
buf = StringIO(f.read())
|
buf = StringIO(f.read())
|
||||||
f = gzip.GzipFile(fileobj=buf)
|
f = gzip.GzipFile(fileobj=buf)
|
||||||
res = f.read()
|
res = f.read()
|
||||||
name = re.search("dn=([^\&]*)", mags[int(link)][0])
|
name = re.search("dn=([^\&]*)", mags[int(link)][0])
|
||||||
torrent_name = urllib.unquote(name.group(1).encode('ascii')) \
|
torrent_name = urllib.unquote(name.group(1).encode('ascii')) \
|
||||||
.decode('utf-8').replace("+", " ")
|
.decode('utf-8').replace("+", " ")
|
||||||
desc = re.search(r"<div class=\"nfo\">\s*<pre>(.+?)(?=</pre>)", res, re.DOTALL).group(1)
|
desc = re.search(r"<div class=\"nfo\">\s*<pre>(.+?)(?=</pre>)", res, re.DOTALL).group(1)
|
||||||
# Replace HTML links with markdown style versions
|
# Replace HTML links with markdown style versions
|
||||||
desc = re.sub(r"<a href=\"\s*([^\"]+?)\s*\"[^>]*>(\s*)([^<]+?)(\s*)</a>", r"\2[\3](\1)\4", desc)
|
desc = re.sub(r"<a href=\"\s*([^\"]+?)\s*\"[^>]*>(\s*)([^<]+?)(\s*)</a>", r"\2[\3](\1)\4", desc)
|
||||||
@ -290,9 +290,9 @@ def main():
|
|||||||
f = gzip.GzipFile(fileobj=buf)
|
f = gzip.GzipFile(fileobj=buf)
|
||||||
res = f.read().replace(" ", " ")
|
res = f.read().replace(" ", " ")
|
||||||
files = re.findall(r"<td align=\"left\">\s*([^<]+?)\s*</td><td align=\"right\">\s*([^<]+?)\s*</tr>", res)
|
files = re.findall(r"<td align=\"left\">\s*([^<]+?)\s*</td><td align=\"right\">\s*([^<]+?)\s*</tr>", res)
|
||||||
name = re.search("dn=([^\&]*)", mags[int(link)][0])
|
name = re.search("dn=([^\&]*)", mags[int(link)][0])
|
||||||
torrent_name = urllib.unquote(name.group(1).encode('ascii')) \
|
torrent_name = urllib.unquote(name.group(1).encode('ascii')) \
|
||||||
.decode('utf-8').replace("+", " ")
|
.decode('utf-8').replace("+", " ")
|
||||||
print ('Files in "' + torrent_name + '":', color="zebra_1")
|
print ('Files in "' + torrent_name + '":', color="zebra_1")
|
||||||
cur_color = "zebra_0"
|
cur_color = "zebra_0"
|
||||||
for f in files:
|
for f in files:
|
||||||
@ -309,29 +309,29 @@ def main():
|
|||||||
choices = range(0, len(mags))
|
choices = range(0, 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 = raw_input("Select link(s) (Type 'h' for more options): ")
|
l = raw_input("Select link(s) (Type 'h' for more options): ")
|
||||||
except KeyboardInterrupt :
|
except KeyboardInterrupt :
|
||||||
print("\nCancelled.")
|
print("\nCancelled.")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Very permissive handling
|
# Very permissive handling
|
||||||
# Check for any occurances or d, f, or p
|
# Check for any occurances or d, f, or p
|
||||||
cmd_code_match = re.search(r'([hdfp])', l, flags=re.IGNORECASE)
|
cmd_code_match = re.search(r'([hdfp])', l, flags=re.IGNORECASE)
|
||||||
if cmd_code_match:
|
if cmd_code_match:
|
||||||
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)
|
l = re.sub(r"^[hdfp, ]*|[hdfp, ]*$", "", l)
|
||||||
# Substitute multiple consecutive spaces or commas for single comma
|
# Substitute multiple consecutive spaces or commas for single comma
|
||||||
l = re.sub("[ ,]+", ",", l)
|
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)
|
l = re.sub("[^0-9,]", "", l)
|
||||||
# Turn into list
|
# Turn into list
|
||||||
choices = l.split(",")
|
choices = l.split(",")
|
||||||
# Act on option, if supplied
|
# Act on option, if supplied
|
||||||
if code == 'h':
|
if code == 'h':
|
||||||
print("Options:")
|
print("Options:")
|
||||||
@ -354,10 +354,10 @@ def main():
|
|||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print('Exception:')
|
print('Exception:')
|
||||||
print(str(e))
|
print(str(e))
|
||||||
choices = ()
|
choices = ()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if config.get('SaveToFile', 'enabled'):
|
if config.get('SaveToFile', 'enabled'):
|
||||||
@ -382,7 +382,7 @@ def main():
|
|||||||
os.system("""transmission-remote --add "%s" """ % (url))
|
os.system("""transmission-remote --add "%s" """ % (url))
|
||||||
os.system("transmission-remote -l")
|
os.system("transmission-remote -l")
|
||||||
elif args.command:
|
elif args.command:
|
||||||
os.system(args.command % (url))
|
os.system(args.command % (url))
|
||||||
else:
|
else:
|
||||||
webbrowser.open(url)
|
webbrowser.open(url)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user