qBittorrent/src/search_engine/novaprinter.py
Christophe Dumez 4a02d171b4 - BUGFIX: 'Unknown' is now displayed in search results columns where value is -1
- BUGFIX: Improved search engine core a little
- BUGFIX: Forgot to remove *.pyc files when uninstalling a search plugin
2007-09-02 07:58:25 +00:00

30 lines
No EOL
755 B
Python

#VERSION: 1.11
def prettyPrinter(dictionnary):
dictionnary['size'] = anySizeToBytes(dictionnary['size'])
print "%(link)s|%(name)s|%(size)s|%(seeds)s|%(leech)s|%(engine_url)s" % dictionnary
def anySizeToBytes(size_string):
"""
Convert a string like '1 KB' to '1024' (bytes)
"""
# separate integer from unit
try:
size, unit = size_string.split()
except:
try:
size = size_string.strip()
unit = ''.join([c for c in size if c.isalpha()])
size = size[:-len(unit)]
except:
return -1
if len(size) == 0:
return -1
size = float(size)
short_unit = unit.upper()[0]
# convert
units_dict = { 'T': 40, 'G': 30, 'M': 20, 'K': 10 }
if units_dict.has_key( short_unit ):
size = size * 2**units_dict[short_unit]
return int(size)