Skip to content

Commit

Permalink
Updated API info, resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
kyamiko committed May 31, 2017
1 parent 17ed7cb commit e3d0f23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 7 additions & 3 deletions nyaa/api_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def ghetto_import():
INFO_HASH_PATTERN = '^[0-9a-fA-F]{40}$' # INFO_HASH as string


@api_blueprint.route('/v2/info/<torrent_id_or_hash>', methods=['GET'])
@api_blueprint.route('/info/<torrent_id_or_hash>', methods=['GET'])
@basic_auth_user
@api_require_user
def v2_api_info(torrent_id_or_hash):
Expand Down Expand Up @@ -326,7 +326,7 @@ def v2_api_info(torrent_id_or_hash):
'id': torrent.id,
'name': torrent.display_name,
'hash_b32': torrent.info_hash_as_b32, #as used in magnet uri
'hash_hex': torrent.info_hash.hex(), #as shown in torrent client
'hash_hex': torrent.info_hash_as_hex, #.hex(), #as shown in torrent client
'magnet': torrent.magnet_uri,
'main_category': torrent.main_category.name,
'main_category_id': torrent.main_category.id,
Expand All @@ -335,7 +335,11 @@ 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},
'filelist': files
'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
}

return flask.jsonify(torrent_metadata), 200
9 changes: 7 additions & 2 deletions utils/api_info_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import argparse
import requests
import json
from pprint import pprint

DEV_HOST = 'http://127.0.0.1:5500'
NYAA_HOST = 'https://nyaa.si'
SUKEBEI_HOST = 'https://sukebei.nyaa.si'

API_BASE = '/api'
API_INFO = API_BASE + '/v2/info'
API_INFO = API_BASE + '/info'

ID_PATTERN = '^[1-9][0-9]*$'
INFO_HASH_PATTERN = '^[0-9a-fA-F]{40}$'
Expand Down Expand Up @@ -60,4 +61,8 @@
# Go!
r = requests.get(api_info_url, auth=auth)

print(r.text)
#print(r.text)

# For printing unicode instead of unicode escape sequences
jr = json.loads(r.text)
pprint(jr)

0 comments on commit e3d0f23

Please sign in to comment.