API#
Reference#
- exception yumemi.AnidbError(*args, result: Optional[Result] = None)[source]#
Bases:
Exception
- classmethod from_result(result: Result) AnidbError [source]#
- class yumemi.Client(client_name: str, client_version: int)[source]#
Bases:
object
- auth(username: str, password: str) Result [source]#
Authenticate to AniDB.
- Parameters:
username – User name.
password – User password.
- Returns:
AUTH command result with session key removed from the result message.
- Raises:
ClientError – Raised when authentication failed.
See also
- check_session() bool [source]#
Check if a user is logged in and the session is still active on the server.
This method can be called once every 30 minutes to keep the connection alive.
See also
- client_name: str#
- client_version: int#
- command(command: str, params: Optional[dict[str, Any]] = None) Result [source]#
Sends a command to the API, wait for a response, and return the command result.
Exceptions are raised only for common client and server side errors. You still need to check the result code to see if the command succeeded or not.
Commands documentation is on AniDB Wiki.
- Parameters:
command – Command name.
params – Command parameters.
- Returns:
Command result.
- Raises:
ClientError – Raised for common client side errors, like invalid command or invalid parameters.
ServerError – When something went wrong on the server side.
- encrypt(username: str, api_key: str) None [source]#
Start encrypted session. A normal authentication is still necessary and should follow the encrypt call.
- Parameters:
username – User name.
api_key – API key, defined in profile settings.
- Raises:
ClientError – Raised when encrypted session could not be established.
See also
- exception yumemi.ClientError(*args, result: Optional[Result] = None)[source]#
Bases:
AnidbError
- class yumemi.CodecCrypt(encoding: str, encrypt_key: str)[source]#
Bases:
CodecPlain
- encrypt_key: str#
- class yumemi.Connection(server_host: str = 'api.anidb.net', server_port: int = 9000, local_port: int = 8888)[source]#
Bases:
object
Low-level conection to the AniDB UDP API with thread safe flood protection (packet rate limit, one packet every two seconds).
- local_port: int#
- server_host: str#
- server_port: int#
- class yumemi.Result(command: str, params: dict[str, Any], code: int, message: str, data: tuple[tuple[str, ...], ...])[source]#
Bases:
object
- code: int#
- command: str#
- data: tuple[tuple[str, ...], ...]#
- message: str#
- params: dict[str, Any]#
- exception yumemi.ServerError(*args, result: Optional[Result] = None)[source]#
Bases:
AnidbError
Example#
import yumemi
# Your client name and version, create on https://anidb.net/software
client = yumemi.Client('example', 1)
# Check if API is OK
if not client.ping():
print('AniDB is DOWN')
exit(1)
# Optionaly encrypt connection
client.encrypt('my-username', 'udp-api-key')
# Login to AniDB
client.auth('my-username', 'my-password')
# Send some commands...
result = client.command('ANIME', {'aid': 11829})
if result.code == 230:
aid = result.data[0][0]
year = result.data[0][10]
name = result.data[0][12]
print(f'{name} (a{aid}) @ {year}')
else:
print(f'Error: {result.message}')
# ... Send more commands...
# And logout at the end
client.logout()