Skip to content

Commit

Permalink
Request changes, added print options
Browse files Browse the repository at this point in the history
  • Loading branch information
kyamiko committed May 31, 2017
1 parent e3d0f23 commit 783bf0d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
9 changes: 5 additions & 4 deletions nyaa/api_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,12 @@ def v2_api_info(torrent_id_or_hash):
'information': torrent.information,
'description': torrent.description,
'stats': {'seeders': torrent.stats.seed_count, 'leechers': torrent.stats.leech_count, 'downloads': torrent.stats.download_count},
'filesize': torrent.filesize,
'files': files,
# reduce torrent flags to 0/1
'is_trusted': 1 if torrent.trusted else 0,
'is_complete': 1 if torrent.complete else 0,
'is_remake': 1 if torrent.remake else 0
# reduce torrent flags to True/False
'is_trusted': True if torrent.trusted else False,
'is_complete': True if torrent.complete else False,
'is_remake': True if torrent.remake else False
}

return flask.jsonify(torrent_metadata), 200
24 changes: 19 additions & 5 deletions utils/api_info_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

parser.add_argument('-q', '--query', required=True, help='Torrent by id or hash Required.')

parser.add_argument('--raw', default=False, action='store_true', help='Print only raw response (JSON)')

if __name__ == '__main__':
args = parser.parse_args()

Expand Down Expand Up @@ -61,8 +63,20 @@
# Go!
r = requests.get(api_info_url, auth=auth)

#print(r.text)

# For printing unicode instead of unicode escape sequences
jr = json.loads(r.text)
pprint(jr)
if args.raw:
print(r.text)
else:
try:
rj = r.json()
except ValueError:
print('Bad response:')
print(r.text)
exit(1)

errors = rj.get('errors')

if errors:
print('Info request failed:', errors)
exit(1)
else:
print("Torrent #{} '{}' uploaded by '{}' ({} bytes) {} / {}\n{}".format(rj['id'], rj['name'], rj['submitter'], rj['filesize'], rj['main_category'], rj['sub_category'], rj['magnet']))

0 comments on commit 783bf0d

Please sign in to comment.