Skip to main content

AIOSeedrcc is a Python asyncrnous library for interacting with Seedr.cc API.

Project description

AIOSeedrcc logo

Asynchronous Python API Wrapper for Seedr.cc

Stars Issues

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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. 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

aioseedrcc-0.3.2.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aioseedrcc-0.3.2-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file aioseedrcc-0.3.2.tar.gz.

File metadata

  • Download URL: aioseedrcc-0.3.2.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for aioseedrcc-0.3.2.tar.gz
Algorithm Hash digest
SHA256 00ca6256e2092fe259d2a81b151dd55e348e83150c7ce8d8c8c6d97a8ba5319e
MD5 71d10c353f9026f2b45d257420e5d66b
BLAKE2b-256 0d803bff820eb3bb03fa3be4f301961b38994bf0381c122a06350811bf21b8cc

See more details on using hashes here.

File details

Details for the file aioseedrcc-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: aioseedrcc-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for aioseedrcc-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4810e24f9371b32a743987d6a45e0ec477f5eb6cebd64b22fe75d29095dbfff3
MD5 d325b71fb3842e72acb9d142ec7d2e7e
BLAKE2b-256 c0a1bf16dc68198614726aa708c82712df0310b52329419baff52296e857f9f7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page