3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are met:
6 # * Redistributions of source code must retain the above copyright notice,
7 # this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution.
11 # * Neither the name of the author nor the names of its contributors may be
12 # used to endorse or promote products derived from this software without
13 # specific prior written permission.
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
28 def prettyPrinter(dictionary
):
29 dictionary
['size'] = anySizeToBytes(dictionary
['size'])
30 outtext
= "|".join((dictionary
["link"], dictionary
["name"].replace("|", " "),
31 str(dictionary
["size"]), str(dictionary
["seeds"]),
32 str(dictionary
["leech"]), dictionary
["engine_url"]))
33 if 'desc_link' in dictionary
:
34 outtext
= "|".join((outtext
, dictionary
["desc_link"]))
37 with
open(1, 'w', encoding
='utf-8', closefd
=False) as utf8stdout
:
38 print(outtext
, file=utf8stdout
)
41 def anySizeToBytes(size_string
):
43 Convert a string like '1 KB' to '1024' (bytes)
45 # separate integer from unit
47 size
, unit
= size_string
.split()
50 size
= size_string
.strip()
51 unit
= ''.join([c
for c
in size
if c
.isalpha()])
53 size
= size
[:-len(unit
)]
61 short_unit
= unit
.upper()[0]
64 units_dict
= {'T': 40, 'G': 30, 'M': 20, 'K': 10}
65 if short_unit
in units_dict
:
66 size
= size
* 2**units_dict
[short_unit
]