fix roku thumbnails

This commit is contained in:
Luke Pulverenti 2015-04-15 11:41:42 -04:00
parent 9189b551ec
commit 064b5e82e4
4 changed files with 63 additions and 22 deletions

View File

@ -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<string> GetEtagValues()
protected virtual List<string> GetEtagValues(User user)
{
return new List<string>
{

View File

@ -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<string> names, string name)
public static bool EqualsAny(IEnumerable<string> 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<string> DistinctNames(this IEnumerable<string> names)
{
return names.DistinctBy(NormalizeForComparison, StringComparer.OrdinalIgnoreCase);
return names.DistinctBy(RemoveDiacritics, StringComparer.OrdinalIgnoreCase);
}
}
class TextComparer : IComparer<string>, IEqualityComparer<string>
{
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();
}
}
}

View File

@ -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);

View File

@ -357,7 +357,10 @@ namespace MediaBrowser.Server.Implementations.Dto
: item.CanDownload(user);
}
if (fields.Contains(ItemFields.Etag))
{
dto.Etag = item.GetEtag(user);
}
return dto;
}