aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs')
-rw-r--r--MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs55
1 files changed, 12 insertions, 43 deletions
diff --git a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs
index fee11d989..d65084287 100644
--- a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs
+++ b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs
@@ -6,14 +6,11 @@ using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
-using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
-using MediaBrowser.Common.IO;
-using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
namespace MediaBrowser.Providers.MediaInfo
@@ -23,8 +20,6 @@ namespace MediaBrowser.Providers.MediaInfo
/// </summary>
public class AudioImageProvider : IDynamicImageProvider, IHasItemChangeMonitor
{
- private readonly ConcurrentDictionary<string, SemaphoreSlim> _locks = new ConcurrentDictionary<string, SemaphoreSlim>();
-
private readonly IMediaEncoder _mediaEncoder;
private readonly IServerConfigurationManager _config;
private readonly IFileSystem _fileSystem;
@@ -67,41 +62,25 @@ namespace MediaBrowser.Providers.MediaInfo
if (!_fileSystem.FileExists(path))
{
- var semaphore = GetLock(path);
-
- // Acquire a lock
- await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
-
- try
- {
- // Check again in case it was saved while waiting for the lock
- if (!_fileSystem.FileExists(path))
- {
- _fileSystem.CreateDirectory(Path.GetDirectoryName(path));
-
- var imageStream = imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).IndexOf("front", StringComparison.OrdinalIgnoreCase) != -1) ??
- imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).IndexOf("cover", StringComparison.OrdinalIgnoreCase) != -1) ??
- imageStreams.FirstOrDefault();
+ _fileSystem.CreateDirectory(Path.GetDirectoryName(path));
- var imageStreamIndex = imageStream == null ? (int?)null : imageStream.Index;
+ var imageStream = imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).IndexOf("front", StringComparison.OrdinalIgnoreCase) != -1) ??
+ imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).IndexOf("cover", StringComparison.OrdinalIgnoreCase) != -1) ??
+ imageStreams.FirstOrDefault();
- var tempFile = await _mediaEncoder.ExtractAudioImage(item.Path, imageStreamIndex, cancellationToken).ConfigureAwait(false);
+ var imageStreamIndex = imageStream == null ? (int?)null : imageStream.Index;
- _fileSystem.CopyFile(tempFile, path, true);
+ var tempFile = await _mediaEncoder.ExtractAudioImage(item.Path, imageStreamIndex, cancellationToken).ConfigureAwait(false);
- try
- {
- _fileSystem.DeleteFile(tempFile);
- }
- catch
- {
+ _fileSystem.CopyFile(tempFile, path, true);
- }
- }
+ try
+ {
+ _fileSystem.DeleteFile(tempFile);
}
- finally
+ catch
{
- semaphore.Release();
+
}
}
@@ -145,16 +124,6 @@ namespace MediaBrowser.Providers.MediaInfo
}
}
- /// <summary>
- /// Gets the lock.
- /// </summary>
- /// <param name="filename">The filename.</param>
- /// <returns>SemaphoreSlim.</returns>
- private SemaphoreSlim GetLock(string filename)
- {
- return _locks.GetOrAdd(filename, key => new SemaphoreSlim(1, 1));
- }
-
public string Name
{
get { return "Image Extractor"; }