AIOSeedrcc is a Python asyncrnous library for interacting with Seedr.cc API.
Project description
Asynchronous Python API Wrapper for Seedr.cc
Table of Contents
Installation
-
Install via PyPi
pip install aioseedrcc
-
Install from the source
pip install git+https://github.com/mhdzumair/aioseedrcc.git
Start guide
Getting Token
There are two methods to get the account token. You can login with username/password or by authorizing with device code.
Logging with Username and Password
This method uses the seedr Chrome extension API.
import asyncio
from aioseedrcc import Login
async def main():
async with Login('foo@bar.com', 'password') as seedr:
response = await seedr.authorize()
print(response)
# Getting the token
print(seedr.token)
asyncio.run(main())
Authorizing with device code
This method uses the seedr kodi API.
To use this method, generate a device & user code. Paste the user code in https://seedr.cc/devices and authorize with the device code.
import asyncio
from aioseedrcc import Login
async def main():
async with Login() as seedr:
device_code = await seedr.get_device_code()
# Go to https://seedr.cc/devices and paste the user code
print(device_code)
# Authorize with device code
response = await seedr.authorize(device_code['device_code'])
print(response)
# Getting the token
print(seedr.token)
asyncio.run(main())
✏️ Note: You must use the token from the instance variable 'token' instead of the 'access_token' or 'refresh_token' from the response.
Basic Examples
For all available methods, please refer to the documentation. Also, it is recommended to set a callback function, read more about it here.
import asyncio
from aioseedrcc import Seedr
async def main():
async with Seedr(token='token') as account:
# Getting user settings
settings = await account.get_settings()
print(settings)
# Adding torrent
response = await account.add_torrent('magnetlink')
print(response)
# Listing folder contents
contents = await account.list_contents()
print(contents)
asyncio.run(main())
Managing token
The access token may expire after a certain time and need to be refreshed. However, this process is handled by the module and you don't have to worry about it.
⚠️ The token is updated after this process and if you are storing the token in a file/database and reading the token from it, It is recommended to update the token in the database/file using the callback function. If you do not update the token in such case, the module will refresh the token in each session which will cost extra request and increase the response time.
Callback function
You can set a callback function which will be called automatically each time the token is refreshed. You can use such function to deal with the refreshed token.
✏️ Note: The callback function must be asynchronous and have at least one parameter. The first parameter of the callback function will be the Seedr
class instance.
Callback function with single argument
Here is an example of a callback function with a single argument which reads and updates the token in a file called token.txt
.
import asyncio
from aioseedrcc import Seedr
# Read the token from token.txt
with open('token.txt', 'r') as f:
token = f.read().strip()
# Defining the callback function
async def after_refresh(seedr):
with open('token.txt', 'w') as f:
f.write(seedr.token)
async def main():
async with Seedr(token, token_refresh_callback=after_refresh) as account:
# Your code here
pass
asyncio.run(main())
Callback function with multiple arguments
In situations where you need to pass multiple arguments to the callback function, you can use the token_refresh_callback_kwargs
argument. This can be useful if your app is dealing with multiple users.
Here is an example of a callback function with multiple arguments which will update the token of a certain user in the database after the token of that user is refreshed.
import asyncio
from aioseedrcc import Seedr
# Defining the callback function
async def after_refresh(seedr, user_id):
# Add your code to deal with the database
print(f'Token of the user {user_id} is updated.')
async def main():
# Creating a Seedr object for user 12345
async with Seedr(token='token', token_refresh_callback=after_refresh, token_refresh_callback_kwargs={'user_id': '12345'}) as account:
# Your code here
pass
asyncio.run(main())
Documentation
The detailed documentation of each method is available here.
Contributing
Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE for more information.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aioseedrcc-0.3.1.tar.gz
.
File metadata
- Download URL: aioseedrcc-0.3.1.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c6616196d1a00a0e2477fae356d297c295e3546b571314678eb1cdbca33528f |
|
MD5 | 04047f33433995bfa29a9916eae5600e |
|
BLAKE2b-256 | b130ad6f860058e008b13ff49fa77cb130af8b3b7316b4185d5b6bc8fdaf8b9a |
File details
Details for the file aioseedrcc-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: aioseedrcc-0.3.1-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbb11c531f75d040137bd172143d6599190e7252da14c6290b6299febfec0e80 |
|
MD5 | 3fd15cc4cbd57c2630ce0a7106030d16 |
|
BLAKE2b-256 | 89e5912126ae9be5ee8f5c8b6083d6d619f1f3046ff3fc871724c1d1f0871f70 |