| | | 1 | | using Anichron.Core.Domain; |
| | | 2 | | using Anichron.Worker.Ingestion.Pipeline; |
| | | 3 | | using Anichron.Worker.Ingestion.Proxy; |
| | | 4 | | |
| | | 5 | | namespace Anichron.Worker.Ingestion.Classification; |
| | | 6 | | |
| | 57 | 7 | | internal sealed partial class LivePhotoPairer( |
| | 57 | 8 | | PairedMovResolver pairedMovResolver, |
| | 57 | 9 | | PairedMovProxyWriter pairedMovProxyWriter, |
| | 57 | 10 | | ILogger<LivePhotoPairer> logger) |
| | | 11 | | { |
| | | 12 | | public async Task PairAsync(IngestionContext context, IngestionClassification classification, CancellationToken ct) |
| | 48 | 13 | | { |
| | 48 | 14 | | if (classification.Pairing is PairingAction.AttachMov or PairingAction.PointAtMov) |
| | 15 | 15 | | { |
| | 15 | 16 | | var mov = await PointPhotoAtMovAsync(context, classification, ct); |
| | 15 | 17 | | if (classification.Pairing == PairingAction.AttachMov) |
| | 11 | 18 | | await pairedMovProxyWriter.WriteMissingAsync(context, mov, ct); |
| | 15 | 19 | | } |
| | 33 | 20 | | else if (classification.Pairing == PairingAction.BackfillMovProxy) |
| | 4 | 21 | | { |
| | 4 | 22 | | await pairedMovProxyWriter.WriteMissingAsync(context, classification.Secondary!.Stored!, ct); |
| | 4 | 23 | | } |
| | 48 | 24 | | } |
| | | 25 | | |
| | | 26 | | private async Task<MediaAsset> PointPhotoAtMovAsync( |
| | | 27 | | IngestionContext context, IngestionClassification classification, CancellationToken ct) |
| | 15 | 28 | | { |
| | 15 | 29 | | var heic = classification.Primary.Row!; |
| | 15 | 30 | | heic.MediaType = context.Item.PrimaryMediaType; |
| | 15 | 31 | | var mov = await pairedMovResolver.PairAsync(context, heic, ct); |
| | 15 | 32 | | Log.Paired(logger, context.Item.RelativePath, heic.Id); |
| | 15 | 33 | | return mov; |
| | 15 | 34 | | } |
| | | 35 | | |
| | | 36 | | private static partial class Log |
| | | 37 | | { |
| | | 38 | | [LoggerMessage(Level = LogLevel.Information, Message = "Paired already-ingested {RelativePath} (asset {AssetId}) |
| | | 39 | | public static partial void Paired(ILogger logger, string relativePath, Guid assetId); |
| | | 40 | | } |
| | | 41 | | } |