From 67758e1eef7c943989ff0f12f91fa2a81082fd49 Mon Sep 17 00:00:00 2001 From: aldacron Date: Thu, 18 May 2017 00:27:27 -0700 Subject: [PATCH] updated example again --- nyaa/api_handler.py | 8 +- nyaa/templates/home.html | 3 +- utils/api_uploader.py | 170 +++++++++++++++++++++------------------ 3 files changed, 97 insertions(+), 84 deletions(-) diff --git a/nyaa/api_handler.py b/nyaa/api_handler.py index 1c29897..8090a5a 100644 --- a/nyaa/api_handler.py +++ b/nyaa/api_handler.py @@ -57,7 +57,7 @@ def api_upload(upload_request, user): form_info_as_dict = [] for k, v in form_info.items(): if k in ['is_anonymous', 'is_hidden', 'is_remake', 'is_complete']: - if v == 'y': + if v == True: form_info_as_dict.append((k, v)) else: form_info_as_dict.append((k, v)) @@ -65,7 +65,7 @@ def api_upload(upload_request, user): # print(repr(form_info)) except Exception as e: - return flask.make_response(flask.jsonify({"Failure": "Invalid form. See HELP in api_uploader.py"}), 400) + return flask.make_response(flask.jsonify({'Failure': ['Invalid data. See HELP in api_uploader.py']}), 400) try: torrent_file = upload_request.files['torrent_file'] @@ -81,7 +81,7 @@ def api_upload(upload_request, user): if upload_request.method == 'POST' and form.validate(): torrent = backend.handle_torrent_upload(form, user, True) - return flask.make_response(flask.jsonify({"Success": "Request was processed {0}".format(torrent.id)}), 200) + return flask.make_response(flask.jsonify({'Success': int('{0}'.format(torrent.id))}), 200) else: # print(form.errors) return_error_messages = [] @@ -89,4 +89,4 @@ def api_upload(upload_request, user): # print(error_messages) return_error_messages.extend(error_messages) - return flask.make_response(flask.jsonify({"Failure": return_error_messages}), 400) + return flask.make_response(flask.jsonify({'Failure': return_error_messages}), 400) diff --git a/nyaa/templates/home.html b/nyaa/templates/home.html index f0fb99d..1d61b7c 100644 --- a/nyaa/templates/home.html +++ b/nyaa/templates/home.html @@ -3,8 +3,9 @@ {% block body %}
+

5/18 Update:We've added an upload api for ease of uploading. See documentation here.

5/17 Update: We've added faster and more accurate search! In addition to your typical keyword search in both English and other languages, you can also now use powerful operators - like clockwork planet -horrible or commie|horrible|cartel yowamushi to search. For all supported operators, please visit here. More features are coming soon!


+ like clockwork planet -horrible or commie|horrible|cartel yowamushi to search. For all supported operators, please click here. More features are coming soon!


We welcome you to provide feedback at #nyaa-dev@irc.rizon.net

Our GitHub: https://github.com/nyaadevs - creating issues for features and faults is recommendable!

diff --git a/utils/api_uploader.py b/utils/api_uploader.py index 3102e83..2ed84f0 100644 --- a/utils/api_uploader.py +++ b/utils/api_uploader.py @@ -1,118 +1,130 @@ # Uploads a single torrent file -# Works on nyaa.si +# Works on nyaa.si and sukebei.nyaa.si # An updated version will work on sukebei.nyaa.si import json -# pip install requests -# http://docs.python-requests.org/en/master/user/install/ import requests -#url = "http://127.0.0.1:5500/api/upload" -url = "https://nyaa.si/api/upload" +''' +The POST payload to the api endpoint (/api/upload) should look like this +{ + 'auth_info': { + 'username': str, + 'password': str + }, + 'torrent_info': { + 'category': str, # see below + 'display_name': str, # optional + 'information': str, + 'description': str, + 'is_anonymous': boolean, + 'is_hidden': boolean, + 'is_remake': boolean, + 'is_complete': boolean + }, + 'torrent_file': bytes # see below example +} -# ########################## REQUIRED: YOUR USERNAME AND PASSWORD ############################## -username = "" -password = "" +A successful request should return {'Success': int(torrent_id)} +A failed request should return {'Failure': ["Failure 1", "Failure 2"...]]} + +''' # ########################################### HELP ############################################ - # ################################# CATEGORIES MUST BE EXACT ################################## -""" +''' +# Nyaa categories only for now, but api still works for sukebei + Anime - Anime - AMV : "1_1" - Anime - English : "1_2" - Anime - Non-English : "1_3" - Anime - Raw : "1_4" + Anime - AMV : '1_1' + Anime - English : '1_2' + Anime - Non-English : '1_3' + Anime - Raw : '1_4' Audio - Lossless : "2_1" - Lossy : "2_2" + Lossless : '2_1' + Lossy : '2_2' Literature - Literature - English-translated : "3_1" - Literature - Non-English : "3_2" - Literature - Non-English-Translated : "3_3" - Literature - Raw : "3_4" + Literature - English-translated : '3_1' + Literature - Non-English : '3_2' + Literature - Non-English-Translated : '3_3' + Literature - Raw : '3_4' Live Action - Live Action - English-translated : "4_1" - Live Action - Idol/Promotional Video : "4_2" - Live Action - Non-English-translated : "4_3" - Live Action - Raw : "4_4" + Live Action - English-translated : '4_1' + Live Action - Idol/Promotional Video : '4_2' + Live Action - Non-English-translated : '4_3' + Live Action - Raw : '4_4' Pictures - Pictures - Graphics : "5_1" - Pictures - Photos : "5_2" + Pictures - Graphics : '5_1' + Pictures - Photos : '5_2' Software - Software - Applications : "6_1" - Software - Games : "6_2" -""" + Software - Applications : '6_1' + Software - Games : '6_2' +''' # ################################# CATEGORIES MUST BE EXACT ################################## # ###################################### EXAMPLE REQUEST ###################################### -""" +''' # Required -file_name = "/path/to/my_file.torrent" -# Required -category = "6_1" -# Required -display_name = "API upload example" +username = '' +password = '' +torrent_file = '/path/to/my.torrent' +category = '1_2' + +#Optional +display_name = '' +information = 'API HOWTO' +description = 'Visit #nyaa-dev@irc.rizon.net' + +# Defaults to False, change to True to set +is_anonymous : False, +is_hidden : False, +is_remake : False, +is_complete : False +''' -# May be blank -information = "API HOWTO" -# May be blank -description = "Visit #nyaa-dev@irc.rizon.net" -# Default is 'n' No -# Change to 'y' Yes to set -is_anonymous : 'n', -is_hidden : 'n', -is_remake : 'n', -is_complete : 'n' -""" -# ############################################################################################# # ######################################## CHANGE HERE ######################################## -# Required -file_name = "" -# Required -category = "" -# Required -display_name = "" -# May be blank -information = "" -# May be blank -description = "" -# Default is 'n' No -# Change to 'y' Yes to set -is_anonymous = 'n' -is_hidden = 'n' -is_remake = 'n' -is_complete = 'n' -# ############################################################################################# +url = 'https://nyaa.si/api/upload' # or https://sukebei.nyaa.si/api/upload or http://127.0.0.1:5500/api/upload + +# Required +username = '' +password = '' +torrent_file = '' +category = '' + +# Optional +display_name = '' +information = '' +description = '' +is_anonymous = False +is_hidden = False +is_remake = False +is_complete = False -# #################################### DO NOT CHANGE BELOW #################################### -# ############################ UNLESS YOU KNOW WHAT YOU ARE DOING ############################# auth_info = { - "username" : username, - "password" : password + 'username' : username, + 'password' : password } metadata={ - "category" : category, - "display_name" : display_name, - "information" : information, - "description" : description, - "is_anonymous" : is_anonymous, - "is_hidden" : is_hidden, - "is_remake" : is_remake, - "is_complete" : is_complete + 'category' : category, + 'display_name' : display_name, + 'information' : information, + 'description' : description, + 'is_anonymous' : is_anonymous, + 'is_hidden' : is_hidden, + 'is_remake' : is_remake, + 'is_complete' : is_complete } files = { 'auth_info' : (json.dumps(auth_info)), 'torrent_info' : (json.dumps(metadata)), - 'torrent_file' : ('{0}'.format(file_name), open(file_name, 'rb'), 'application/octet-stream') + 'torrent_file' : ('{0}'.format(torrent_file), open(torrent_file, 'rb'), 'application/octet-stream') } response = requests.post(url, files=files) - json_response = response.json() - print(json_response) +# A successful request should print {'Success': int(torrent_id)} \ No newline at end of file