Skip to main content

Asyncio client for TeraBox cloud storage

Project description


Features

  • ⚡ Fully asynchronous (asyncio)
  • 🌐 HTTP client based on aiohttp
  • 🔐 Authentication and session handling
  • 📂 File and directory operations
  • ⬆️ File uploads and downloads

Installation

pip install aioterabox

Install from source

git clone https://github.com/devbis/aioterabox.git
cd aioterabox
pip install -e .

Usage

import asyncio
import aiohttp
from aioterabox.api import TeraboxClient


async def main():
    async with aiohttp.ClientSession() as session:
        tb = TeraboxClient(
            session=session,
            email='your_email',
            password='your_password',
            cookies={
                'csrfToken': '...',
                'browserid': '...',
                'ndus': '...',
                'jstoken': '...',
            },
        )
        await tb.login()

        # get quota
        print('quota = ', await tb.get_storage_quota())

        # list files
        files = await tb.list_remote_directory('/path/to/directory')
        print(files)
        
        # create directory
        await tb.create_directory('/remote/directory')

        # upload file
        await tb.upload_file('/home/user/localfile.zip', f'/remote/directory/remotefile.zip')

        # download file
        meta = await tb.get_files_meta(['/remote/directory/remotefile.zip'])[0]
        async with session.get(meta['dlink']) as resp:
            # the link is signed and can be downloaded without authentication
            with open('/tmp/downloadedfile.zip', 'wb') as f:
                while chunk := await resp.content.read(1024):
                    f.write(chunk)

        # rename file  
        await tb.rename_file('/remote/directory/remotefile.zip', 'newname.zip')

        # delete file
        await tb.delete_files(['/remote/directory/newname.zip'])

asyncio.run(main())

Though the library supports authentication via username and password, it is highly recommended to use session cookies for better reliability. You can obtain the required cookies by logging into TeraBox via a web browser and inspecting the cookies set for the domain.

For file operations you should always use absolute paths starting from the root directory /.

Configuration

Getting the JS Token

To use this tool you need to have a Terabox account and a JS Token key. You can get the session JS Token by logging into your Terabox account and following the sequence of steps below:

  1. Open your Terabox cloud.
  2. Open the browser's developer tools (F12).
    Developer tools F12
  3. Enable the "Device Toolbar" then click the back arrow to get back to Terabox.
    Developer tools F12 "Device Toolbar" Back Arrow
  4. Go to the "Network" tab.
    Developer tools F12 Network tab
  5. Select the "XHR" filter.
    Developer tools F12 XHR filter
  6. Click any directory or file in the cloud.
  7. Look for any request made to the Terabox cloud URL and click on it.
    Developer tools F12 request item
  8. Select the "Payload" tab.
    Developer tools F12 Payload tab
  9. Look for the jsToken parameter in the list and copy its value.

If you can't find the jsToken parameter, try selecting any other directory or file in the cloud and look for the jsToken parameter in the request payload. Make sure that you have the "XHR" filter selected and that you are looking at the "Payload" tab.

Getting the cookies values

Additionally to the JS Token, you will need to capture the cookies values. You can get them by following the sequence of steps below:

  1. Open your Terabox cloud.
  2. Open the browser's developer tools (F12).
    Developer tools F12
  3. Go to the "Application" tab.
    Developer tools F12 Application tab
  4. Select the "Cookies" item in the left panel.
    Developer tools F12 Cookies tab
  5. Look for the cookies values and copy them.
    Developer tools F12 Cookies values

You will need to copy the csrfToken, browserid, and ndus values. Once the values are provided the library will refresh the csrfToken and jstoken values on login automatically.

Requirements

  • Python 3.9+
  • aiofiles
  • aiohttp
  • cryptography

Thanks

https://github.com/seiya-npm/terabox-api for reverse engineering the TeraBox API and JavaScript implementation. https://github.com/dnigamer/TeraboxUploaderCLI/ for the instructions on obtaining session cookies.

Disclaimer

This project is not affiliated with or endorsed by TeraBox. The API behavior may change at any time, which can break compatibility.

Use at your own risk.

License

Apache License 2.0

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

aioterabox-0.1.0.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

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

aioterabox-0.1.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file aioterabox-0.1.0.tar.gz.

File metadata

  • Download URL: aioterabox-0.1.0.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.11

File hashes

Hashes for aioterabox-0.1.0.tar.gz
Algorithm Hash digest
SHA256 da33712ba58275f138f656e2fa59d1bd59deb4397d69e6ead39d08859da64011
MD5 b74dd26cf7e83afd804658b0c2a3c2da
BLAKE2b-256 9c98b9002b63110ffc2ccbb8ee9afa2409bfa7f3a5131de0d2c95af60bb9a965

See more details on using hashes here.

File details

Details for the file aioterabox-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aioterabox-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.11

File hashes

Hashes for aioterabox-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e57381ef4e1abbc929edaceb1f6a4bc3f6a6359003e1e41cbc8024178231b3b6
MD5 250394aaaf536fcefb9484aac25026ee
BLAKE2b-256 a7a639a8bc47d989b37b2438c105fe1dd5ebbc61ada4a7641fc670f1abc2feb7

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