Add logging to Spotify lyrics search for better debugging

Show when Spotify search is skipped, fails, or finds no matches
This commit is contained in:
2026-02-06 00:59:23 -05:00
parent e36e685bee
commit 2dd7020a61

View File

@@ -136,6 +136,7 @@ public class SpotifyLyricsService
{
if (!_settings.Enabled || string.IsNullOrEmpty(_settings.SessionCookie))
{
_logger.LogDebug("Spotify lyrics search skipped: API not enabled or no session cookie");
return null;
}
@@ -144,6 +145,7 @@ public class SpotifyLyricsService
var token = await _spotifyClient.GetWebAccessTokenAsync();
if (string.IsNullOrEmpty(token))
{
_logger.LogWarning("Could not get Spotify access token for lyrics search");
return null;
}
@@ -154,6 +156,8 @@ public class SpotifyLyricsService
query += $" album:{albumName}";
}
_logger.LogDebug("Searching Spotify for lyrics: {Query}", query);
var searchUrl = $"https://api.spotify.com/v1/search?q={Uri.EscapeDataString(query)}&type=track&limit=5";
var request = new HttpRequestMessage(HttpMethod.Get, searchUrl);
@@ -162,6 +166,7 @@ public class SpotifyLyricsService
var response = await _httpClient.SendAsync(request);
if (!response.IsSuccessStatusCode)
{
_logger.LogWarning("Spotify search failed with status {StatusCode}", response.StatusCode);
return null;
}
@@ -173,6 +178,7 @@ public class SpotifyLyricsService
!tracks.TryGetProperty("items", out var items) ||
items.GetArrayLength() == 0)
{
_logger.LogInformation("No Spotify tracks found for: {Track} - {Artist}", trackName, artistName);
return null;
}
@@ -205,9 +211,11 @@ public class SpotifyLyricsService
if (!string.IsNullOrEmpty(bestMatchId))
{
_logger.LogDebug("Found Spotify track match: {TrackId} (score: {Score})", bestMatchId, bestScore);
return await GetLyricsByTrackIdAsync(bestMatchId);
}
_logger.LogInformation("No suitable Spotify track match found for: {Track} - {Artist}", trackName, artistName);
return null;
}
catch (Exception ex)