@elizaos/plugin-music 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,192 @@
1
+ # @elizaos/plugin-music-library
2
+
3
+ A comprehensive plugin for elizaOS that provides music data storage, user preferences, analytics, external music metadata APIs, and YouTube search functionality.
4
+
5
+ ## Features
6
+
7
+ ### Music Metadata & External APIs
8
+ - **Track Information**: Extract metadata from YouTube URLs and track titles
9
+ - **Artist Information**: Get artist details from multiple sources
10
+ - **Album Information**: Retrieve album metadata
11
+ - **Multiple Sources**: MusicBrainz, Last.fm, Genius, TheAudioDB, Wikipedia
12
+ - **Fallback Chain**: Automatically tries multiple sources for best results
13
+ - **Rate Limiting**: Built-in rate limiting for all APIs
14
+ - **Retry Logic**: Automatic retry with exponential backoff
15
+ - **Service Health Monitoring**: Tracks status of all integrated APIs
16
+
17
+ ### YouTube Integration
18
+ - **YouTube Search**: Search for tracks, artists, albums on YouTube
19
+ - **Smart Query Parsing**: Detects artist, genre, mood intents
20
+ - **URL Extraction**: Parse and validate YouTube URLs
21
+
22
+ ### Music Library & Data Storage
23
+ - **Track Database**: Store and discover tracks, albums, artists
24
+ - **Play History**: Track what's been played and when
25
+ - **Request Tracking**: Log who requested which tracks
26
+ - **High-Quality Music Storage**: Store original high-quality audio files for archival
27
+ - Organized by artist/album/track
28
+ - Full metadata indexing
29
+ - Optional high-quality vs standard quality modes
30
+
31
+ ### Playlists
32
+ - **Create & Save**: Save playlists for users
33
+ - **Load & List**: Load and list playlists
34
+ - **Share**: Share playlists between users
35
+
36
+ ### User Preferences
37
+ - **Favorite Tracks**: Track user favorite tracks
38
+ - **Favorite Artists**: Track favorite artists
39
+ - **Disliked Tracks**: Remember what users don't like
40
+ - **Genre Preferences**: Learn genre preferences over time
41
+ - **Room Preferences**: Aggregate preferences across users in a room
42
+
43
+ ### Analytics
44
+ - **Play Tracking**: Track every play with duration and requester
45
+ - **Session Tracking**: Track listening sessions
46
+ - **Statistics**: Get analytics for rooms (top tracks, artists, genres)
47
+
48
+ ### Anti-Repetition
49
+ - **Repetition Control**: Prevent tracks from replaying too soon
50
+ - **Variety Scoring**: Score tracks by variety to encourage diverse playlists
51
+
52
+ ## Installation
53
+
54
+ As this is a workspace package, it's installed as part of the elizaOS monorepo:
55
+
56
+ ```bash
57
+ bun install
58
+ ```
59
+
60
+ ## Configuration
61
+
62
+ The plugin works out of the box with MusicBrainz (free, no API key needed). For enhanced features, configure additional APIs:
63
+
64
+ ### Storage Configuration
65
+
66
+ ```bash
67
+ # High-quality music storage directory (default: ./storage/music)
68
+ MUSIC_STORAGE_DIR=/path/to/storage
69
+
70
+ # Store highest quality available (default: true)
71
+ MUSIC_STORAGE_HIGH_QUALITY=true
72
+ ```
73
+
74
+ **Storage vs Cache**:
75
+ - **Music Library Storage** (this plugin): Permanent high-quality storage for archival and library management
76
+ - Original quality files (WebM, MP4, etc.)
77
+ - Organized by artist/album/track
78
+ - Indexed for browsing and discovery
79
+ - No expiration
80
+ - **Music Player Cache** (`plugin-music-player`): Temporary Discord-optimized cache for performance
81
+ - Pre-transcoded to Opus/WebM for Discord
82
+ - Flat cache directory
83
+ - 7-day TTL with automatic cleanup
84
+ - Trades disk space for reduced CPU/bandwidth
85
+
86
+ ### Optional Configuration
87
+
88
+ Add these to your `.env` file for enhanced metadata:
89
+
90
+ ```bash
91
+ # MusicBrainz (optional - custom User-Agent)
92
+ MUSICBRAINZ_USER_AGENT=YourAppName/1.0.0 (https://yourapp.com)
93
+
94
+ # Last.fm API (free tier with signup)
95
+ LASTFM_API_KEY=your_lastfm_api_key
96
+
97
+ # Genius API (free tier with signup) - for lyrics URLs
98
+ GENIUS_API_KEY=your_genius_api_key
99
+
100
+ # TheAudioDB API (free tier with signup) - for high-quality artwork
101
+ THEAUDIODB_API_KEY=your_theaudiodb_api_key
102
+ ```
103
+
104
+ ## Usage
105
+
106
+ Add the plugin to your character configuration:
107
+
108
+ ```json
109
+ {
110
+ "plugins": [
111
+ "@elizaos/plugin-sql",
112
+ "@elizaos/plugin-music-library"
113
+ ]
114
+ }
115
+ ```
116
+
117
+ ### Service Usage
118
+
119
+ Access services directly in your code:
120
+
121
+ ```typescript
122
+ const musicLibrary = runtime.getService('musicLibrary');
123
+
124
+ // Get track info
125
+ const trackInfo = await musicLibrary.getTrackInfo('https://youtube.com/watch?v=...');
126
+
127
+ // Save a playlist
128
+ const playlist = await musicLibrary.savePlaylist(userId, {
129
+ name: 'My Playlist',
130
+ tracks: [...]
131
+ });
132
+
133
+ // Track analytics
134
+ await musicLibrary.trackTrackPlayed(roomId, track, duration, requester);
135
+
136
+ // Get user preferences
137
+ const prefs = await musicLibrary.getUserPreferences(userId);
138
+ ```
139
+
140
+ ### Actions
141
+
142
+ Available actions:
143
+ - `MUSIC_LIBRARY` - Consolidated planner-facing action.
144
+ - `op=playlist`, `subaction=save|load|delete|add` - Manage playlists.
145
+ - `op=search-youtube` - Search YouTube for music.
146
+ - `op=play-query` - Smart music query parser.
147
+ - `op=download` - Download music to the local library.
148
+
149
+ Legacy planner action names such as `PLAYLIST_OP`, `PLAYLIST`,
150
+ `SEARCH_YOUTUBE`, `PLAY_MUSIC_QUERY`, and `DOWNLOAD_MUSIC` are retained as
151
+ similes for `MUSIC_LIBRARY`.
152
+
153
+ ## Integration with Other Plugins
154
+
155
+ This plugin is designed to work with:
156
+
157
+ - **@elizaos/plugin-music-player**: Provides data storage for playback
158
+ - **@elizaos/plugin-radio**: Provides preferences and analytics for radio programming
159
+ - **@elizaos/plugin-sql**: Required for data persistence
160
+
161
+ ## API
162
+
163
+ ### Services
164
+
165
+ #### MusicInfoService
166
+ - `getTrackInfo(urlOrTitle: string)`: Get track metadata
167
+ - `getArtistInfo(artistName: string)`: Get artist information
168
+ - `getAlbumInfo(albumTitle: string, artistName?: string)`: Get album information
169
+
170
+ #### YouTubeSearchService
171
+ - `search(query: string, maxResults?: number)`: Search YouTube
172
+ - `extractVideoId(url: string)`: Extract video ID from URL
173
+
174
+ #### MusicLibraryService
175
+ - `addSong(song)`, `getSong(url)`, `getRecentSongs(limit)`, `searchLibrary(query)`
176
+ - `savePlaylist(entityId, playlist)`, `loadPlaylists(entityId)`
177
+ - `trackTrackPlayed(roomId, track, duration)`, `trackTrackRequest(entityId, track)`
178
+ - `getAggregatedRoomPreferences(roomId)` returns combined favorites/dislikes for auto-fill logic
179
+ - Exposes `repetitionControl` utilities and a configured `spotifyClient`
180
+
181
+ ### Components
182
+
183
+ See individual component files for detailed APIs:
184
+ - `components/musicLibrary.ts` - Track/album/artist database
185
+ - `components/playlists.ts` - Playlist management
186
+ - `components/preferences.ts` - User preferences
187
+ - `components/analytics.ts` - Analytics tracking
188
+ - `components/repetitionControl.ts` - Anti-repetition logic
189
+
190
+ ## License
191
+
192
+ MIT