mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-22 01:54:42 +01:00
support image stubbing
This commit is contained in:
@@ -25,13 +25,6 @@ namespace MediaBrowser.Controller.Drawing
|
||||
/// <value>The image enhancers.</value>
|
||||
IEnumerable<IImageEnhancer> ImageEnhancers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the image.
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <returns>ImageSize.</returns>
|
||||
ImageSize GetImageSize(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the image.
|
||||
/// </summary>
|
||||
|
||||
@@ -1432,6 +1432,23 @@ namespace MediaBrowser.Controller.Entities
|
||||
return GetImageInfo(type, imageIndex) != null;
|
||||
}
|
||||
|
||||
public void SetImage(ItemImageInfo image, int index)
|
||||
{
|
||||
if (image.Type == ImageType.Chapter)
|
||||
{
|
||||
throw new ArgumentException("Cannot set chapter images using SetImagePath");
|
||||
}
|
||||
|
||||
var existingImage = GetImageInfo(image.Type, index);
|
||||
|
||||
if (existingImage != null)
|
||||
{
|
||||
ImageInfos.Remove(existingImage);
|
||||
}
|
||||
|
||||
ImageInfos.Add(image);
|
||||
}
|
||||
|
||||
public void SetImagePath(ImageType type, int index, FileSystemMetadata file)
|
||||
{
|
||||
if (type == ImageType.Chapter)
|
||||
@@ -1473,18 +1490,21 @@ namespace MediaBrowser.Controller.Entities
|
||||
// Remove it from the item
|
||||
RemoveImage(info);
|
||||
|
||||
// Delete the source file
|
||||
var currentFile = new FileInfo(info.Path);
|
||||
|
||||
// Deletion will fail if the file is hidden so remove the attribute first
|
||||
if (currentFile.Exists)
|
||||
if (info.IsLocalFile)
|
||||
{
|
||||
if ((currentFile.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
|
||||
{
|
||||
currentFile.Attributes &= ~FileAttributes.Hidden;
|
||||
}
|
||||
// Delete the source file
|
||||
var currentFile = new FileInfo(info.Path);
|
||||
|
||||
FileSystem.DeleteFile(currentFile.FullName);
|
||||
// Deletion will fail if the file is hidden so remove the attribute first
|
||||
if (currentFile.Exists)
|
||||
{
|
||||
if ((currentFile.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
|
||||
{
|
||||
currentFile.Attributes &= ~FileAttributes.Hidden;
|
||||
}
|
||||
|
||||
FileSystem.DeleteFile(currentFile.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
|
||||
@@ -1505,11 +1525,16 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// </summary>
|
||||
public bool ValidateImages(IDirectoryService directoryService)
|
||||
{
|
||||
var allDirectories = ImageInfos.Select(i => System.IO.Path.GetDirectoryName(i.Path)).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
|
||||
var allFiles = allDirectories.SelectMany(directoryService.GetFiles).Select(i => i.FullName).ToList();
|
||||
var allFiles = ImageInfos
|
||||
.Where(i => i.IsLocalFile)
|
||||
.Select(i => System.IO.Path.GetDirectoryName(i.Path))
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.SelectMany(directoryService.GetFiles)
|
||||
.Select(i => i.FullName)
|
||||
.ToList();
|
||||
|
||||
var deletedImages = ImageInfos
|
||||
.Where(image => !allFiles.Contains(image.Path, StringComparer.OrdinalIgnoreCase))
|
||||
.Where(image => image.IsLocalFile && !allFiles.Contains(image.Path, StringComparer.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
|
||||
if (deletedImages.Count > 0)
|
||||
@@ -1619,7 +1644,10 @@ namespace MediaBrowser.Controller.Entities
|
||||
}
|
||||
else
|
||||
{
|
||||
existing.DateModified = FileSystem.GetLastWriteTimeUtc(newImage);
|
||||
if (existing.IsLocalFile)
|
||||
{
|
||||
existing.DateModified = FileSystem.GetLastWriteTimeUtc(newImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1628,7 +1656,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
var newImagePaths = images.Select(i => i.FullName).ToList();
|
||||
|
||||
var deleted = existingImages
|
||||
.Where(i => !newImagePaths.Contains(i.Path, StringComparer.OrdinalIgnoreCase) && !FileSystem.FileExists(i.Path))
|
||||
.Where(i => i.IsLocalFile && !newImagePaths.Contains(i.Path, StringComparer.OrdinalIgnoreCase) && !FileSystem.FileExists(i.Path))
|
||||
.ToList();
|
||||
|
||||
ImageInfos = ImageInfos.Except(deleted).ToList();
|
||||
@@ -1679,6 +1707,12 @@ namespace MediaBrowser.Controller.Entities
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
if (!info1.IsLocalFile || !info2.IsLocalFile)
|
||||
{
|
||||
// TODO: Not supported yet
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
var path1 = info1.Path;
|
||||
var path2 = info2.Path;
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CommonIO;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Library;
|
||||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
@@ -191,6 +193,21 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// </summary>
|
||||
/// <param name="image">The image.</param>
|
||||
void RemoveImage(ItemImageInfo image);
|
||||
|
||||
/// <summary>
|
||||
/// Updates to repository.
|
||||
/// </summary>
|
||||
/// <param name="updateReason">The update reason.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the image.
|
||||
/// </summary>
|
||||
/// <param name="image">The image.</param>
|
||||
/// <param name="index">The index.</param>
|
||||
void SetImage(ItemImageInfo image, int index);
|
||||
}
|
||||
|
||||
public static class HasImagesExtensions
|
||||
|
||||
@@ -36,14 +36,6 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// <value>The date last refreshed.</value>
|
||||
DateTime DateLastRefreshed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Updates to repository.
|
||||
/// </summary>
|
||||
/// <param name="updateReason">The update reason.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// This is called before any metadata refresh and returns true or false indicating if changes were made
|
||||
/// </summary>
|
||||
|
||||
@@ -29,6 +29,13 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Path != null)
|
||||
{
|
||||
if (Path.StartsWith("http", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,5 +534,14 @@ namespace MediaBrowser.Controller.Library
|
||||
/// <param name="to">To.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
string SubstitutePath(string path, string from, string to);
|
||||
|
||||
/// <summary>
|
||||
/// Converts the image to local.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="image">The image.</param>
|
||||
/// <param name="imageIndex">Index of the image.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task<ItemImageInfo> ConvertImageToLocal(IHasImages item, ItemImageInfo image, int imageIndex);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using MediaBrowser.Model.Drawing;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
|
||||
namespace MediaBrowser.Controller.Providers
|
||||
{
|
||||
public class DynamicImageResponse
|
||||
{
|
||||
public string Path { get; set; }
|
||||
public MediaProtocol Protocol { get; set; }
|
||||
public Stream Stream { get; set; }
|
||||
public ImageFormat Format { get; set; }
|
||||
public bool HasImage { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user