feat(backend): auto-download YouTube tracks saved to playlists

This commit is contained in:
2026-07-16 01:06:04 +02:00
parent 11ed8b40ff
commit 73826b9d08
18 changed files with 672 additions and 1 deletions
@@ -9,6 +9,7 @@ namespace Musify.Infrastructure.MassTransit.Sagas
public State Failed { get; private set; } = null!;
public Event<CreateTrackResourcesEvent> ProcessingStarted { get; private set; } = null!;
public Event<DownloadYouTubeTrackEvent> YouTubeDownloadStarted { get; private set; } = null!;
public Event<TrackPictureProcessed> PictureProcessed { get; private set; } = null!;
public Event<TrackAudioProcessed> AudioProcessed { get; private set; } = null!;
public Event<TrackPictureProcessingFailed> PictureFailed { get; private set; } = null!;
@@ -19,6 +20,7 @@ namespace Musify.Infrastructure.MassTransit.Sagas
InstanceState(state => state.CurrentState);
Event(() => ProcessingStarted, config => config.CorrelateById(context => context.Message.TrackId));
Event(() => YouTubeDownloadStarted, config => config.CorrelateById(context => context.Message.TrackId));
Event(() => PictureProcessed, config => config.CorrelateById(context => context.Message.TrackId));
Event(() => AudioProcessed, config => config.CorrelateById(context => context.Message.TrackId));
Event(() => PictureFailed, config => config.CorrelateById(context => context.Message.TrackId));
@@ -34,9 +36,20 @@ namespace Musify.Infrastructure.MassTransit.Sagas
context.Saga.PictureKey = context.Message.PictureDestinationKey;
context.Saga.AudioKey = context.Message.AudioDestinationKey;
} )
.TransitionTo(Processing),
When(YouTubeDownloadStarted)
.Then(context =>
{
context.Saga.CreatedAt = DateTime.UtcNow;
context.Saga.UpdatedAt = DateTime.UtcNow;
context.Saga.Bucket = context.Message.Bucket;
context.Saga.PictureKey = string.Empty;
context.Saga.AudioKey = string.Empty;
} )
.TransitionTo(Processing));
During(Processing,
Ignore(YouTubeDownloadStarted),
When(PictureProcessed)
.Then(context =>
{
@@ -72,7 +85,18 @@ namespace Musify.Infrastructure.MassTransit.Sagas
Ignore(PictureProcessed),
Ignore(AudioProcessed),
Ignore(PictureFailed),
Ignore(AudioFailed));
Ignore(AudioFailed),
When(YouTubeDownloadStarted)
.Then(context =>
{
context.Saga.UpdatedAt = DateTime.UtcNow;
context.Saga.PictureProcessed = false;
context.Saga.AudioProcessed = false;
context.Saga.Bucket = context.Message.Bucket;
context.Saga.PictureKey = string.Empty;
context.Saga.AudioKey = string.Empty;
} )
.TransitionTo(Processing));
SetCompletedWhenFinalized();
}