diff --git a/nyaa/api_handler.py b/nyaa/api_handler.py index aa09752e..d6342768 100644 --- a/nyaa/api_handler.py +++ b/nyaa/api_handler.py @@ -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 diff --git a/utils/api_info_v2.py b/utils/api_info_v2.py index dc548f3e..31b0a863 100644 --- a/utils/api_info_v2.py +++ b/utils/api_info_v2.py @@ -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() @@ -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']))