Trakt was the one service outside the tracker abstraction. TraktScrobbleService re-implemented the whole playback lifecycle beside TrackerCoordinator, and TraktSyncService pushed watched state from its own WatchStateNotifier subscription, so the player called two objects at every lifecycle point and one watch could be written twice. TraktTracker now implements RealtimeScrobbleTracker like Simkl; the duplicated player call sites collapse to one each, and Trakt shares the coordinator's ID resolver instead of re-fetching show ids every episode. Capabilities are split so a tracker declares what it is rather than being special-cased: ScrobblePolicy carries each service's own resend/seek rules, EpisodeHistoryTracker names the remote row a per-item history write targets, and SeriesProgressTracker covers one-counter-per-series services. Writes from all four trackers go through a shared TrackerWriteQueue, generalised from the Trakt-only queue, with the legacy Trakt payload migrated on load. Trakt becomes the fourth TrackersProvider slot and TraktAccountProvider is deleted, so one object owns the active session per profile. Two failure paths found while consolidating are fixed here too. The queue's retries only ran on profile bind, connect and app foreground, so a network blip mid-session left queued watches waiting for the next foreground. OfflineModeProvider now notifies on connectivity changes, not just offline-state or WiFi-flag changes, and main.dart flushes the queue when the network returns. The queue also counted every failure toward the five attempts that permanently drop an item, so a rate limit or a service having a bad hour could discard a pending watch - the loss the queue exists to prevent. Only an answer about the write itself now spends an attempt: 4xx counts, while rate limits, 5xx, recoverable token-refresh failures and requests that never arrived do not. A back-off answer also defers that service for the rest of the flush, so a queue holding many rows does not fire all of them at a service that just asked for quiet.
43 lines
1.8 KiB
Dart
43 lines
1.8 KiB
Dart
/// Bundled Trakt API credentials and base URLs.
|
|
///
|
|
/// The client_id/client_secret are extractable from the binary; this is
|
|
/// the standard pattern for native Trakt apps and is acceptable given the
|
|
/// same threat model as the Plex token already in `SharedPreferences`.
|
|
class TraktConstants {
|
|
TraktConstants._();
|
|
|
|
// Registered Trakt app credentials. Same threat model as the Plex token in
|
|
// SharedPreferences — extractable from the binary, but acceptable for a
|
|
// native client app. To rotate, update the registration at
|
|
// https://trakt.tv/oauth/applications.
|
|
static const String clientId = '9861e686e95c13409dd321736f903973cb9b8e5c6abd0634bec8962f52ea30f4';
|
|
static const String clientSecret = 'acfa17b9d77fabd7e51175b7da6631aea69423530a6d49b3b3c38cd107cbd207';
|
|
|
|
static const String apiBase = 'https://api.trakt.tv';
|
|
static const String apiVersion = '2';
|
|
|
|
// OAuth endpoints
|
|
static const String deviceCodeUrl = '$apiBase/oauth/device/code';
|
|
static const String deviceTokenUrl = '$apiBase/oauth/device/token';
|
|
static const String tokenUrl = '$apiBase/oauth/token';
|
|
static const String revokeUrl = '$apiBase/oauth/revoke';
|
|
|
|
// Scopes — Trakt's OAuth doesn't use granular scopes; "public" is the only value
|
|
static const String scope = 'public';
|
|
|
|
/// Headers required on every Trakt API call.
|
|
static Map<String, String> headers({String? accessToken}) {
|
|
return {
|
|
'Content-Type': 'application/json',
|
|
'Accept': 'application/json',
|
|
'trakt-api-version': apiVersion,
|
|
'trakt-api-key': clientId,
|
|
if (accessToken != null) 'Authorization': 'Bearer $accessToken',
|
|
};
|
|
}
|
|
}
|
|
|
|
/// Catalog list flavor for Trakt's discover/watchlist endpoints, named after
|
|
/// the URL path segment (`/movies/trending`, `/sync/watchlist/shows/...`).
|
|
enum TraktCatalogType { movies, shows }
|