mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
commit
ed9727e320
@ -5,15 +5,19 @@ using MediaBrowser.Model.Entities;
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using CommonIO;
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
||||||
{
|
{
|
||||||
public class PhotoResolver : ItemResolver<Photo>
|
public class PhotoResolver : ItemResolver<Photo>
|
||||||
{
|
{
|
||||||
private readonly IImageProcessor _imageProcessor;
|
private readonly IImageProcessor _imageProcessor;
|
||||||
public PhotoResolver(IImageProcessor imageProcessor)
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
|
||||||
|
public PhotoResolver(IImageProcessor imageProcessor, ILibraryManager libraryManager)
|
||||||
{
|
{
|
||||||
_imageProcessor = imageProcessor;
|
_imageProcessor = imageProcessor;
|
||||||
|
_libraryManager = libraryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -23,20 +27,45 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
|||||||
/// <returns>Trailer.</returns>
|
/// <returns>Trailer.</returns>
|
||||||
protected override Photo Resolve(ItemResolveArgs args)
|
protected override Photo Resolve(ItemResolveArgs args)
|
||||||
{
|
{
|
||||||
// Must be an image file within a photo collection
|
if (!args.IsDirectory)
|
||||||
if (string.Equals(args.GetCollectionType(), CollectionType.Photos, StringComparison.OrdinalIgnoreCase) &&
|
|
||||||
!args.IsDirectory &&
|
|
||||||
IsImageFile(args.Path, _imageProcessor))
|
|
||||||
{
|
{
|
||||||
|
// Must be an image file within a photo collection
|
||||||
|
var collectionType = args.GetCollectionType();
|
||||||
|
|
||||||
|
if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
if (IsImageFile(args.Path, _imageProcessor))
|
||||||
|
{
|
||||||
|
var filename = Path.GetFileNameWithoutExtension(args.Path);
|
||||||
|
|
||||||
|
// Make sure the image doesn't belong to a video file
|
||||||
|
if (args.DirectoryService.GetFiles(Path.GetDirectoryName(args.Path)).Any(i => IsOwnedByMedia(i, filename)))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return new Photo
|
return new Photo
|
||||||
{
|
{
|
||||||
Path = args.Path
|
Path = args.Path
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsOwnedByMedia(FileSystemMetadata file, string imageFilename)
|
||||||
|
{
|
||||||
|
if (_libraryManager.IsVideoFile(file.FullName) && imageFilename.StartsWith(Path.GetFileNameWithoutExtension(file.Name), StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly string[] IgnoreFiles =
|
private static readonly string[] IgnoreFiles =
|
||||||
{
|
{
|
||||||
"folder",
|
"folder",
|
||||||
@ -44,7 +73,8 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
|||||||
"landscape",
|
"landscape",
|
||||||
"fanart",
|
"fanart",
|
||||||
"backdrop",
|
"backdrop",
|
||||||
"poster"
|
"poster",
|
||||||
|
"cover"
|
||||||
};
|
};
|
||||||
|
|
||||||
internal static bool IsImageFile(string path, IImageProcessor imageProcessor)
|
internal static bool IsImageFile(string path, IImageProcessor imageProcessor)
|
||||||
|
@ -154,7 +154,6 @@ namespace MediaBrowser.Server.Implementations.TV
|
|||||||
SortOrder = SortOrder.Descending,
|
SortOrder = SortOrder.Descending,
|
||||||
IsPlayed = true,
|
IsPlayed = true,
|
||||||
Limit = 1,
|
Limit = 1,
|
||||||
IsVirtualItem = false,
|
|
||||||
ParentIndexNumberNotEquals = 0
|
ParentIndexNumberNotEquals = 0
|
||||||
|
|
||||||
}).FirstOrDefault();
|
}).FirstOrDefault();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user