rework image providers
This commit is contained in:
parent
17f5ae8118
commit
0abe0685f5
|
@ -44,7 +44,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
/// <summary>
|
||||
/// The supported image extensions
|
||||
/// </summary>
|
||||
public static readonly string[] SupportedImageExtensions = { ".png", ".jpg", ".jpeg", ".tbn" };
|
||||
public static readonly string[] SupportedImageExtensions = { ".png", ".jpg", ".jpeg" };
|
||||
|
||||
public static readonly List<string> SupportedImageExtensionsList = SupportedImageExtensions.ToList();
|
||||
|
||||
|
@ -1532,7 +1532,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
}
|
||||
|
||||
// Remove it from the item
|
||||
ImageInfos.Remove(info);
|
||||
RemoveImage(info);
|
||||
|
||||
// Delete the source file
|
||||
var currentFile = new FileInfo(info.Path);
|
||||
|
@ -1551,6 +1551,11 @@ namespace MediaBrowser.Controller.Entities
|
|||
return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
|
||||
}
|
||||
|
||||
public void RemoveImage(ItemImageInfo image)
|
||||
{
|
||||
ImageInfos.Remove(image);
|
||||
}
|
||||
|
||||
public virtual Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken)
|
||||
{
|
||||
return LibraryManager.UpdateItem(this, updateReason, cancellationToken);
|
||||
|
@ -1641,9 +1646,9 @@ namespace MediaBrowser.Controller.Entities
|
|||
return ImageInfos.Where(i => i.Type == imageType);
|
||||
}
|
||||
|
||||
public bool AddImages(ImageType imageType, IEnumerable<FileInfo> images)
|
||||
public bool AddImages(ImageType imageType, List<FileInfo> images)
|
||||
{
|
||||
return AddImages(imageType, images.Cast<FileSystemInfo>());
|
||||
return AddImages(imageType, images.Cast<FileSystemInfo>().ToList());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1653,7 +1658,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
/// <param name="images">The images.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||||
/// <exception cref="System.ArgumentException">Cannot call AddImages with chapter images</exception>
|
||||
public bool AddImages(ImageType imageType, IEnumerable<FileSystemInfo> images)
|
||||
public bool AddImages(ImageType imageType, List<FileSystemInfo> images)
|
||||
{
|
||||
if (imageType == ImageType.Chapter)
|
||||
{
|
||||
|
@ -1664,6 +1669,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
.ToList();
|
||||
|
||||
var newImageList = new List<FileSystemInfo>();
|
||||
var imageAdded = false;
|
||||
|
||||
foreach (var newImage in images)
|
||||
{
|
||||
|
@ -1678,6 +1684,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
if (existing == null)
|
||||
{
|
||||
newImageList.Add(newImage);
|
||||
imageAdded = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1686,6 +1693,17 @@ namespace MediaBrowser.Controller.Entities
|
|||
}
|
||||
}
|
||||
|
||||
if (imageAdded || images.Count != existingImages.Count)
|
||||
{
|
||||
var newImagePaths = images.Select(i => i.FullName).ToList();
|
||||
|
||||
var deleted = existingImages
|
||||
.Where(i => !newImagePaths.Contains(i.Path, StringComparer.OrdinalIgnoreCase) && !File.Exists(i.Path))
|
||||
.ToList();
|
||||
|
||||
ImageInfos = ImageInfos.Except(deleted).ToList();
|
||||
}
|
||||
|
||||
ImageInfos.AddRange(newImageList.Select(i => GetImageInfo(i, imageType)));
|
||||
|
||||
return newImageList.Count > 0;
|
||||
|
|
|
@ -141,7 +141,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
/// <param name="imageType">Type of the image.</param>
|
||||
/// <param name="images">The images.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||||
bool AddImages(ImageType imageType, IEnumerable<FileSystemInfo> images);
|
||||
bool AddImages(ImageType imageType, List<FileSystemInfo> images);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether [is save local metadata enabled].
|
||||
|
@ -190,6 +190,12 @@ namespace MediaBrowser.Controller.Entities
|
|||
/// </summary>
|
||||
/// <returns><c>true</c> if [is internet metadata enabled]; otherwise, <c>false</c>.</returns>
|
||||
bool IsInternetMetadataEnabled();
|
||||
|
||||
/// <summary>
|
||||
/// Removes the image.
|
||||
/// </summary>
|
||||
/// <param name="image">The image.</param>
|
||||
void RemoveImage(ItemImageInfo image);
|
||||
}
|
||||
|
||||
public static class HasImagesExtensions
|
||||
|
|
|
@ -10,7 +10,7 @@ using System.Linq;
|
|||
|
||||
namespace MediaBrowser.LocalMetadata.Images
|
||||
{
|
||||
public class EpisodeLocalLocalImageProvider : ILocalImageFileProvider
|
||||
public class EpisodeLocalLocalImageProvider : ILocalImageFileProvider, IHasOrder
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
||||
|
@ -24,6 +24,11 @@ namespace MediaBrowser.LocalMetadata.Images
|
|||
get { return "Local Images"; }
|
||||
}
|
||||
|
||||
public int Order
|
||||
{
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
public bool Supports(IHasImages item)
|
||||
{
|
||||
return item is Episode && item.SupportsLocalMetadata;
|
||||
|
|
|
@ -26,6 +26,11 @@ namespace MediaBrowser.LocalMetadata.Images
|
|||
|
||||
public bool Supports(IHasImages item)
|
||||
{
|
||||
if (item is Photo)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!item.IsSaveLocalMetadataEnabled())
|
||||
{
|
||||
return true;
|
||||
|
|
|
@ -12,7 +12,7 @@ using System.Linq;
|
|||
|
||||
namespace MediaBrowser.LocalMetadata.Images
|
||||
{
|
||||
public class LocalImageProvider : ILocalImageFileProvider
|
||||
public class LocalImageProvider : ILocalImageFileProvider, IHasOrder
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
||||
|
|
|
@ -36,16 +36,15 @@ namespace MediaBrowser.Providers.Manager
|
|||
|
||||
public bool ValidateImages(IHasImages item, IEnumerable<IImageProvider> providers, IDirectoryService directoryService)
|
||||
{
|
||||
var hasChanges = item.ValidateImages(directoryService);
|
||||
var hasChanges = false;
|
||||
|
||||
foreach (var provider in providers.OfType<ILocalImageFileProvider>())
|
||||
var images = providers.OfType<ILocalImageFileProvider>()
|
||||
.SelectMany(i => i.GetImages(item, directoryService))
|
||||
.ToList();
|
||||
|
||||
if (MergeImages(item, images))
|
||||
{
|
||||
var images = provider.GetImages(item, directoryService);
|
||||
|
||||
if (MergeImages(item, images))
|
||||
{
|
||||
hasChanges = true;
|
||||
}
|
||||
hasChanges = true;
|
||||
}
|
||||
|
||||
return hasChanges;
|
||||
|
@ -377,8 +376,7 @@ namespace MediaBrowser.Providers.Manager
|
|||
item.SetImagePath(type, image.FileInfo);
|
||||
changed = true;
|
||||
}
|
||||
else if (!string.Equals(currentImage.Path, image.FileInfo.FullName,
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
else if (!string.Equals(currentImage.Path, image.FileInfo.FullName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
item.SetImagePath(type, image.FileInfo);
|
||||
changed = true;
|
||||
|
@ -389,6 +387,15 @@ namespace MediaBrowser.Providers.Manager
|
|||
currentImage.Length = ((FileInfo) image.FileInfo).Length;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var existing = item.GetImageInfo(type, 0);
|
||||
if (existing != null && !File.Exists(existing.Path))
|
||||
{
|
||||
item.RemoveImage(existing);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (UpdateMultiImages(item, images, ImageType.Backdrop))
|
||||
|
@ -412,16 +419,16 @@ namespace MediaBrowser.Providers.Manager
|
|||
{
|
||||
var changed = false;
|
||||
|
||||
var backdrops = images.Where(i => i.Type == type).ToList();
|
||||
if (backdrops.Count > 0)
|
||||
var newImages = images.Where(i => i.Type == type).ToList();
|
||||
if (newImages.Count > 0)
|
||||
{
|
||||
var foundImages = images.Where(i => i.Type == type)
|
||||
var newImageFileInfos = images.Where(i => i.Type == type)
|
||||
.Select(i => i.FileInfo)
|
||||
.ToList();
|
||||
|
||||
if (foundImages.Count > 0)
|
||||
if (newImageFileInfos.Count > 0)
|
||||
{
|
||||
if (item.AddImages(type, foundImages))
|
||||
if (item.AddImages(type, newImageFileInfos))
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user