feat(backend): record listening history for YouTube playback

Playing a YouTube song now creates a lightweight track row (without queueing a download) and writes listening history; saving to a playlist queues the download via the new DownloadRequested flag.
This commit is contained in:
2026-07-16 01:15:36 +02:00
parent a6f976a065
commit 6d73fe88ab
8 changed files with 869 additions and 16 deletions
@@ -107,6 +107,29 @@ namespace Musify.Infrastructure.Services
return new YouTubeStreamInfo(audioStream.Url, expiresInSeconds);
}
public async Task<ErrorOr<YouTubeSongResult>> GetSongAsync(string videoId, CancellationToken cancellationToken)
{
try
{
var info = await client.GetSongVideoInfoAsync(videoId, cancellationToken);
return new YouTubeSongResult(
videoId,
info.Name,
string.Join(", ", info.Artists.Select(artist => artist.Name)),
string.Empty,
(int)info.Duration.TotalSeconds,
info.Thumbnails
.OrderByDescending(thumbnail => thumbnail.Width)
.Select(thumbnail => thumbnail.Url)
.FirstOrDefault() ?? string.Empty);
}
catch (Exception exception)
{
return Error.Failure(description: $"Failed to load YouTube song info for '{videoId}': {exception.Message}");
}
}
private static string SearchCacheKey(string token) => $"yt-search:{token}";
private static string StreamCacheKey(string videoId) => $"yt-stream:{videoId}";