Skip to content

Trakt.tv Integration ​

Since: 0.14.0 Plugin type: scrobbler

Note

Trakt.tv integration is a built-in server plugin. No separate install is required.

Overview ​

The Trakt.tv integration provides two-way watch-history synchronization and real-time scrobbling for movies and TV shows.

  • Two-way sync: Completed items (β‰₯ 90% watched) are pushed from Phlix to Trakt; items watched on other Trakt-connected apps are pulled into Phlix.
  • Scrobbling: Uses Trakt's 3-state scrobble protocol (start / pause / stop) to track playback in real time.
  • Authentication: OAuth2 with PKCE β€” no password is stored.

What Gets Synced ​

DirectionTriggerData
Phlix β†’ TraktPlayback stops at β‰₯ 90% completionWatched-history entry
Trakt β†’ PhlixScheduled sync runWatched-history entries not yet β‰₯ 90% in Phlix

Note

Trakt β†’ Phlix sync requires matching Trakt items to local media items via TMDB/TVDB/IMDB IDs. This lookup is stubbed in 0.14.0 and returns null, so the pull direction is a no-op until it is wired up. The push direction (Phlix β†’ Trakt) works fully.


Connecting Your Account ​

Prerequisites ​

You need a Trakt application with credentials:

  1. Go to https://trakt.tv/apps
  2. Click Register a New Application
  3. Set the Redirect URI to match your server's callback URL (see config/scrobblers/trakt.php redirect_uri)
  4. Copy the Client ID and Client Secret

Connect Flow ​

  1. Open Settings β†’ Integrations β†’ Trakt.tv in the Phlix web UI
  2. Click Connect with Trakt
  3. You are redirected to Trakt's authorization page β€” approve access
  4. Phlix receives the callback, exchanges the code for tokens, and stores them
  5. Your Trakt username is displayed as confirmation

The OAuth flow uses PKCE (S256 code challenge method). Tokens are stored per-user in the plugins settings table and are refreshed automatically on 401 responses.


Configuration ​

Environment / Config File ​

The server-side config lives in config/scrobblers/trakt.php:

php
// config/scrobblers/trakt.php
return [
    'client_id'     => getenv('TRAKT_CLIENT_ID') ?: '',
    'client_secret' => getenv('TRAKT_CLIENT_SECRET') ?: '',
    'redirect_uri'  => 'https://your-server.com/api/v1/oauth/trakt/callback',
    'sync_interval' => 30,   // minutes between Trakt→Phlix sync runs
];
KeySourceDescription
client_idTRAKT_CLIENT_ID env var or directTrakt app Client ID
client_secretTRAKT_CLIENT_SECRET env var or directTrakt app Client Secret
redirect_uriDirect in configMust match what is registered in your Trakt app
sync_intervalDirect in configMinutes between scheduled sync runs (default: 30, min: 5, max: 1440)

Per-User Settings ​

These are stored in the plugins settings JSON for each user:

KeyTypeDefaultDescription
enabledboolfalseMaster on/off switch
usernamestring''Trakt username for attribution
access_tokenstringnullOAuth access token
refresh_tokenstringnullOAuth refresh token
expires_atintnullUnix timestamp when access token expires
sync_enabledbooltrueWhether two-way history sync runs
sync_interval_minutesint30How often Trakt→Phlix sync fires
scrobble_enabledbooltrueWhether real-time scrobbling is active

Scheduled Sync Behaviour ​

The Trakt β†’ Phlix sync runs on a configurable interval (default 30 minutes):

  1. Fetches the user's full watched history from Trakt (paginated, up to 100 items per page)
  2. For each Trakt item, looks up the corresponding local media item (stubbed β€” returns null until ID resolution is wired up)
  3. If the local item exists and is below the 90% completion threshold, writes a completed entry to the local watch history
  4. Items already β‰₯ 90% complete in Phlix are skipped (last-write-wins on the 90% threshold)

The push direction (Phlix β†’ Trakt) is triggered immediately on PlaybackStopped when the item has reached β‰₯ 90% completion β€” it does not wait for the scheduled sync.


Troubleshooting ​

"Scrobble failed (auth)" in logs ​

Cause: Access token expired and refresh failed (e.g., refresh token revoked).

Fix: Disconnect and reconnect the account in Settings β†’ Integrations β†’ Trakt.tv.

Sync runs but nothing is written ​

Cause: The Trakt β†’ Phlix media-item ID lookup is stubbed in 0.14.0. Items that exist in Trakt but not in the local library are correctly skipped; items in the local library are also skipped because the lookup currently returns null.

Fix: This is a known limitation. The TMDB/TVDB resolver is tracked as a future enhancement.

"Plugin not configured" in logs ​

Cause: Either client_id / client_secret are empty in config/scrobblers/trakt.php, or the user has not connected their Trakt account in the UI.

Fix: Verify the config file has valid credentials, then connect the account in the web UI.

Token refresh fails with 401 ​

Cause: The user revoked the application's access from their Trakt account page.

Fix: The user must disconnect and reconnect from Settings β†’ Integrations β†’ Trakt.tv.


See Also ​

BSD-3-Clause