1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 13:49:59 +00:00

updated example again

This commit is contained in:
aldacron 2017-05-18 00:27:27 -07:00
parent 63c05cd6ef
commit 67758e1eef
3 changed files with 97 additions and 84 deletions

View file

@ -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)

View file

@ -3,8 +3,9 @@
{% block body %}
<div class="alert alert-info">
<p><strong>5/18 Update:</strong>We've added an upload api for ease of uploading. See documentation <a href="https://github.com/nyaadevs/nyaa/blob/master/utils/api_uploader.py">here</a>.</p>
<p><strong>5/17 Update:</strong> 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 <kbd>clockwork planet -horrible</kbd> or <kbd>commie|horrible|cartel yowamushi</kbd> to search. For all supported operators, please visit <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html#_simple_query_string_syntax">here</a>. More features are coming soon!</p><br>
like <kbd>clockwork planet -horrible</kbd> or <kbd>commie|horrible|cartel yowamushi</kbd> to search. For all supported operators, please click <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html#_simple_query_string_syntax">here</a>. More features are coming soon!</p><br>
<p>We welcome you to provide feedback at <a href="irc://irc.rizon.net/nyaa-dev">#nyaa-dev@irc.rizon.net</a></p>
<p>Our GitHub: <a href="https://github.com/nyaadevs" target="_blank">https://github.com/nyaadevs</a> - creating <a href="https://github.com/nyaadevs/nyaa/issues">issues</a> for features and faults is recommendable!</p>
</div>

View file

@ -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)}