diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index 5b04ceea25..f19e3e037f 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -57,7 +57,6 @@ namespace Emby.Drawing private readonly IJsonSerializer _jsonSerializer; private readonly IServerApplicationPaths _appPaths; private readonly IImageEncoder _imageEncoder; - private readonly SemaphoreSlim _imageProcessingSemaphore; private readonly Func _libraryManager; public ImageProcessor(ILogger logger, @@ -102,8 +101,6 @@ namespace Emby.Drawing } _cachedImagedSizes = new ConcurrentDictionary(sizeDictionary); - _logger.Info("ImageProcessor started with {0} max concurrent image processes", maxConcurrentImageProcesses); - _imageProcessingSemaphore = new SemaphoreSlim(maxConcurrentImageProcesses, maxConcurrentImageProcesses); } public string[] SupportedInputFormats @@ -238,8 +235,6 @@ namespace Emby.Drawing var outputFormat = GetOutputFormat(options.SupportedOutputFormats[0]); var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, outputFormat, options.AddPlayedIndicator, options.PercentPlayed, options.UnplayedCount, options.Blur, options.BackgroundColor, options.ForegroundLayer); - //var imageProcessingLockTaken = false; - try { CheckDisposed(); @@ -253,10 +248,6 @@ namespace Emby.Drawing var tmpPath = Path.ChangeExtension(Path.Combine(_appPaths.TempDirectory, Guid.NewGuid().ToString("N")), Path.GetExtension(cacheFilePath)); _fileSystem.CreateDirectory(Path.GetDirectoryName(tmpPath)); - //await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false); - - //imageProcessingLockTaken = true; - _imageEncoder.EncodeImage(originalImagePath, tmpPath, AutoOrient(options.Item), newWidth, newHeight, quality, options, outputFormat); CopyFile(tmpPath, cacheFilePath); @@ -273,13 +264,6 @@ namespace Emby.Drawing // Just spit out the original file if all the options are default return new Tuple(originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); } - //finally - //{ - // if (imageProcessingLockTaken) - // { - // _imageProcessingSemaphore.Release(); - // } - //} } private void CopyFile(string src, string destination) @@ -786,24 +770,15 @@ namespace Emby.Drawing var tmpPath = Path.Combine(_appPaths.TempDirectory, Path.ChangeExtension(Guid.NewGuid().ToString(), Path.GetExtension(enhancedImagePath))); _fileSystem.CreateDirectory(Path.GetDirectoryName(tmpPath)); - await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false); + await ExecuteImageEnhancers(supportedEnhancers, originalImagePath, tmpPath, item, imageType, imageIndex).ConfigureAwait(false); try { - await ExecuteImageEnhancers(supportedEnhancers, originalImagePath, tmpPath, item, imageType, imageIndex).ConfigureAwait(false); - - try - { - _fileSystem.CopyFile(tmpPath, enhancedImagePath, true); - } - catch - { - - } + _fileSystem.CopyFile(tmpPath, enhancedImagePath, true); } - finally + catch { - _imageProcessingSemaphore.Release(); + } return tmpPath; diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 97f2c57eb0..af826f231b 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -49,16 +49,6 @@ namespace MediaBrowser.MediaEncoding.Encoder /// private readonly SemaphoreSlim _thumbnailResourcePool = new SemaphoreSlim(1, 1); - /// - /// The video image resource pool - /// - private readonly SemaphoreSlim _videoImageResourcePool = new SemaphoreSlim(1, 1); - - /// - /// The audio image resource pool - /// - private readonly SemaphoreSlim _audioImageResourcePool = new SemaphoreSlim(2, 2); - /// /// The FF probe resource pool /// @@ -724,8 +714,6 @@ namespace MediaBrowser.MediaEncoding.Encoder private async Task ExtractImage(string[] inputFiles, string container, int? imageStreamIndex, MediaProtocol protocol, bool isAudio, Video3DFormat? threedFormat, TimeSpan? offset, CancellationToken cancellationToken) { - var resourcePool = isAudio ? _audioImageResourcePool : _videoImageResourcePool; - var inputArgument = GetInputArgument(inputFiles, protocol); if (isAudio) @@ -740,7 +728,7 @@ namespace MediaBrowser.MediaEncoding.Encoder { try { - return await ExtractImageInternal(inputArgument, container, imageStreamIndex, protocol, threedFormat, offset, true, resourcePool, cancellationToken).ConfigureAwait(false); + return await ExtractImageInternal(inputArgument, container, imageStreamIndex, protocol, threedFormat, offset, true, cancellationToken).ConfigureAwait(false); } catch (ArgumentException) { @@ -752,10 +740,10 @@ namespace MediaBrowser.MediaEncoding.Encoder } } - return await ExtractImageInternal(inputArgument, container, imageStreamIndex, protocol, threedFormat, offset, false, resourcePool, cancellationToken).ConfigureAwait(false); + return await ExtractImageInternal(inputArgument, container, imageStreamIndex, protocol, threedFormat, offset, false, cancellationToken).ConfigureAwait(false); } - private async Task ExtractImageInternal(string inputPath, string container, int? imageStreamIndex, MediaProtocol protocol, Video3DFormat? threedFormat, TimeSpan? offset, bool useIFrame, SemaphoreSlim resourcePool, CancellationToken cancellationToken) + private async Task ExtractImageInternal(string inputPath, string container, int? imageStreamIndex, MediaProtocol protocol, Video3DFormat? threedFormat, TimeSpan? offset, bool useIFrame, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(inputPath)) { @@ -835,31 +823,21 @@ namespace MediaBrowser.MediaEncoding.Encoder using (var processWrapper = new ProcessWrapper(process, this, _logger)) { - await resourcePool.WaitAsync(cancellationToken).ConfigureAwait(false); - bool ranToCompletion; - try + StartProcess(processWrapper); + + var timeoutMs = ConfigurationManager.Configuration.ImageExtractionTimeoutMs; + if (timeoutMs <= 0) { - StartProcess(processWrapper); - - var timeoutMs = ConfigurationManager.Configuration.ImageExtractionTimeoutMs; - if (timeoutMs <= 0) - { - timeoutMs = DefaultImageExtractionTimeoutMs; - } - - ranToCompletion = process.WaitForExit(timeoutMs); - - if (!ranToCompletion) - { - StopProcess(processWrapper, 1000); - } - + timeoutMs = DefaultImageExtractionTimeoutMs; } - finally + + ranToCompletion = process.WaitForExit(timeoutMs); + + if (!ranToCompletion) { - resourcePool.Release(); + StopProcess(processWrapper, 1000); } var exitCode = ranToCompletion ? processWrapper.ExitCode ?? 0 : -1; @@ -1118,7 +1096,6 @@ namespace MediaBrowser.MediaEncoding.Encoder { if (dispose) { - _videoImageResourcePool.Dispose(); StopProcesses(); } } diff --git a/MediaBrowser.Providers/Omdb/OmdbProvider.cs b/MediaBrowser.Providers/Omdb/OmdbProvider.cs index 148bfc8a8d..2c368c97b2 100644 --- a/MediaBrowser.Providers/Omdb/OmdbProvider.cs +++ b/MediaBrowser.Providers/Omdb/OmdbProvider.cs @@ -14,8 +14,6 @@ using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Common.IO; -using MediaBrowser.Controller.IO; namespace MediaBrowser.Providers.Omdb { @@ -68,21 +66,11 @@ namespace MediaBrowser.Providers.Omdb item.ProductionYear = year; } - // Seeing some bogus RT data on omdb for series, so filter it out here - // RT doesn't even have tv series - int tomatoMeter; + var tomatoScore = result.GetRottenTomatoScore(); - if (!string.IsNullOrEmpty(result.tomatoMeter) - && int.TryParse(result.tomatoMeter, NumberStyles.Integer, _usCulture, out tomatoMeter) - && tomatoMeter >= 0) + if (tomatoScore.HasValue) { - item.CriticRating = tomatoMeter; - } - - if (!string.IsNullOrEmpty(result.tomatoConsensus) - && !string.Equals(result.tomatoConsensus, "No consensus yet.", StringComparison.OrdinalIgnoreCase)) - { - item.CriticRatingSummary = WebUtility.HtmlDecode(result.tomatoConsensus); + item.CriticRating = tomatoScore; } int voteCount; @@ -169,21 +157,11 @@ namespace MediaBrowser.Providers.Omdb item.ProductionYear = year; } - // Seeing some bogus RT data on omdb for series, so filter it out here - // RT doesn't even have tv series - int tomatoMeter; + var tomatoScore = result.GetRottenTomatoScore(); - if (!string.IsNullOrEmpty(result.tomatoMeter) - && int.TryParse(result.tomatoMeter, NumberStyles.Integer, _usCulture, out tomatoMeter) - && tomatoMeter >= 0) + if (tomatoScore.HasValue) { - item.CriticRating = tomatoMeter; - } - - if (!string.IsNullOrEmpty(result.tomatoConsensus) - && !string.Equals(result.tomatoConsensus, "No consensus yet.", StringComparison.OrdinalIgnoreCase)) - { - item.CriticRatingSummary = WebUtility.HtmlDecode(result.tomatoConsensus); + item.CriticRating = tomatoScore; } int voteCount; @@ -486,39 +464,51 @@ namespace MediaBrowser.Providers.Omdb public string Year { get; set; } public string Rated { get; set; } public string Released { get; set; } - public int Episode { get; set; } public string Runtime { get; set; } public string Genre { get; set; } public string Director { get; set; } public string Writer { get; set; } public string Actors { get; set; } public string Plot { get; set; } + public string Language { get; set; } + public string Country { get; set; } + public string Awards { get; set; } public string Poster { get; set; } + public List Ratings { get; set; } + public string Metascore { get; set; } public string imdbRating { get; set; } public string imdbVotes { get; set; } public string imdbID { get; set; } public string Type { get; set; } - public string tomatoMeter { get; set; } - public string tomatoImage { get; set; } - public string tomatoRating { get; set; } - public string tomatoReviews { get; set; } - public string tomatoFresh { get; set; } - public string tomatoRotten { get; set; } - public string tomatoConsensus { get; set; } - public string tomatoUserMeter { get; set; } - public string tomatoUserRating { get; set; } - public string tomatoUserReviews { get; set; } public string DVD { get; set; } public string BoxOffice { get; set; } public string Production { get; set; } public string Website { get; set; } public string Response { get; set; } + public int Episode { get; set; } - public string Language { get; set; } - public string Country { get; set; } - public string Awards { get; set; } - public string Metascore { get; set; } + public float? GetRottenTomatoScore() + { + if (Ratings != null) + { + var rating = Ratings.FirstOrDefault(i => string.Equals(i.Source, "Rotten Tomatoes", StringComparison.OrdinalIgnoreCase)); + if (rating != null && rating.Value != null) + { + var value = rating.Value.TrimEnd('%'); + float score; + if (float.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out score)) + { + return score; + } + } + } + return null; + } + } + public class OmdbRating + { + public string Source { get; set; } + public string Value { get; set; } } - } } diff --git a/MediaBrowser.XbmcMetadata/Providers/BaseNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/BaseNfoProvider.cs index 7e37d61df4..e5931cf25a 100644 --- a/MediaBrowser.XbmcMetadata/Providers/BaseNfoProvider.cs +++ b/MediaBrowser.XbmcMetadata/Providers/BaseNfoProvider.cs @@ -78,9 +78,4 @@ namespace MediaBrowser.XbmcMetadata.Providers } } } - - static class XmlProviderUtils - { - internal static readonly SemaphoreSlim XmlParsingResourcePool = new SemaphoreSlim(4, 4); - } }