mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
feat: prefetch lyrics immediately after Odesli conversion
- After Odesli converts Tidal ID to Spotify ID, immediately fetch lyrics - Lyrics are cached and ready when client requests them - Happens in background, doesn't block streaming - Ensures best user experience with instant lyrics availability
This commit is contained in:
@@ -7,6 +7,7 @@ using allstarr.Models.Search;
|
|||||||
using allstarr.Models.Subsonic;
|
using allstarr.Models.Subsonic;
|
||||||
using allstarr.Services.Local;
|
using allstarr.Services.Local;
|
||||||
using allstarr.Services.Common;
|
using allstarr.Services.Common;
|
||||||
|
using allstarr.Services.Lyrics;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using IOFile = System.IO.File;
|
using IOFile = System.IO.File;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@@ -55,6 +56,7 @@ public class SquidWTFDownloadService : BaseDownloadService
|
|||||||
private readonly SquidWTFSettings _squidwtfSettings;
|
private readonly SquidWTFSettings _squidwtfSettings;
|
||||||
private readonly OdesliService _odesliService;
|
private readonly OdesliService _odesliService;
|
||||||
private readonly RoundRobinFallbackHelper _fallbackHelper;
|
private readonly RoundRobinFallbackHelper _fallbackHelper;
|
||||||
|
private readonly IServiceProvider _serviceProvider;
|
||||||
|
|
||||||
protected override string ProviderName => "squidwtf";
|
protected override string ProviderName => "squidwtf";
|
||||||
|
|
||||||
@@ -75,6 +77,7 @@ public class SquidWTFDownloadService : BaseDownloadService
|
|||||||
_squidwtfSettings = SquidWTFSettings.Value;
|
_squidwtfSettings = SquidWTFSettings.Value;
|
||||||
_odesliService = odesliService;
|
_odesliService = odesliService;
|
||||||
_fallbackHelper = new RoundRobinFallbackHelper(apiUrls, logger, "SquidWTF");
|
_fallbackHelper = new RoundRobinFallbackHelper(apiUrls, logger, "SquidWTF");
|
||||||
|
_serviceProvider = serviceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -311,6 +314,7 @@ public class SquidWTFDownloadService : BaseDownloadService
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts Tidal track ID to Spotify ID for lyrics support.
|
/// Converts Tidal track ID to Spotify ID for lyrics support.
|
||||||
/// Called in background after streaming starts.
|
/// Called in background after streaming starts.
|
||||||
|
/// Also prefetches lyrics immediately after conversion.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override async Task ConvertToSpotifyIdAsync(string externalProvider, string externalId)
|
protected override async Task ConvertToSpotifyIdAsync(string externalProvider, string externalId)
|
||||||
{
|
{
|
||||||
@@ -323,7 +327,35 @@ public class SquidWTFDownloadService : BaseDownloadService
|
|||||||
if (!string.IsNullOrEmpty(spotifyId))
|
if (!string.IsNullOrEmpty(spotifyId))
|
||||||
{
|
{
|
||||||
Logger.LogDebug("Background Spotify ID obtained for Tidal/{TrackId}: {SpotifyId}", externalId, 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<SpotifyLyricsService>();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user