Retrieves a list of recently skipped tracks

Fetches and formats information about the most recently skipped tracks, including detailed metadata and skip statistics. This function provides the data needed for "Recently Skipped" UI displays and trend analysis.

The returned data includes:

  • Track identifiers and basic metadata (name, artist, album)
  • Timestamp of most recent skip
  • Skip percentage (how often this track is skipped)
  • Total skip count for each track

The results are sorted by recency, with the most recently skipped tracks appearing first. This provides an up-to-date view of listening behavior and helps identify potential patterns in recently skipped content.

// Display the 5 most recently skipped tracks
const recentSkips = await getRecentSkippedTracks(5);
renderRecentSkipsWidget(recentSkips);
export const getRecentSkippedTracks = async (
limit: number = 10,
): Promise<
Array<{
id: string;
name: string;
artist: string;
album: string;
timestamp: string;
skipPercentage: number;
skipCount: number;
}>
> => {
try {
const statistics = await getStatistics();

// Convert track metrics to array and sort by last played (most recent first)
const tracks = Object.entries(statistics.trackMetrics)
.map(([id, metrics]) => ({
id,
name: metrics.name || "Unknown Track",
artist: metrics.artistName || "Unknown Artist",
album: "Unknown Album", // We don't have album info in the metrics
timestamp: metrics.lastPlayed || new Date().toISOString(),
skipPercentage:
metrics.skipCount > 0
? Math.round(
(metrics.skipCount / Math.max(metrics.playCount, 1)) * 100,
)
: 0,
skipCount: metrics.skipCount || 0,
}))
.filter((track) => track.skipCount > 0) // Only include tracks that have been skipped
.sort(
(a, b) =>
new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime(),
) // Sort by most recent
.slice(0, limit); // Take only the specified number of tracks

return tracks;
} catch (error) {
console.error("Error getting recent skipped tracks:", error);
return [];
}
};
  • Parameters

    • limit: number = 10

      Maximum number of tracks to return (default: 10)

    Returns Promise<
        {
            id: string;
            name: string;
            artist: string;
            album: string;
            timestamp: string;
            skipPercentage: number;
            skipCount: number;
        }[],
    >

    Promise resolving to an array of recent skipped track objects