mirror of
https://github.com/vikstrous/pirate-get
synced 2025-01-10 10:04:21 +01:00
handle search with no terms/results
This commit is contained in:
parent
5a6429d61d
commit
5daf53dab1
@ -67,11 +67,18 @@ def make_magnet(name, info_hash):
|
|||||||
def remote(printer, category, sort, mode, terms, mirror, timeout):
|
def remote(printer, category, sort, mode, terms, mirror, timeout):
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
|
# special query when no terms
|
||||||
|
if not terms:
|
||||||
|
if category == 0:
|
||||||
|
category = 'all'
|
||||||
|
query = '/precompiled/data_top100_{}.json'.format(category)
|
||||||
|
else:
|
||||||
|
query = '/q.php?q={}&cat={}'.format(' '.join(terms), category)
|
||||||
|
|
||||||
# Catch the Ctrl-C exception and exit cleanly
|
# Catch the Ctrl-C exception and exit cleanly
|
||||||
try:
|
try:
|
||||||
req = request.Request(
|
req = request.Request(
|
||||||
'{}/q.php?q={}&cat={}'.format(
|
mirror + query,
|
||||||
mirror, ' '.join(terms), category),
|
|
||||||
headers=pirate.data.default_headers)
|
headers=pirate.data.default_headers)
|
||||||
try:
|
try:
|
||||||
f = request.urlopen(req, timeout=timeout)
|
f = request.urlopen(req, timeout=timeout)
|
||||||
@ -80,7 +87,12 @@ def remote(printer, category, sort, mode, terms, mirror, timeout):
|
|||||||
|
|
||||||
if f.info().get('Content-Encoding') == 'gzip':
|
if f.info().get('Content-Encoding') == 'gzip':
|
||||||
f = gzip.GzipFile(fileobj=BytesIO(f.read()))
|
f = gzip.GzipFile(fileobj=BytesIO(f.read()))
|
||||||
for res in json.load(f):
|
data = json.load(f)
|
||||||
|
|
||||||
|
if len(data) == 1 and 'No results' in data[0]['name']:
|
||||||
|
return []
|
||||||
|
|
||||||
|
for res in data:
|
||||||
res['size'] = pretty_size(int(res['size']))
|
res['size'] = pretty_size(int(res['size']))
|
||||||
res['magnet'] = make_magnet(res['name'], res['info_hash'])
|
res['magnet'] = make_magnet(res['name'], res['info_hash'])
|
||||||
res['info_hash'] = int(res['info_hash'], 16)
|
res['info_hash'] = int(res['info_hash'], 16)
|
||||||
|
Loading…
Reference in New Issue
Block a user