Skip to content

pavelnil/Trakt-Token-Manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Trakt Token Manager

A script for automatic management of Trakt authorization tokens. Designed for use with the Elementum addon in Kodi through the Elementum Trakt Updater addon to use tokens from a single account on multiple devices. It may also be useful in other projects.

The script performs:

  • Obtaining OAuth tokens via device code flow.
  • Automatically refreshing the access token before it expires.
  • Saving tokens to a trakt_tokens.json file.
  • Generating a elementum_trakt_config.json configuration file with the access token, username, refresh token, and expiration time.
  • Option to hide the real refresh token in the config (a fake one is used).

Alternative

Using different Client IDs and Client Secrets or moving them to settings and recompiling Elementum. If there are many devices, this may appear suspicious to Trakt's anti-fraud system.

Features

  • Authorization via device code — simply enter the code on the Trakt website.
  • Automatic token refresh (checks every 5 minutes).
  • One‑time mode (--once) — perform a check and exit.
  • Force refresh (--force) — forcibly refresh the token.
  • Force reauthorization (--auth) — reset tokens and perform a new authorization on the Trakt website.
  • Hide real refresh token (--hide-refresh-token) — a fake token is written to the Elementum config, while the real one remains in trakt_tokens.json.
  • Logging to trakt_manager.log and the console.

Requirements

  • Python 3.6 or higher.
  • The requests library (installed via pip).

Installation

Use Windows standalone executable. or

  1. Clone the repository or download the script.
  2. Install dependencies:
    pip install requests
  3. Run the script.

Usage

Basic run (continuous mode)

python trakt_manager.py

The script will perform initial authorization (if no tokens exist), save the config, and then check every 5 minutes whether the token needs refreshing. Press Ctrl+C to stop.

One-time check

python trakt_manager.py --once

Checks the tokens, refreshes if needed, generates the config, and exits.

Force token refresh

python trakt_manager.py --force

Forcibly refreshes the access token even if the current one hasn’t expired.

Force reauthorization

python trakt_manager.py --auth

Resets old tokens and starts the authorization procedure again.

Specify username

python trakt_manager.py --username mytraktusername

If you know the username in advance, you can provide it to avoid being prompted automatically. The username is also saved in the token file.

Hide real refresh token

python trakt_manager.py --hide-refresh-token

A fake refresh token (64 random characters) is written to elementum_trakt_config.json. The real refresh token remains only in trakt_tokens.json. This can be useful if you are sharing the config with third‑party applications and don’t want to expose the real token.

Configuration files

  • trakt_tokens.json — stores all tokens and metadata:
    {
      "access_token": "...",
      "refresh_token": "...",
      "created_at": 1234567890,
      "expires_in": 86400,
      "username": "mytraktusername",
      "fake_refresh_token": "...",
      "fake_expires_in": 864000
    }
  • elementum_trakt_config.json — configuration for Elementum:
    {
      "trakt_token": "access_token",
      "trakt_username": "mytraktusername",
      "trakt_refresh_token": "fake_refresh_token_or_real",
      "trakt_token_expiry": 1234567890
    }

Logging

The script writes logs to trakt_manager.log and the console. The log level is INFO.

Notes

  • The script uses standard Trakt authorization parameters pre‑registered for the Elementum addon. If you want to use your own Trakt application, change CLIENT_ID and CLIENT_SECRET in the code.
  • In continuous mode, the check interval is 5 minutes. You can change it by editing time.sleep(300) in the loop.
  • If the token has expired, the script tries to refresh it using the refresh_token. If refresh fails, a full authorization is performed.

About

Automated Trakt access token renewal Python script.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages