This document describes the new real-time "Now Watching" feature that integrates Trakt scrobble data with TMDB images.
The /api/watching endpoint provides real-time information about what you're currently watching, complete with high-quality backdrop images from TMDB and progress tracking.
- Real-time scrobble detection from Trakt API
- High-quality backdrop images from TMDB (multiple resolutions)
- Progress calculation with time remaining
- Works for both movies and TV episodes
- Beautiful UI banner that appears when watching content
- Responsive design with gradient overlays for text readability
Add these to your .env.local file:
TRAKT_API_KEY=your_trakt_client_id
TRAKT_USERNAME=your_trakt_username
TMDB_API_KEY=your_tmdb_api_key-
Trakt API Key:
- Go to https://trakt.tv/oauth/applications
- Create a new application
- Use the Client ID as your
TRAKT_API_KEY
-
TMDB API Key:
- Go to https://www.themoviedb.org/settings/api
- Request an API key
- Use the API Key (v3 auth) as your
TMDB_API_KEY
Response when watching:
{
"isWatching": true,
"content": {
"type": "episode",
"title": "House of Cards",
"subtitle": "S3E10 - Chapter 36",
"year": 2013,
"progress": {
"started_at": "2025-07-19T13:00:12.000Z",
"expires_at": "2025-07-19T13:57:12.000Z",
"percentage": 45
},
"images": {
"backdrop": "https://image.tmdb.org/t/p/w1280/backdrop1.jpg",
"backdrop_medium": "https://image.tmdb.org/t/p/w1280/backdrop2.jpg",
"backdrop_small": "https://image.tmdb.org/t/p/w1280/backdrop3.jpg"
},
"ids": {
"trakt": 1416,
"tmdb": 1425,
"imdb": "tt1856010"
}
}
}Response when not watching:
{
"isWatching": false
}The watching data is automatically integrated into the UserProfileStats component:
- Dynamic banner appears when content is being watched
- Background image uses TMDB backdrop with gradient overlay
- Progress bar shows current viewing progress
- Time indicators show start time and estimated end time
- External links to Trakt, IMDb, and TMDB
- Responsive design that works on all screen sizes
- Gradient overlays for optimal text readability
- Progress visualization with animated progress bar
- External links with proper icons
- Fallback background when no backdrop image is available
- Skeleton loading for the watching banner
- Graceful fallbacks when APIs are unavailable
- Error handling with console logging
- Frontend requests watching data from
/api/watching - API fetches current scrobble from Trakt API
- If watching, API fetches backdrop images from TMDB
- Progress calculation based on start/end times
- Response includes all data needed for UI display
- Component renders beautiful banner with all information
/app/api/watching/route.ts- New API endpoint/components/UserProfileStats.tsx- Updated with watching banner/lib/types/index.ts- Added watching-related types/lib/services/api.ts- Added fetchWatchingData function/app/api-test/page.tsx- Added watching endpoint to test interface/API_DOCUMENTATION.md- Added documentation
interface WatchingData {
isWatching: boolean;
content?: {
type: 'movie' | 'episode';
title: string;
subtitle?: string;
year: number;
progress?: {
started_at: string;
expires_at: string;
percentage?: number;
};
images: {
backdrop?: string;
backdrop_medium?: string;
backdrop_small?: string;
};
ids: {
trakt: number;
tmdb: number;
imdb: string;
};
};
}curl http://localhost:3000/api/watching- Start watching something on a device with Trakt scrobbling enabled
- Visit your application homepage
- The watching banner should appear automatically
- Go to
/api-test - Select "Now Watching" from the endpoint list
- Click "Test Endpoint" to see current status
- Auto-refresh watching status every minute
- Episode thumbnails for TV shows
- Playlist support for continuous watching
- Watch party integration for shared viewing
- Notification system for friends' watching activity
- Caching: Watching data is not cached due to real-time nature
- API calls: Makes 1 Trakt API call + 1 TMDB API call per request
- Rate limiting: Respects both Trakt and TMDB rate limits
- Fallbacks: Gracefully handles API failures
-
"Not watching" always returned:
- Check if Trakt scrobbling is enabled on your media player
- Verify TRAKT_API_KEY and TRAKT_USERNAME are correct
-
No backdrop images:
- Verify TMDB_API_KEY is valid
- Check if the content has images on TMDB
-
Incorrect progress calculation:
- This depends on accurate scrobble timing from your media player
- Some players may report inaccurate start/end times
Check browser console and Next.js terminal for error messages:
- Trakt API errors
- TMDB API errors
- Network issues
- Environment variable problems
Created: July 19, 2025
Version: 1.0
Status: ✅ Ready for use