Skip to main content
Glama

analyze_library

Group and analyze music library data by genre, key, year, artist, or rating, with aggregation options like count, playCount, or totalTime, and return top results for insights.

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
NameRequiredDescriptionDefault
aggregate_byNocount
group_byNogenre
top_nNo

Implementation Reference

  • MCP tool registration for analyze_library. Thin handler that ensures database connection and delegates to RekordboxDatabase.analyze_library method.
    @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
  • Core handler implementing the library analysis logic: loads tracks, groups by specified field (genre/key/year/artist/rating), 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) }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/davehenke/rekordbox-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server