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

Update print_search_results for --local mode

This commit is contained in:
Rnhmjoj 2015-03-27 22:08:32 +01:00
parent 73f1221f36
commit 0bee36746e

View File

@ -1,5 +1,3 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# Copyright 2015, Viktor Stanchev and contributors # Copyright 2015, Viktor Stanchev and contributors
@ -327,20 +325,35 @@ def get_torrent(info_hash):
return torrent.read() return torrent.read()
# enhanced print output with column titles def print_search_results(mags, sizes, uploaded, local):
def print_search_results(mags, sizes, uploaded): columns = int(os.popen('stty size', 'r').read().split()[1])
columns = int(os.popen('stty size', 'r').read().split()[1]) - 52
cur_color = 'zebra_0' cur_color = 'zebra_0'
if local:
print('{:>4} {:{length}}'.format(
'LINK', 'NAME', length=columns - 8),
color='header')
else:
print('{:>4} {:>5} {:>5} {:>5} {:9} {:11} {:{length}}'.format( print('{:>4} {:>5} {:>5} {:>5} {:9} {:11} {:{length}}'.format(
'LINK', 'SEED', 'LEECH', 'RATIO', 'LINK', 'SEED', 'LEECH', 'RATIO',
'SIZE', 'UPLOAD', 'NAME', length=columns), 'SIZE', 'UPLOAD', 'NAME', length=columns - 52),
color='header') color='header')
for m, magnet in enumerate(mags): for m, magnet in enumerate(mags):
no_seeders = int(magnet[1]) # Alternate between colors
no_leechers = int(magnet[2]) cur_color = 'zebra_0' if cur_color == 'zebra_1' else 'zebra_1'
name = re.search(r'dn=([^\&]*)', magnet[0]) name = re.search(r'dn=([^\&]*)', magnet[0])
torrent_name = parse.unquote(name.group(1)).replace('+', ' ')
if local:
line = '{:5} {:{length}}'
content = [m, torrent_name[:columns]]
else:
no_seeders, no_leechers = map(int, magnet[1:])
size = float(sizes[m][0])
unit = sizes[m][1]
date = uploaded[m]
# compute the S/L ratio (Higher is better) # compute the S/L ratio (Higher is better)
try: try:
@ -348,18 +361,13 @@ def print_search_results(mags, sizes, uploaded):
except ZeroDivisionError: except ZeroDivisionError:
ratio = float('inf') ratio = float('inf')
# Alternate between colors line = ('{:4} {:5} {:5} {:5.1f} {:5.1f}'
cur_color = 'zebra_0' if (cur_color == 'zebra_1') else 'zebra_1' ' {:3} {:<11} {:{length}}')
content = [m, no_seeders, no_leechers, ratio,
size, unit, date, torrent_name[:columns - 52]]
torrent_name = parse.unquote(name.group(1)).replace('+', ' ')
# enhanced print output with justified columns # enhanced print output with justified columns
print('{:4} {:5} {:5} {:5.1f} {:5.1f} {:3} ' print(line.format(*content, length=columns - 52), color=cur_color)
'{:<11} {:{length}}'.format(m, no_seeders, no_leechers,
ratio, float(sizes[m][0]),
sizes[m][1], uploaded[m],
torrent_name[:columns],
length=columns),
color=cur_color)
def print_descriptions(chosen_links, mags, site, identifiers): def print_descriptions(chosen_links, mags, site, identifiers):
@ -533,6 +541,7 @@ def main():
else: else:
path = config.get('LocalDB', 'path') path = config.get('LocalDB', 'path')
mags = local(path, args.search) mags = local(path, args.search)
sizes, uploaded = [], []
else: else:
mags, mirrors = [], [] mags, mirrors = [], []
@ -563,7 +572,7 @@ def main():
print('No results') print('No results')
return return
print_search_results(mags, sizes, uploaded) print_search_results(mags, sizes, uploaded, local=args.database)
if args.first: if args.first:
print('Choosing first result') print('Choosing first result')