From 45e8872cc086fe2b086e209a08839b3ff689ecf3 Mon Sep 17 00:00:00 2001 From: gnattu Date: Mon, 27 May 2024 01:40:28 +0800 Subject: [PATCH] Extract media attachment one by one if the filename appears to be a path (#11812) --- .../Attachments/AttachmentExtractor.cs | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs b/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs index 3b7745b6a1..9149905586 100644 --- a/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs +++ b/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs @@ -89,15 +89,28 @@ namespace MediaBrowser.MediaEncoding.Attachments string outputPath, CancellationToken cancellationToken) { - using (await _semaphoreLocks.LockAsync(outputPath, cancellationToken).ConfigureAwait(false)) + var shouldExtractOneByOne = mediaSource.MediaAttachments.Any(a => a.FileName.Contains('/', StringComparison.OrdinalIgnoreCase) || a.FileName.Contains('\\', StringComparison.OrdinalIgnoreCase)); + if (shouldExtractOneByOne) { - if (!Directory.Exists(outputPath)) + var attachmentIndexes = mediaSource.MediaAttachments.Select(a => a.Index); + foreach (var i in attachmentIndexes) { - await ExtractAllAttachmentsInternal( - _mediaEncoder.GetInputArgument(inputFile, mediaSource), - outputPath, - false, - cancellationToken).ConfigureAwait(false); + var newName = Path.Join(outputPath, i.ToString(CultureInfo.InvariantCulture)); + await ExtractAttachment(inputFile, mediaSource, i, newName, cancellationToken).ConfigureAwait(false); + } + } + else + { + using (await _semaphoreLocks.LockAsync(outputPath, cancellationToken).ConfigureAwait(false)) + { + if (!Directory.Exists(outputPath)) + { + await ExtractAllAttachmentsInternal( + _mediaEncoder.GetInputArgument(inputFile, mediaSource), + outputPath, + false, + cancellationToken).ConfigureAwait(false); + } } } }