analyze_library
Analyze your rekordbox library by grouping tracks and aggregating data to identify patterns in genres, artists, years, keys, or ratings.
Instructions
Analyze library with grouping and aggregation.
Args: group_by: Field to group by (genre, key, year, artist, rating) aggregate_by: Aggregation method (count, playCount, totalTime) top_n: Number of top results to return
Returns: Analysis results
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| group_by | No | genre | |
| aggregate_by | No | count | |
| top_n | No |
Implementation Reference
- rekordbox_mcp/server.py:248-270 (registration)Registration and handler for the 'analyze_library' MCP tool. Decorated with @mcp.tool(), defines input parameters via type hints, and delegates execution to RekordboxDatabase.analyze_library.@mcp.tool() async def analyze_library( group_by: str = "genre", aggregate_by: str = "count", top_n: int = 10 ) -> Dict[str, Any]: """ Analyze library with grouping and aggregation. Args: group_by: Field to group by (genre, key, year, artist, rating) aggregate_by: Aggregation method (count, playCount, totalTime) top_n: Number of top results to return Returns: Analysis results """ if not db: raise RuntimeError("Database not initialized.") analysis = await db.analyze_library(group_by, aggregate_by, top_n) return analysis
- rekordbox_mcp/database.py:363-403 (handler)Core implementation of library analysis: loads all active tracks, groups by specified field (genre, key, etc.), aggregates count/playCount/totalTime, sorts top N by aggregate, returns structured results.async def analyze_library(self, group_by: str, aggregate_by: str, top_n: int) -> Dict[str, Any]: """Analyze library with grouping and aggregation.""" if not self.db: raise RuntimeError("Database not connected") all_content = list(self.db.get_content()) active_content = [c for c in all_content if getattr(c, 'rb_local_deleted', 0) == 0] groups = {} for content in active_content: # Get grouping key if group_by == "genre": key = getattr(content, 'GenreName', '') or "Unknown" elif group_by == "key": key = getattr(content, 'KeyName', '') or "Unknown" elif group_by == "year": key = str(getattr(content, 'ReleaseYear', '') or "Unknown") elif group_by == "artist": key = getattr(content, 'ArtistName', '') or "Unknown" elif group_by == "rating": key = str(getattr(content, 'Rating', 0) or 0) else: key = "Unknown" if key not in groups: groups[key] = {"count": 0, "playCount": 0, "totalTime": 0} groups[key]["count"] += 1 groups[key]["playCount"] += getattr(content, 'DJPlayCount', 0) or 0 groups[key]["totalTime"] += getattr(content, 'Length', 0) or 0 # Sort by the requested aggregation sorted_groups = sorted(groups.items(), key=lambda x: x[1][aggregate_by], reverse=True) return { "group_by": group_by, "aggregate_by": aggregate_by, "results": dict(sorted_groups[:top_n]), "total_groups": len(groups) }