mirror of
https://github.com/jellyfin/jellyfin
synced 2024-09-19 15:52:23 +00:00
PhotoResolver: change how generated images are detected
Backdrops/fanart are generated as (backdrop)|(fanart)[0-9]*.extension Fixes #7830
This commit is contained in:
parent
2bb534d5e3
commit
57891e7639
|
@ -1,5 +1,3 @@
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -25,7 +23,7 @@ namespace Emby.Server.Implementations.Library.Resolvers
|
||||||
private readonly NamingOptions _namingOptions;
|
private readonly NamingOptions _namingOptions;
|
||||||
private readonly IDirectoryService _directoryService;
|
private readonly IDirectoryService _directoryService;
|
||||||
|
|
||||||
private static readonly HashSet<string> _ignoreFiles = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
private static readonly string[] _ignoreFiles = new[]
|
||||||
{
|
{
|
||||||
"folder",
|
"folder",
|
||||||
"thumb",
|
"thumb",
|
||||||
|
@ -56,7 +54,7 @@ namespace Emby.Server.Implementations.Library.Resolvers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="args">The args.</param>
|
/// <param name="args">The args.</param>
|
||||||
/// <returns>Trailer.</returns>
|
/// <returns>Trailer.</returns>
|
||||||
protected override Photo Resolve(ItemResolveArgs args)
|
protected override Photo? Resolve(ItemResolveArgs args)
|
||||||
{
|
{
|
||||||
if (!args.IsDirectory)
|
if (!args.IsDirectory)
|
||||||
{
|
{
|
||||||
|
@ -68,10 +66,11 @@ namespace Emby.Server.Implementations.Library.Resolvers
|
||||||
{
|
{
|
||||||
if (IsImageFile(args.Path, _imageProcessor))
|
if (IsImageFile(args.Path, _imageProcessor))
|
||||||
{
|
{
|
||||||
var filename = Path.GetFileNameWithoutExtension(args.Path);
|
var filename = Path.GetFileNameWithoutExtension(args.Path.AsSpan());
|
||||||
|
|
||||||
// Make sure the image doesn't belong to a video file
|
// Make sure the image doesn't belong to a video file
|
||||||
var files = _directoryService.GetFiles(Path.GetDirectoryName(args.Path));
|
var files = _directoryService.GetFiles(Path.GetDirectoryName(args.Path)
|
||||||
|
?? throw new InvalidOperationException("Path can't be a root directory."));
|
||||||
|
|
||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
{
|
{
|
||||||
|
@ -92,32 +91,32 @@ namespace Emby.Server.Implementations.Library.Resolvers
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool IsOwnedByMedia(NamingOptions namingOptions, string file, string imageFilename)
|
internal static bool IsOwnedByMedia(NamingOptions namingOptions, string file, ReadOnlySpan<char> imageFilename)
|
||||||
{
|
{
|
||||||
return VideoResolver.IsVideoFile(file, namingOptions) && IsOwnedByResolvedMedia(file, imageFilename);
|
return VideoResolver.IsVideoFile(file, namingOptions) && IsOwnedByResolvedMedia(file, imageFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool IsOwnedByResolvedMedia(string file, string imageFilename)
|
internal static bool IsOwnedByResolvedMedia(ReadOnlySpan<char> file, ReadOnlySpan<char> imageFilename)
|
||||||
=> imageFilename.StartsWith(Path.GetFileNameWithoutExtension(file), StringComparison.OrdinalIgnoreCase);
|
=> imageFilename.StartsWith(Path.GetFileNameWithoutExtension(file), StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
internal static bool IsImageFile(string path, IImageProcessor imageProcessor)
|
internal static bool IsImageFile(string path, IImageProcessor imageProcessor)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(path);
|
ArgumentNullException.ThrowIfNull(path);
|
||||||
|
|
||||||
|
var extension = Path.GetExtension(path.AsSpan()).TrimStart('.');
|
||||||
|
if (!imageProcessor.SupportedInputFormats.Contains(extension, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var filename = Path.GetFileNameWithoutExtension(path);
|
var filename = Path.GetFileNameWithoutExtension(path);
|
||||||
|
|
||||||
if (_ignoreFiles.Contains(filename))
|
if (_ignoreFiles.Any(i => filename.StartsWith(i, StringComparison.OrdinalIgnoreCase)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_ignoreFiles.Any(i => filename.IndexOf(i, StringComparison.OrdinalIgnoreCase) != -1))
|
return true;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
string extension = Path.GetExtension(path).TrimStart('.');
|
|
||||||
return imageProcessor.SupportedInputFormats.Contains(extension, StringComparison.OrdinalIgnoreCase);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace MediaBrowser.Controller.Resolvers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="args">The args.</param>
|
/// <param name="args">The args.</param>
|
||||||
/// <returns>BaseItem.</returns>
|
/// <returns>BaseItem.</returns>
|
||||||
BaseItem ResolvePath(ItemResolveArgs args);
|
BaseItem? ResolvePath(ItemResolveArgs args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IMultiItemResolver
|
public interface IMultiItemResolver
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
|
|
||||||
|
@ -23,7 +21,7 @@ namespace MediaBrowser.Controller.Resolvers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="args">The args.</param>
|
/// <param name="args">The args.</param>
|
||||||
/// <returns>`0.</returns>
|
/// <returns>`0.</returns>
|
||||||
protected internal virtual T Resolve(ItemResolveArgs args)
|
protected internal virtual T? Resolve(ItemResolveArgs args)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +40,7 @@ namespace MediaBrowser.Controller.Resolvers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="args">The args.</param>
|
/// <param name="args">The args.</param>
|
||||||
/// <returns>BaseItem.</returns>
|
/// <returns>BaseItem.</returns>
|
||||||
public BaseItem ResolvePath(ItemResolveArgs args)
|
public BaseItem? ResolvePath(ItemResolveArgs args)
|
||||||
{
|
{
|
||||||
var item = Resolve(args);
|
var item = Resolve(args);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue