Work with Tautulli analytics integration for Plex streaming metrics...
This skill helps with Tautulli analytics features in homescreen-hero. Tautulli provides streaming metrics and watch history from Plex servers.
The TautulliClient wraps the Tautulli API v2. It handles:
{"response": {"result": "success", "data": ...}})| Method | Purpose | Returns |
|---|---|---|
ping() |
Health check | (bool, Optional[str]) - success status and error message |
get_libraries() |
Get Plex libraries | List of library dicts with section_id |
get_collection_stats(rating_key, query_days) |
Watch stats for a collection | Dict with total_plays, total_duration |
get_history(length, start) |
Watch history entries | List of history dicts with timestamps |
get_user_watch_time_stats(query_days) |
User watch stats | List of user stats |
get_plays_by_date(time_range, y_axis) |
Play counts by date | Dict with categories (dates) and series (play data) |
get_plays_by_hourofday(time_range, y_axis) |
Play counts by hour | Dict with categories (hours) and series |
get_plays_by_stream_type(time_range, y_axis) |
Plays by stream type with concurrent streams | Dict with stream type data including max concurrent |
Tautulli requires:
HSH_TAUTULLI_API_KEY environment variable (or in config.yaml)HSH_TAUTULLI_BASE_URL environment variable (default: http://localhost:8181)enabled: true in config.yaml under tautulli sectionThe tautulli_analytics.py module collects watch statistics and stores them in SQLite:
collect_analytics_for_collections(config, collection_names, rotation_id)
record_collection_analytics()collected, failed, and total_collectionscollect_analytics_for_all_active(config)
collect_analytics_for_collections() internallycollection_analytics table in SQLiteWhen adding a new chart to the frontend:
tautulli_client.pyhomescreen_hero/web/routers/analytics.pyfrom homescreen_hero.core.integrations.tautulli_client import get_tautulli_client
from homescreen_hero.core.config.loader import load_config
config = load_config()
client = get_tautulli_client(config)
if client:
success, error = client.ping()
print(f"Tautulli connection: {'OK' if success else f'Failed - {error}'}")
# Get stats for a specific collection (by rating_key)
stats = client.get_collection_stats(rating_key=12345, query_days=30)
print(f"Total plays: {stats['total_plays']}")
# Get play history
history = client.get_history(length=100)
for entry in history:
print(f"{entry['user']}: {entry['title']} at {entry['date']}")
{
"total_plays": 42,
"total_duration": 7200,
"total_time": "2h 0m"
}
{
"categories": ["2024-01-01", "2024-01-02", ...],
"series": {
"Movies": [5, 8, 3, ...],
"TV": [12, 15, 10, ...]
}
}
{
"categories": ["2024-01-01", "2024-01-02", ...],
"series": {
"Direct Play": [5, 8, ...],
"Direct Stream": [3, 2, ...],
"Transcode": [1, 4, ...],
"Concurrent Streams": [8, 12, ...] // Max concurrent per day
}
}
Analytics are stored in collection_analytics table:
collection_name - Name of the collectionplex_library - Library name (Movies, TV Shows, etc.)rating_key - Plex rating keytotal_plays - Total play counttotal_duration_seconds - Total watch time in secondsunique_users - Count of unique users (nullable)rotation_id - FK to rotation that triggered collection (nullable)collected_at - Timestamp of collectionextra_data - JSON field for additional metadatalogger.debug() for API requests, logger.info() for successful operations, logger.error() for failures