diff --git a/allstarr/Services/SquidWTF/SquidWTFDownloadService.cs b/allstarr/Services/SquidWTF/SquidWTFDownloadService.cs
index 6468a33..bd227cc 100644
--- a/allstarr/Services/SquidWTF/SquidWTFDownloadService.cs
+++ b/allstarr/Services/SquidWTF/SquidWTFDownloadService.cs
@@ -7,6 +7,7 @@ using allstarr.Models.Search;
using allstarr.Models.Subsonic;
using allstarr.Services.Local;
using allstarr.Services.Common;
+using allstarr.Services.Lyrics;
using Microsoft.Extensions.Options;
using IOFile = System.IO.File;
using Microsoft.Extensions.Logging;
@@ -55,6 +56,7 @@ public class SquidWTFDownloadService : BaseDownloadService
private readonly SquidWTFSettings _squidwtfSettings;
private readonly OdesliService _odesliService;
private readonly RoundRobinFallbackHelper _fallbackHelper;
+ private readonly IServiceProvider _serviceProvider;
protected override string ProviderName => "squidwtf";
@@ -75,6 +77,7 @@ public class SquidWTFDownloadService : BaseDownloadService
_squidwtfSettings = SquidWTFSettings.Value;
_odesliService = odesliService;
_fallbackHelper = new RoundRobinFallbackHelper(apiUrls, logger, "SquidWTF");
+ _serviceProvider = serviceProvider;
}
@@ -311,6 +314,7 @@ public class SquidWTFDownloadService : BaseDownloadService
///
/// Converts Tidal track ID to Spotify ID for lyrics support.
/// Called in background after streaming starts.
+ /// Also prefetches lyrics immediately after conversion.
///
protected override async Task ConvertToSpotifyIdAsync(string externalProvider, string externalId)
{
@@ -323,7 +327,35 @@ public class SquidWTFDownloadService : BaseDownloadService
if (!string.IsNullOrEmpty(spotifyId))
{
Logger.LogDebug("Background Spotify ID obtained for Tidal/{TrackId}: {SpotifyId}", externalId, spotifyId);
- // Spotify ID is cached by Odesli service for future lyrics requests
+
+ // Immediately prefetch lyrics now that we have the Spotify ID
+ // This ensures lyrics are cached and ready when the client requests them
+ _ = Task.Run(async () =>
+ {
+ try
+ {
+ using var scope = _serviceProvider.CreateScope();
+ var spotifyLyricsService = scope.ServiceProvider.GetService();
+
+ if (spotifyLyricsService != null)
+ {
+ var lyrics = await spotifyLyricsService.GetLyricsByTrackIdAsync(spotifyId);
+ if (lyrics != null && lyrics.Lines.Count > 0)
+ {
+ Logger.LogDebug("Background lyrics prefetched for Spotify/{SpotifyId}: {LineCount} lines",
+ spotifyId, lyrics.Lines.Count);
+ }
+ else
+ {
+ Logger.LogDebug("No lyrics available for Spotify/{SpotifyId}", spotifyId);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ Logger.LogDebug(ex, "Background lyrics prefetch failed for Spotify/{SpotifyId}", spotifyId);
+ }
+ });
}
}