1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 21:20:00 +00:00
nyaa/utils/api_uploader.py

135 lines
3.6 KiB
Python
Raw Normal View History

2017-05-18 03:56:36 +00:00
# Uploads a single torrent file
2017-05-18 07:27:27 +00:00
# Works on nyaa.si and sukebei.nyaa.si
2017-05-12 18:51:49 +00:00
2017-05-18 04:31:28 +00:00
# Consider using api_uploader_v2.py instead
# It has a nice command line interface
2017-05-12 18:51:49 +00:00
import json
import requests
2017-05-18 07:27:27 +00:00
'''
2017-05-18 08:03:30 +00:00
The POST payload to the api endpoint (/api/upload) should be multipart/form-data containing three fields
'auth_info': file containing "{
'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': multi part file format
2017-05-12 18:51:49 +00:00
2017-05-18 07:27:27 +00:00
A successful request should return {'Success': int(torrent_id)}
A failed request should return {'Failure': ["Failure 1", "Failure 2"...]]}
2017-05-12 18:51:49 +00:00
2017-05-18 07:27:27 +00:00
'''
2017-05-18 03:56:36 +00:00
2017-05-18 07:27:27 +00:00
# ########################################### HELP ############################################
2017-05-18 03:56:36 +00:00
# ################################# CATEGORIES MUST BE EXACT ##################################
2017-05-18 07:27:27 +00:00
'''
# Nyaa categories only for now, but api still works for sukebei
2017-05-18 03:56:36 +00:00
Anime
2017-05-18 07:27:27 +00:00
Anime - AMV : '1_1'
Anime - English : '1_2'
Anime - Non-English : '1_3'
Anime - Raw : '1_4'
2017-05-18 03:56:36 +00:00
Audio
2017-05-18 07:27:27 +00:00
Lossless : '2_1'
Lossy : '2_2'
2017-05-18 03:56:36 +00:00
Literature
2017-05-18 07:27:27 +00:00
Literature - English-translated : '3_1'
Literature - Non-English : '3_2'
Literature - Non-English-Translated : '3_3'
Literature - Raw : '3_4'
2017-05-18 03:56:36 +00:00
Live Action
2017-05-18 07:27:27 +00:00
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'
2017-05-18 03:56:36 +00:00
Pictures
2017-05-18 07:27:27 +00:00
Pictures - Graphics : '5_1'
Pictures - Photos : '5_2'
2017-05-18 03:56:36 +00:00
Software
2017-05-18 07:27:27 +00:00
Software - Applications : '6_1'
Software - Games : '6_2'
'''
2017-05-18 03:56:36 +00:00
# ################################# CATEGORIES MUST BE EXACT ##################################
# ###################################### EXAMPLE REQUEST ######################################
2017-05-18 07:27:27 +00:00
'''
2017-05-18 03:56:36 +00:00
# Required
2017-05-18 07:27:27 +00:00
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
'''
2017-05-12 18:51:49 +00:00
2017-05-18 03:56:36 +00:00
# ######################################## CHANGE HERE ########################################
2017-05-18 07:27:27 +00:00
2017-05-18 04:31:28 +00:00
url = 'https://nyaa.si/api/upload' # or 'https://sukebei.nyaa.si/api/upload' or 'http://127.0.0.1:5500/api/upload'
2017-05-18 07:27:27 +00:00
2017-05-18 03:56:36 +00:00
# Required
2017-05-18 07:27:27 +00:00
username = ''
password = ''
torrent_file = ''
category = ''
# Optional
display_name = ''
information = ''
description = ''
is_anonymous = False
is_hidden = False
is_remake = False
is_complete = False
2017-05-18 03:56:36 +00:00
auth_info = {
2017-05-18 07:27:27 +00:00
'username' : username,
'password' : password
2017-05-18 03:56:36 +00:00
}
2017-05-12 18:51:49 +00:00
2017-05-18 03:56:36 +00:00
metadata={
2017-05-18 07:27:27 +00:00
'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
2017-05-18 03:56:36 +00:00
}
2017-05-12 18:51:49 +00:00
files = {
2017-05-18 03:56:36 +00:00
'auth_info' : (json.dumps(auth_info)),
'torrent_info' : (json.dumps(metadata)),
2017-05-18 07:27:27 +00:00
'torrent_file' : ('{0}'.format(torrent_file), open(torrent_file, 'rb'), 'application/octet-stream')
2017-05-18 03:56:36 +00:00
}
2017-05-12 18:51:49 +00:00
response = requests.post(url, files=files)
json_response = response.json()
print(json_response)
2017-05-18 04:31:28 +00:00
# A successful request should print {'Success': int(torrent_id)}