Generates a GitHub-style contribution graph from your Trakt watch history.
Turn your Trakt watch history (movies and TV shows) into a visually appealing heatmap, styled like GitHub's contribution graph. Display your viewing habits in your GitHub profile README or share them anywhere with light and dark theme SVGs!
- Fetches your Trakt watch history via the Trakt API.
- Generates SVG graphs in both light and dark themes for:
- Movies only
- Shows only
- All watch history combined
- Includes your Trakt profile image and the Trakt logo.
- Supports customization: choose a specific year, set the week start (Sunday/Monday), and select content types.
- Interactive tooltips: Hover over a cell to see details of what was watched on that day (viewable in a browser).
Automate graph generation using GitHub Actions.
name: Update Trakt Contribution Graph
on:
schedule:
- cron: "0 0 * * *" # Runs daily at midnight UTC
workflow_dispatch: # Allows manual triggering
permissions:
contents: write
jobs:
update-trakt-graph:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm ci
- run: npm start -u YOUR_TRAKT_USERNAME -a
env:
TRAKT_API_KEY: ${{ secrets.TRAKT_API_KEY }}
- run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add images/github-trakt-*.svg
git commit --allow-empty -m "π Update Trakt contribution graph"
git push
-
Fork This Repository:
- Click "Fork" to create a copy under your GitHub account.
-
Set Up Environment Variables:
- Go to your repository's "Settings" > "Secrets and variables" > "Actions" > "Secrets".
- Add
TRAKT_API_KEY
with your Trakt API key (see Obtaining a Trakt API Key).
-
Update the Username:
- Open
.github/workflows/update-trakt-graph.yml
. - Replace
YOUR_TRAKT_USERNAME
with your Trakt username:run: npm start -u YOUR_TRAKT_USERNAME
- Open
-
Enable GitHub Actions:
- Go to the "Actions" tab and enable workflows if prompted.
-
Customize (Optional):
- Add flags to the
npm start
command:-y YEAR
: Specify a year (e.g.,-y 2024
).-w monday
: Start weeks on Monday (default:sunday
).-m
: Filter to movies only.-s
: Filter to shows only.-a
: Generate all types (movies
,shows
, andall
) at once. Example:
run: npm start -u YOUR_TRAKT_USERNAME -y 2024 -a
- Add flags to the
-
Update the README:
- Replace placeholders in the
<picture>
tag with your GitHub and Trakt usernames:<p align="left"> <a href="https://trakt.tv/users/YOUR_TRAKT_USERNAME/" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://github.com/YOUR_USERNAME/trakt-graph/blob/main/images/github-trakt-dark.svg" /> <source media="(prefers-color-scheme: light)" srcset="https://github.com/YOUR_USERNAME/trakt-graph/blob/main/images/github-trakt-light.svg" /> <img alt="Trakt contribution graph" src="https://github.com/YOUR_USERNAME/trakt-graph/blob/main/images/github-trakt-light.svg" /> </picture> </a> </p>
- Replace placeholders in the
-
Run the Action:
- Wait for the daily run or trigger it manually via the "Actions" tab.
Generate the graph locally:
# Clone the repo
git clone https://github.com/nichtlegacy/trakt-graph.git
cd trakt-graph
# Install dependencies
npm install
# Generate the graph
npm start -u YOUR_TRAKT_USERNAME
The SVGs will be saved to the images/
directory. Add optional flags like -y 2024
or -w monday
.
- A public Trakt profile with watch history.
- A Trakt API key (see below).
- Node.js v18+ (for local use).
- GitHub account with Actions enabled (for automation).
To use this project, youβll need a Trakt API key (Client ID) from Trakt.tv. Follow these steps to obtain one:
- Sign in to Trakt.tv.
- Go to Settings > API > New Application.
- Fill out the application form:
- Name: "Trakt Contribution Graph" (or any name you prefer).
- Icon: Leave unselected (no icon required).
- Note: If you choose to upload one, use a transparent PNG, square, and at least 256x256 pixels.
- Description: Optional (e.g., "Generates a contribution graph from Trakt watch history"). This appears in the Connected Apps section when users grant access.
- Redirect URI: Enter
urn:ietf:wg:oauth:2.0:oob
(for Device authentication, as no redirect is needed for this script).- Enter this exactly as shown, one URI per line, without query strings.
- Javascript (CORS) Origins: Leave blank (not required for this project).
- Permissions: Check both:
/checkin
/scrobble
- Note: These permissions are selected for completeness, though this script only requires read access to your history.
- Click "Save" to create the application.
- Copy the Client ID from the application details page β this is your
TRAKT_API_KEY
. - For local use, add it to a
.env
file in the project root:TRAKT_API_KEY=your-client-id-here
- For GitHub Actions, add it as a repository secret:
- Go to "Settings" > "Secrets and variables" > "Actions" > "Secrets".
- Add a new secret named
TRAKT_API_KEY
with the Client ID as the value (see Setup Steps).
trakt-graph/
βββ images/ # Output directory for generated SVGs
βββ .github/ # GitHub Actions workflows
β βββ workflows/
β βββ update-trakt-graph.yml
βββ standalone.js # Main script
βββ package.json # Dependencies and scripts
βββ package-lock.json # Dependency lock file
βββ README.md # This file
standalone.js
: Core logic for fetching Trakt data, processing it, and generating SVGs.images/
: Default output directory forgithub-trakt-dark.svg
andgithub-trakt-light.svg
.
The script uses the following Trakt API endpoints:
GET /users/{username}?extended=full
: Fetches user profile data (display name, avatar).GET /users/{username}/history
: Retrieves all watch history (paginated).GET /users/{username}/history/movies
: Retrieves movie watch history.GET /users/{username}/history/shows
: Retrieves show watch history.
Requests are authenticated with the TRAKT_API_KEY
via the trakt-api-key
header.
The script includes console logs for debugging and monitoring:
- Profile Fetch Errors: Warns if profile data fetch fails, using fallback values.
- Image Conversion Errors: Warns if Base64 conversion fails (e.g., for avatars or logos).
- History Fetch: Logs page-by-page progress (e.g., "Fetched page 1: 100 items").
- History Processing: Logs the selected year, year-wise counts, total items, and day count stats.
- Output Confirmation: Confirms SVG file generation.
These logs are useful for troubleshooting API issues or verifying data processing.
Below are example outputs with automatic light/dark switching:
Have ideas or improvements? Open an issue or submit a pull request! Contributions are welcome.
MIT License - see LICENSE for details.