@@ -98,52 +98,99 @@ func main() {
9898
9999 mbService := musicbrainz .NewMusicBrainzService (database )
100100 playingNowService := playingnow .NewPlayingNowService (database , atprotoService )
101- spotifyService := spotify .NewSpotifyService (database , atprotoService , mbService , playingNowService )
102- lastfmService := lastfm .NewLastFMService (database , viper .GetString ("lastfm.api_key" ), mbService , atprotoService , playingNowService )
103- // Read Apple Music settings with env fallbacks
104- teamID := viper .GetString ("applemusic.team_id" )
105- if teamID == "" {
106- teamID = viper .GetString ("APPLE_MUSIC_TEAM_ID" )
107- }
108- keyID := viper .GetString ("applemusic.key_id" )
109- if keyID == "" {
110- keyID = viper .GetString ("APPLE_MUSIC_KEY_ID" )
101+
102+ // Check feature toggles for music services
103+ enableSpotify := viper .GetBool ("enable_spotify" )
104+ enableLastFM := viper .GetBool ("enable_lastfm" )
105+ enableAppleMusic := viper .GetBool ("enable_applemusic" )
106+
107+ var spotifyService * spotify.Service
108+ var lastfmService * lastfm.Service
109+ var appleMusicService * applemusic.Service
110+
111+ // Initialize Spotify service if enabled and credentials are present
112+ if enableSpotify {
113+ clientID := viper .GetString ("spotify.client_id" )
114+ clientSecret := viper .GetString ("spotify.client_secret" )
115+
116+ if clientID != "" && clientSecret != "" {
117+ spotifyService = spotify .NewSpotifyService (database , atprotoService , mbService , playingNowService )
118+ log .Println ("Spotify service enabled and configured" )
119+ } else {
120+ log .Println ("Spotify enabled but credentials missing (client_id or client_secret). Spotify features will be disabled." )
121+ }
122+ } else {
123+ log .Println ("Spotify service disabled via ENABLE_SPOTIFY=false" )
111124 }
112- keyPath := viper .GetString ("applemusic.private_key_path" )
113- if keyPath == "" {
114- keyPath = viper .GetString ("APPLE_MUSIC_PRIVATE_KEY_PATH" )
125+
126+ // Initialize Last.fm service if enabled and API key is present
127+ if enableLastFM {
128+ apiKey := viper .GetString ("lastfm.api_key" )
129+
130+ if apiKey != "" {
131+ lastfmService = lastfm .NewLastFMService (database , apiKey , mbService , atprotoService , playingNowService )
132+ log .Println ("Last.fm service enabled and configured" )
133+ } else {
134+ log .Println ("Last.fm enabled but API key missing. Last.fm features will be disabled." )
135+ }
136+ } else {
137+ log .Println ("Last.fm service disabled via ENABLE_LASTFM=false" )
115138 }
116139
117- var appleMusicService * applemusic.Service
118- // Only initialize Apple Music service if all required credentials are present
119- if teamID != "" && keyID != "" && keyPath != "" {
120- appleMusicService = applemusic .NewService (
121- teamID ,
122- keyID ,
123- keyPath ,
124- ).WithPersistence (
125- func () (string , time.Time , bool , error ) {
126- return database .GetAppleMusicDeveloperToken ()
127- },
128- func (token string , exp time.Time ) error {
129- return database .SaveAppleMusicDeveloperToken (token , exp )
130- },
131- ).WithDeps (database , atprotoService , mbService , playingNowService )
140+ // Initialize Apple Music service if enabled and credentials are present
141+ if enableAppleMusic {
142+ // Read Apple Music settings with env fallbacks
143+ teamID := viper .GetString ("applemusic.team_id" )
144+ if teamID == "" {
145+ teamID = viper .GetString ("APPLE_MUSIC_TEAM_ID" )
146+ }
147+ keyID := viper .GetString ("applemusic.key_id" )
148+ if keyID == "" {
149+ keyID = viper .GetString ("APPLE_MUSIC_KEY_ID" )
150+ }
151+ keyPath := viper .GetString ("applemusic.private_key_path" )
152+ if keyPath == "" {
153+ keyPath = viper .GetString ("APPLE_MUSIC_PRIVATE_KEY_PATH" )
154+ }
155+
156+ // Only initialize if all required credentials are present
157+ if teamID != "" && keyID != "" && keyPath != "" {
158+ appleMusicService = applemusic .NewService (
159+ teamID ,
160+ keyID ,
161+ keyPath ,
162+ ).WithPersistence (
163+ func () (string , time.Time , bool , error ) {
164+ return database .GetAppleMusicDeveloperToken ()
165+ },
166+ func (token string , exp time.Time ) error {
167+ return database .SaveAppleMusicDeveloperToken (token , exp )
168+ },
169+ ).WithDeps (database , atprotoService , mbService , playingNowService )
170+ log .Println ("Apple Music service enabled and configured" )
171+ } else {
172+ log .Println ("Apple Music enabled but credentials missing (team_id, key_id, or private_key_path). Apple Music features will be disabled." )
173+ }
132174 } else {
133- log .Println ("Apple Music credentials not configured (missing team_id, key_id, or private_key_path). Apple Music features will be disabled. " )
175+ log .Println ("Apple Music service disabled via ENABLE_APPLEMUSIC=false " )
134176 }
135177
136178 oauthManager := oauth .NewOAuthServiceManager ()
137179
138- spotifyOAuth := oauth .NewOAuth2Service (
139- viper .GetString ("spotify.client_id" ),
140- viper .GetString ("spotify.client_secret" ),
141- viper .GetString ("callback.spotify" ),
142- viper .GetStringSlice ("spotify.scopes" ),
143- "spotify" ,
144- spotifyService ,
145- )
146- oauthManager .RegisterService ("spotify" , spotifyOAuth )
180+ // Register Spotify OAuth service only if Spotify is enabled and configured
181+ if spotifyService != nil {
182+ spotifyOAuth := oauth .NewOAuth2Service (
183+ viper .GetString ("spotify.client_id" ),
184+ viper .GetString ("spotify.client_secret" ),
185+ viper .GetString ("callback.spotify" ),
186+ viper .GetStringSlice ("spotify.scopes" ),
187+ "spotify" ,
188+ spotifyService ,
189+ )
190+ oauthManager .RegisterService ("spotify" , spotifyOAuth )
191+ log .Println ("Spotify OAuth service registered" )
192+ }
193+
147194 oauthManager .RegisterService ("atproto" , atprotoService )
148195
149196 apiKeyService := apikeyService .NewAPIKeyService (database , sessionManager )
@@ -162,18 +209,27 @@ func main() {
162209 }
163210
164211 trackerInterval := time .Duration (viper .GetInt ("tracker.interval" )) * time .Second
165- lastfmInterval := time .Duration (viper .GetInt ("lastfm.interval_seconds" )) * time .Second // Add config for Last.fm interval
166- if lastfmInterval <= 0 {
167- lastfmInterval = 30 * time .Second
212+
213+ // Start Spotify listening tracker if service is configured
214+ if spotifyService != nil {
215+ go spotifyService .StartListeningTracker (trackerInterval )
216+ log .Println ("Spotify listening tracker started" )
168217 }
169218
170- go spotifyService .StartListeningTracker (trackerInterval )
219+ // Start Last.fm listening tracker if service is configured
220+ if lastfmService != nil {
221+ lastfmInterval := time .Duration (viper .GetInt ("lastfm.interval_seconds" )) * time .Second
222+ if lastfmInterval <= 0 {
223+ lastfmInterval = 30 * time .Second
224+ }
225+ go lastfmService .StartListeningTracker (lastfmInterval )
226+ log .Println ("Last.fm listening tracker started" )
227+ }
171228
172- go lastfmService .StartListeningTracker (lastfmInterval )
173- // Apple Music tracker uses same tracker.interval as Spotify for now
174- // Only start if Apple Music service is configured
229+ // Start Apple Music tracker if service is configured
175230 if appleMusicService != nil {
176231 go appleMusicService .StartListeningTracker (trackerInterval )
232+ log .Println ("Apple Music listening tracker started" )
177233 }
178234
179235 serverAddr := fmt .Sprintf ("%s:%s" , viper .GetString ("server.host" ), viper .GetString ("server.port" ))
0 commit comments