From 064b5e82e436c717f74a4d0a353e01e20da9752c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 15 Apr 2015 11:41:42 -0400 Subject: [PATCH] fix roku thumbnails --- MediaBrowser.Controller/Entities/BaseItem.cs | 6 +- .../Library/NameExtensions.cs | 56 ++++++++++++++++--- .../Encoder/MediaEncoder.cs | 18 +++--- .../Dto/DtoService.cs | 5 +- 4 files changed, 63 insertions(+), 22 deletions(-) diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index b7322494d..10fa4adad 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1894,12 +1894,12 @@ namespace MediaBrowser.Controller.Entities return video.RefreshMetadata(newOptions, cancellationToken); } - public string GetEtag() + public string GetEtag(User user) { - return string.Join("|", GetEtagValues().ToArray()).GetMD5().ToString("N"); + return string.Join("|", GetEtagValues(user).ToArray()).GetMD5().ToString("N"); } - protected virtual List GetEtagValues() + protected virtual List GetEtagValues(User user) { return new List { diff --git a/MediaBrowser.Controller/Library/NameExtensions.cs b/MediaBrowser.Controller/Library/NameExtensions.cs index b2acdc7ea..6973dce64 100644 --- a/MediaBrowser.Controller/Library/NameExtensions.cs +++ b/MediaBrowser.Controller/Library/NameExtensions.cs @@ -2,40 +2,78 @@ using MoreLinq; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; namespace MediaBrowser.Controller.Library { public static class NameExtensions { - public static bool AreEqual(string name1, string name2) + public static bool AreEqual(string x, string y) { - name1 = NormalizeForComparison(name1); - name2 = NormalizeForComparison(name2); + if (string.IsNullOrWhiteSpace(x) && string.IsNullOrWhiteSpace(y)) + { + return true; + } - return string.Equals(name1, name2, StringComparison.OrdinalIgnoreCase); + return string.Compare(x, y, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace) == 0; } - public static bool EqualsAny(IEnumerable names, string name) + public static bool EqualsAny(IEnumerable names, string x) { - name = NormalizeForComparison(name); + x = NormalizeForComparison(x); - return names.Any(i => string.Equals(NormalizeForComparison(i), name, StringComparison.OrdinalIgnoreCase)); + return names.Any(y => string.Compare(x, y, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace) == 0); } private static string NormalizeForComparison(string name) { - if (string.IsNullOrWhiteSpace(name)) + if (name == null) { return string.Empty; } + return name; + //return name.RemoveDiacritics(); + } + + private static string RemoveDiacritics(string name) + { + if (name == null) + { + return string.Empty; + } + + //return name; return name.RemoveDiacritics(); } public static IEnumerable DistinctNames(this IEnumerable names) { - return names.DistinctBy(NormalizeForComparison, StringComparer.OrdinalIgnoreCase); + return names.DistinctBy(RemoveDiacritics, StringComparer.OrdinalIgnoreCase); + } + } + + class TextComparer : IComparer, IEqualityComparer + { + public int Compare(string x, string y) + { + if (string.IsNullOrWhiteSpace(x) && string.IsNullOrWhiteSpace(y)) + { + return 0; + } + + return string.Compare(x, y, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace); + } + + public bool Equals(string x, string y) + { + return Compare(x, y) == 0; + } + + public int GetHashCode(string obj) + { + return (obj ?? string.Empty).GetHashCode(); } } } diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index df7351ad1..956b3723d 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -513,8 +513,6 @@ namespace MediaBrowser.MediaEncoding.Encoder var exitCode = ranToCompletion ? processWrapper.ExitCode ?? 0 : -1; - process.Dispose(); - if (exitCode == -1 || memoryStream.Length == 0) { memoryStream.Dispose(); @@ -594,7 +592,7 @@ namespace MediaBrowser.MediaEncoding.Encoder await resourcePool.WaitAsync(cancellationToken).ConfigureAwait(false); - bool ranToCompletion; + bool ranToCompletion = false; var processWrapper = new ProcessWrapper(process, this); @@ -609,19 +607,23 @@ namespace MediaBrowser.MediaEncoding.Encoder bool isResponsive = true; int lastCount = 0; - while (isResponsive && !process.WaitForExit(30000)) + while (isResponsive) { + if (process.WaitForExit(30000)) + { + ranToCompletion = true; + break; + } + cancellationToken.ThrowIfCancellationRequested(); - int jpegCount = Directory.GetFiles(targetDirectory) + var jpegCount = Directory.GetFiles(targetDirectory) .Count(i => string.Equals(Path.GetExtension(i), ".jpg", StringComparison.OrdinalIgnoreCase)); isResponsive = (jpegCount > lastCount); lastCount = jpegCount; } - ranToCompletion = process.HasExited; - if (!ranToCompletion) { StopProcess(processWrapper, 1000, false); @@ -634,8 +636,6 @@ namespace MediaBrowser.MediaEncoding.Encoder var exitCode = ranToCompletion ? processWrapper.ExitCode ?? 0 : -1; - process.Dispose(); - if (exitCode == -1) { var msg = string.Format("ffmpeg image extraction failed for {0}", inputArgument); diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index c4501564f..190b8fcf4 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -357,7 +357,10 @@ namespace MediaBrowser.Server.Implementations.Dto : item.CanDownload(user); } - + if (fields.Contains(ItemFields.Etag)) + { + dto.Etag = item.GetEtag(user); + } return dto; }