Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/MediaBrowser/Emby
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed Nov 2, 2017
2 parents 51216d1 + ee3122f commit 1fe5913
Show file tree
Hide file tree
Showing 227 changed files with 2,068 additions and 1,892 deletions.
4 changes: 2 additions & 2 deletions Emby.Drawing.Skia/Emby.Drawing.Skia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
<EmbeddedResource Include="fonts\robotoregular.ttf" />
</ItemGroup>
<ItemGroup>
<Reference Include="SkiaSharp, Version=1.58.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\SkiaSharp.1.58.1\lib\portable-net45+win8+wpa81+wp8\SkiaSharp.dll</HintPath>
<Reference Include="SkiaSharp, Version=1.59.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\SkiaSharp.1.59.2\lib\portable-net45+win8+wpa81+wp8\SkiaSharp.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
62 changes: 53 additions & 9 deletions Emby.Drawing.Skia/SkiaEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,27 @@
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using MediaBrowser.Controller.Extensions;
using System.Globalization;
using MediaBrowser.Model.Globalization;

namespace Emby.Drawing.Skia
{
public class SkiaEncoder : IImageEncoder
{
private readonly ILogger _logger;
private readonly IApplicationPaths _appPaths;
private static IApplicationPaths _appPaths;
private readonly Func<IHttpClient> _httpClientFactory;
private readonly IFileSystem _fileSystem;
private static ILocalizationManager _localizationManager;

public SkiaEncoder(ILogger logger, IApplicationPaths appPaths, Func<IHttpClient> httpClientFactory, IFileSystem fileSystem)
public SkiaEncoder(ILogger logger, IApplicationPaths appPaths, Func<IHttpClient> httpClientFactory, IFileSystem fileSystem, ILocalizationManager localizationManager)
{
_logger = logger;
_appPaths = appPaths;
_httpClientFactory = httpClientFactory;
_fileSystem = fileSystem;
_localizationManager = localizationManager;

LogVersion();
}
Expand Down Expand Up @@ -190,14 +195,53 @@ public ImageSize GetImageSize(string path)
}
}

private static bool HasDiacritics(string text)
{
return !String.Equals(text, text.RemoveDiacritics(), StringComparison.Ordinal);
}

private static bool RequiresSpecialCharacterHack(string path)
{
if (_localizationManager.HasUnicodeCategory(path, UnicodeCategory.OtherLetter))
{
return true;
}

if (HasDiacritics(path))
{
return true;
}

return false;
}

private static string NormalizePath(string path, IFileSystem fileSystem)
{
if (!RequiresSpecialCharacterHack(path))
{
return path;
}

var tempPath = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + Path.GetExtension(path) ?? string.Empty);

fileSystem.CopyFile(path, tempPath, true);

return tempPath;
}

private static string[] TransparentImageTypes = new string[] { ".png", ".gif", ".webp" };
internal static SKBitmap Decode(string path, bool forceCleanBitmap, out SKCodecOrigin origin)
internal static SKBitmap Decode(string path, bool forceCleanBitmap, IFileSystem fileSystem, out SKCodecOrigin origin)
{
if (!fileSystem.FileExists(path))
{
throw new FileNotFoundException("File not found", path);
}

var requiresTransparencyHack = TransparentImageTypes.Contains(Path.GetExtension(path) ?? string.Empty);

if (requiresTransparencyHack || forceCleanBitmap)
{
using (var stream = new SKFileStream(path))
using (var stream = new SKFileStream(NormalizePath(path, fileSystem)))
{
using (var codec = SKCodec.Create(stream))
{
Expand Down Expand Up @@ -227,19 +271,19 @@ internal static SKBitmap Decode(string path, bool forceCleanBitmap, out SKCodecO
}
}

var resultBitmap = SKBitmap.Decode(path);
var resultBitmap = SKBitmap.Decode(NormalizePath(path, fileSystem));

if (resultBitmap == null)
{
return Decode(path, true, out origin);
return Decode(path, true, fileSystem, out origin);
}

// If we have to resize these they often end up distorted
if (resultBitmap.ColorType == SKColorType.Gray8)
{
using (resultBitmap)
{
return Decode(path, true, out origin);
return Decode(path, true, fileSystem, out origin);
}
}

Expand All @@ -251,13 +295,13 @@ private SKBitmap GetBitmap(string path, bool cropWhitespace, bool forceAnalyzeBi
{
if (cropWhitespace)
{
using (var bitmap = Decode(path, forceAnalyzeBitmap, out origin))
using (var bitmap = Decode(path, forceAnalyzeBitmap, _fileSystem, out origin))
{
return CropWhiteSpace(bitmap);
}
}

return Decode(path, forceAnalyzeBitmap, out origin);
return Decode(path, forceAnalyzeBitmap, _fileSystem, out origin);
}

private SKBitmap GetBitmap(string path, bool cropWhitespace, bool autoOrient)
Expand Down
4 changes: 2 additions & 2 deletions Emby.Drawing.Skia/StripCollageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private SKBitmap BuildThumbCollageBitmap(string[] paths, int width, int height)
for (int i = 0; i < 4; i++)
{
SKCodecOrigin origin;
using (var currentBitmap = SkiaEncoder.Decode(paths[imageIndex], false, out origin))
using (var currentBitmap = SkiaEncoder.Decode(paths[imageIndex], false, _fileSystem, out origin))
{
// resize to the same aspect as the original
int iWidth = (int)Math.Abs(iHeight * currentBitmap.Width / currentBitmap.Height);
Expand Down Expand Up @@ -165,7 +165,7 @@ private SKBitmap BuildSquareCollageBitmap(string[] paths, int width, int height)
for (var y = 0; y < 2; y++)
{
SKCodecOrigin origin;
using (var currentBitmap = SkiaEncoder.Decode(paths[imageIndex], false, out origin))
using (var currentBitmap = SkiaEncoder.Decode(paths[imageIndex], false, _fileSystem, out origin))
{
using (var resizedBitmap = new SKBitmap(cellWidth, cellHeight, currentBitmap.ColorType, currentBitmap.AlphaType))
{
Expand Down
2 changes: 1 addition & 1 deletion Emby.Drawing.Skia/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="SkiaSharp" version="1.58.1" targetFramework="portable45-net45+win8" />
<package id="SkiaSharp" version="1.59.2" targetFramework="portable45-net45+win8" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -195,52 +195,49 @@ private void ValidateMetadataPath(ServerConfiguration newConfig)
}
}

public void DisableMetadataService(string service)
public bool SetOptimalValues()
{
DisableMetadataService(typeof(Movie), Configuration, service);
DisableMetadataService(typeof(Episode), Configuration, service);
DisableMetadataService(typeof(Series), Configuration, service);
DisableMetadataService(typeof(Season), Configuration, service);
DisableMetadataService(typeof(MusicArtist), Configuration, service);
DisableMetadataService(typeof(MusicAlbum), Configuration, service);
DisableMetadataService(typeof(MusicVideo), Configuration, service);
DisableMetadataService(typeof(Video), Configuration, service);
}
var config = Configuration;

private void DisableMetadataService(Type type, ServerConfiguration config, string service)
{
var options = GetMetadataOptions(type, config);
var changed = false;

if (!options.DisabledMetadataSavers.Contains(service, StringComparer.OrdinalIgnoreCase))
if (!config.EnableCaseSensitiveItemIds)
{
var list = options.DisabledMetadataSavers.ToList();

list.Add(service);

options.DisabledMetadataSavers = list.ToArray(list.Count);
config.EnableCaseSensitiveItemIds = true;
changed = true;
}
}

private MetadataOptions GetMetadataOptions(Type type, ServerConfiguration config)
{
var options = config.MetadataOptions
.FirstOrDefault(i => string.Equals(i.ItemType, type.Name, StringComparison.OrdinalIgnoreCase));
if (!config.SkipDeserializationForBasicTypes)
{
config.SkipDeserializationForBasicTypes = true;
changed = true;
}

if (options == null)
if (!config.EnableSimpleArtistDetection)
{
var list = config.MetadataOptions.ToList();
config.EnableSimpleArtistDetection = true;
changed = true;
}

options = new MetadataOptions
{
ItemType = type.Name
};
if (!config.EnableNormalizedItemByNameIds)
{
config.EnableNormalizedItemByNameIds = true;
changed = true;
}

list.Add(options);
if (!config.DisableLiveTvChannelUserDataName)
{
config.DisableLiveTvChannelUserDataName = true;
changed = true;
}

config.MetadataOptions = list.ToArray(list.Count);
if (!config.EnableNewOmdbSupport)
{
config.EnableNewOmdbSupport = true;
changed = true;
}

return options;
return changed;
}
}
}
3 changes: 2 additions & 1 deletion Emby.Server.Implementations/Data/SqliteItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5298,7 +5298,8 @@ private QueryResult<Tuple<BaseItem, ItemCounts>> GetItemValues(InternalItemsQuer
OfficialRatings = query.OfficialRatings,
GenreIds = query.GenreIds,
Genres = query.Genres,
Years = query.Years
Years = query.Years,
NameContains = query.NameContains
};

var outerWhereClauses = GetWhereClauses(outerQuery, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,8 @@
<Reference Include="SharpCompress, Version=0.18.2.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
<HintPath>..\packages\SharpCompress.0.18.2\lib\net45\SharpCompress.dll</HintPath>
</Reference>
<Reference Include="SimpleInjector, Version=4.0.8.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
<HintPath>..\packages\SimpleInjector.4.0.8\lib\net45\SimpleInjector.dll</HintPath>
<Reference Include="SimpleInjector, Version=4.0.12.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
<HintPath>..\packages\SimpleInjector.4.0.12\lib\net45\SimpleInjector.dll</HintPath>
</Reference>
<Reference Include="SQLitePCL.pretty, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SQLitePCL.pretty.1.1.0\lib\portable-net45+netcore45+wpa81+wp8\SQLitePCL.pretty.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private MultiItemResolverResult ResolveVideos<T>(Folder parent, IEnumerable<File
ProductionYear = video.Year,
Name = parseName ?
video.Name :
Path.GetFileName(video.Files[0].Path),
Path.GetFileNameWithoutExtension(video.Files[0].Path),
AdditionalParts = video.Files.Skip(1).Select(i => i.Path).ToArray(),
LocalAlternateVersions = video.AlternateVersions.Select(i => i.Path).ToArray()
};
Expand Down
39 changes: 30 additions & 9 deletions Emby.Server.Implementations/Library/SearchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ private Task<IEnumerable<SearchHintInfo>> GetSearchHints(SearchQuery query, User

var terms = GetWords(searchTerm);

var hints = new List<Tuple<BaseItem, string, int>>();

var excludeItemTypes = query.ExcludeItemTypes.ToList();
var includeItemTypes = (query.IncludeItemTypes ?? new string[] { }).ToList();

Expand Down Expand Up @@ -161,8 +159,15 @@ private Task<IEnumerable<SearchHintInfo>> GetSearchHints(SearchQuery query, User

AddIfMissing(excludeItemTypes, typeof(CollectionFolder).Name);
AddIfMissing(excludeItemTypes, typeof(Folder).Name);
var mediaTypes = query.MediaTypes.ToList();

if (includeItemTypes.Count > 0)
{
excludeItemTypes.Clear();
mediaTypes.Clear();
}

var mediaItems = _libraryManager.GetItemList(new InternalItemsQuery(user)
var searchQuery = new InternalItemsQuery(user)
{
NameContains = searchTerm,
ExcludeItemTypes = excludeItemTypes.ToArray(excludeItemTypes.Count),
Expand All @@ -178,7 +183,7 @@ private Task<IEnumerable<SearchHintInfo>> GetSearchHints(SearchQuery query, User
IsNews = query.IsNews,
IsSeries = query.IsSeries,
IsSports = query.IsSports,
MediaTypes = query.MediaTypes,
MediaTypes = mediaTypes.ToArray(),

DtoOptions = new DtoOptions
{
Expand All @@ -189,17 +194,33 @@ private Task<IEnumerable<SearchHintInfo>> GetSearchHints(SearchQuery query, User
ItemFields.ChannelInfo
}
}
});
};

List<BaseItem> mediaItems;

if (searchQuery.IncludeItemTypes.Length == 1 && string.Equals(searchQuery.IncludeItemTypes[0], "MusicArtist", StringComparison.OrdinalIgnoreCase))
{
if (searchQuery.ParentId.HasValue)
{
searchQuery.AncestorIds = new string[] { searchQuery.ParentId.Value.ToString("N") };
}
searchQuery.ParentId = null;
searchQuery.IncludeItemsByName = true;
searchQuery.IncludeItemTypes = new string[] { };
mediaItems = _libraryManager.GetArtists(searchQuery).Items.Select(i => i.Item1).ToList();
}
else
{
mediaItems = _libraryManager.GetItemList(searchQuery);
}

// Add search hints based on item name
hints.AddRange(mediaItems.Select(item =>
var returnValue = mediaItems.Select(item =>
{
var index = GetIndex(item.Name, searchTerm, terms);

return new Tuple<BaseItem, string, int>(item, index.Item1, index.Item2);
}));

var returnValue = hints.Where(i => i.Item3 >= 0).OrderBy(i => i.Item3).ThenBy(i => i.Item1.SortName).Select(i => new SearchHintInfo
}).OrderBy(i => i.Item3).ThenBy(i => i.Item1.SortName).Select(i => new SearchHintInfo
{
Item = i.Item1,
MatchedTerm = i.Item2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public LiveStream(MediaSourceInfo mediaSource, IEnvironmentInfo environment, IFi
EnableStreamSharing = true;
SharedStreamIds = new List<string>();
UniqueId = Guid.NewGuid().ToString("N");
TempFilePath = Path.Combine(appPaths.TranscodingTempPath, UniqueId + ".ts");
TempFilePath = Path.Combine(appPaths.GetTranscodingTempPath(), UniqueId + ".ts");
}

public virtual Task Open(CancellationToken openCancellationToken)
Expand Down
7 changes: 1 addition & 6 deletions Emby.Server.Implementations/Localization/Core/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,5 @@
"User": "User",
"System": "System",
"Application": "Application",
"Plugin": "Plugin",
"LabelExit": "Exit",
"LabelVisitCommunity": "Visit Community",
"LabelBrowseLibrary": "Browse Library",
"LabelConfigureServer": "Configure Emby",
"LabelRestartServer": "Restart Server"
"Plugin": "Plugin"
}
Loading

0 comments on commit 1fe5913

Please sign in to comment.