mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 20:00:01 +00:00
updated example again
This commit is contained in:
parent
63c05cd6ef
commit
67758e1eef
|
@ -57,7 +57,7 @@ def api_upload(upload_request, user):
|
||||||
form_info_as_dict = []
|
form_info_as_dict = []
|
||||||
for k, v in form_info.items():
|
for k, v in form_info.items():
|
||||||
if k in ['is_anonymous', 'is_hidden', 'is_remake', 'is_complete']:
|
if k in ['is_anonymous', 'is_hidden', 'is_remake', 'is_complete']:
|
||||||
if v == 'y':
|
if v == True:
|
||||||
form_info_as_dict.append((k, v))
|
form_info_as_dict.append((k, v))
|
||||||
else:
|
else:
|
||||||
form_info_as_dict.append((k, v))
|
form_info_as_dict.append((k, v))
|
||||||
|
@ -65,7 +65,7 @@ def api_upload(upload_request, user):
|
||||||
|
|
||||||
# print(repr(form_info))
|
# print(repr(form_info))
|
||||||
except Exception as e:
|
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:
|
try:
|
||||||
torrent_file = upload_request.files['torrent_file']
|
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():
|
if upload_request.method == 'POST' and form.validate():
|
||||||
torrent = backend.handle_torrent_upload(form, user, True)
|
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:
|
else:
|
||||||
# print(form.errors)
|
# print(form.errors)
|
||||||
return_error_messages = []
|
return_error_messages = []
|
||||||
|
@ -89,4 +89,4 @@ def api_upload(upload_request, user):
|
||||||
# print(error_messages)
|
# print(error_messages)
|
||||||
return_error_messages.extend(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)
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
|
||||||
<div class="alert alert-info">
|
<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
|
<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>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>
|
<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>
|
</div>
|
||||||
|
|
|
@ -1,118 +1,130 @@
|
||||||
# Uploads a single torrent file
|
# 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
|
# An updated version will work on sukebei.nyaa.si
|
||||||
|
|
||||||
import json
|
import json
|
||||||
# pip install requests
|
|
||||||
# http://docs.python-requests.org/en/master/user/install/
|
|
||||||
import requests
|
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 ##############################
|
A successful request should return {'Success': int(torrent_id)}
|
||||||
username = ""
|
A failed request should return {'Failure': ["Failure 1", "Failure 2"...]]}
|
||||||
password = ""
|
|
||||||
|
'''
|
||||||
|
|
||||||
# ########################################### HELP ############################################
|
# ########################################### HELP ############################################
|
||||||
|
|
||||||
# ################################# CATEGORIES MUST BE EXACT ##################################
|
# ################################# CATEGORIES MUST BE EXACT ##################################
|
||||||
"""
|
'''
|
||||||
|
# Nyaa categories only for now, but api still works for sukebei
|
||||||
|
|
||||||
Anime
|
Anime
|
||||||
Anime - AMV : "1_1"
|
Anime - AMV : '1_1'
|
||||||
Anime - English : "1_2"
|
Anime - English : '1_2'
|
||||||
Anime - Non-English : "1_3"
|
Anime - Non-English : '1_3'
|
||||||
Anime - Raw : "1_4"
|
Anime - Raw : '1_4'
|
||||||
Audio
|
Audio
|
||||||
Lossless : "2_1"
|
Lossless : '2_1'
|
||||||
Lossy : "2_2"
|
Lossy : '2_2'
|
||||||
Literature
|
Literature
|
||||||
Literature - English-translated : "3_1"
|
Literature - English-translated : '3_1'
|
||||||
Literature - Non-English : "3_2"
|
Literature - Non-English : '3_2'
|
||||||
Literature - Non-English-Translated : "3_3"
|
Literature - Non-English-Translated : '3_3'
|
||||||
Literature - Raw : "3_4"
|
Literature - Raw : '3_4'
|
||||||
Live Action
|
Live Action
|
||||||
Live Action - English-translated : "4_1"
|
Live Action - English-translated : '4_1'
|
||||||
Live Action - Idol/Promotional Video : "4_2"
|
Live Action - Idol/Promotional Video : '4_2'
|
||||||
Live Action - Non-English-translated : "4_3"
|
Live Action - Non-English-translated : '4_3'
|
||||||
Live Action - Raw : "4_4"
|
Live Action - Raw : '4_4'
|
||||||
Pictures
|
Pictures
|
||||||
Pictures - Graphics : "5_1"
|
Pictures - Graphics : '5_1'
|
||||||
Pictures - Photos : "5_2"
|
Pictures - Photos : '5_2'
|
||||||
Software
|
Software
|
||||||
Software - Applications : "6_1"
|
Software - Applications : '6_1'
|
||||||
Software - Games : "6_2"
|
Software - Games : '6_2'
|
||||||
"""
|
'''
|
||||||
# ################################# CATEGORIES MUST BE EXACT ##################################
|
# ################################# CATEGORIES MUST BE EXACT ##################################
|
||||||
|
|
||||||
# ###################################### EXAMPLE REQUEST ######################################
|
# ###################################### EXAMPLE REQUEST ######################################
|
||||||
"""
|
'''
|
||||||
# Required
|
# Required
|
||||||
file_name = "/path/to/my_file.torrent"
|
username = ''
|
||||||
# Required
|
password = ''
|
||||||
category = "6_1"
|
torrent_file = '/path/to/my.torrent'
|
||||||
# Required
|
category = '1_2'
|
||||||
display_name = "API upload example"
|
|
||||||
|
#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 ########################################
|
# ######################################## CHANGE HERE ########################################
|
||||||
# Required
|
|
||||||
file_name = ""
|
|
||||||
# Required
|
|
||||||
category = ""
|
|
||||||
# Required
|
|
||||||
display_name = ""
|
|
||||||
|
|
||||||
# May be blank
|
url = 'https://nyaa.si/api/upload' # or https://sukebei.nyaa.si/api/upload or http://127.0.0.1:5500/api/upload
|
||||||
information = ""
|
|
||||||
# May be blank
|
# Required
|
||||||
description = ""
|
username = ''
|
||||||
# Default is 'n' No
|
password = ''
|
||||||
# Change to 'y' Yes to set
|
torrent_file = ''
|
||||||
is_anonymous = 'n'
|
category = ''
|
||||||
is_hidden = 'n'
|
|
||||||
is_remake = 'n'
|
# Optional
|
||||||
is_complete = 'n'
|
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 = {
|
auth_info = {
|
||||||
"username" : username,
|
'username' : username,
|
||||||
"password" : password
|
'password' : password
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata={
|
metadata={
|
||||||
"category" : category,
|
'category' : category,
|
||||||
"display_name" : display_name,
|
'display_name' : display_name,
|
||||||
"information" : information,
|
'information' : information,
|
||||||
"description" : description,
|
'description' : description,
|
||||||
"is_anonymous" : is_anonymous,
|
'is_anonymous' : is_anonymous,
|
||||||
"is_hidden" : is_hidden,
|
'is_hidden' : is_hidden,
|
||||||
"is_remake" : is_remake,
|
'is_remake' : is_remake,
|
||||||
"is_complete" : is_complete
|
'is_complete' : is_complete
|
||||||
}
|
}
|
||||||
|
|
||||||
files = {
|
files = {
|
||||||
'auth_info' : (json.dumps(auth_info)),
|
'auth_info' : (json.dumps(auth_info)),
|
||||||
'torrent_info' : (json.dumps(metadata)),
|
'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)
|
response = requests.post(url, files=files)
|
||||||
|
|
||||||
json_response = response.json()
|
json_response = response.json()
|
||||||
|
|
||||||
print(json_response)
|
print(json_response)
|
||||||
|
# A successful request should print {'Success': int(torrent_id)}
|
Loading…
Reference in a new issue