mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-04 14:58:36 +01:00
added IHasImages and IHasUserData
This commit is contained in:
@@ -22,7 +22,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// <summary>
|
||||
/// Class BaseItem
|
||||
/// </summary>
|
||||
public abstract class BaseItem : IHasProviderIds, ILibraryItem
|
||||
public abstract class BaseItem : IHasProviderIds, ILibraryItem, IHasImages, IHasUserData
|
||||
{
|
||||
protected BaseItem()
|
||||
{
|
||||
@@ -132,8 +132,8 @@ namespace MediaBrowser.Controller.Entities
|
||||
[IgnoreDataMember]
|
||||
public string PrimaryImagePath
|
||||
{
|
||||
get { return GetImage(ImageType.Primary); }
|
||||
set { SetImage(ImageType.Primary, value); }
|
||||
get { return this.GetImagePath(ImageType.Primary); }
|
||||
set { this.SetImagePath(ImageType.Primary, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1310,31 +1310,10 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// Gets an image
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
/// <exception cref="System.ArgumentException">Backdrops should be accessed using Item.Backdrops</exception>
|
||||
public string GetImage(ImageType type)
|
||||
{
|
||||
if (type == ImageType.Backdrop)
|
||||
{
|
||||
throw new ArgumentException("Backdrops should be accessed using Item.Backdrops");
|
||||
}
|
||||
if (type == ImageType.Screenshot)
|
||||
{
|
||||
throw new ArgumentException("Screenshots should be accessed using Item.Screenshots");
|
||||
}
|
||||
|
||||
string val;
|
||||
Images.TryGetValue(type, out val);
|
||||
return val;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an image
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <param name="imageIndex">Index of the image.</param>
|
||||
/// <returns><c>true</c> if the specified type has image; otherwise, <c>false</c>.</returns>
|
||||
/// <exception cref="System.ArgumentException">Backdrops should be accessed using Item.Backdrops</exception>
|
||||
public bool HasImage(ImageType type)
|
||||
public bool HasImage(ImageType type, int imageIndex)
|
||||
{
|
||||
if (type == ImageType.Backdrop)
|
||||
{
|
||||
@@ -1345,16 +1324,10 @@ namespace MediaBrowser.Controller.Entities
|
||||
throw new ArgumentException("Screenshots should be accessed using Item.Screenshots");
|
||||
}
|
||||
|
||||
return !string.IsNullOrEmpty(GetImage(type));
|
||||
return !string.IsNullOrEmpty(this.GetImagePath(type));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets an image
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <exception cref="System.ArgumentException">Backdrops should be accessed using Item.Backdrops</exception>
|
||||
public void SetImage(ImageType type, string path)
|
||||
public void SetImagePath(ImageType type, int index, string path)
|
||||
{
|
||||
if (type == ImageType.Backdrop)
|
||||
{
|
||||
@@ -1423,10 +1396,10 @@ namespace MediaBrowser.Controller.Entities
|
||||
else
|
||||
{
|
||||
// Delete the source file
|
||||
DeleteImagePath(GetImage(type));
|
||||
DeleteImagePath(this.GetImagePath(type));
|
||||
|
||||
// Remove it from the item
|
||||
SetImage(type, null);
|
||||
this.SetImagePath(type, null);
|
||||
}
|
||||
|
||||
// Refresh metadata
|
||||
@@ -1597,13 +1570,13 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
if (imageType == ImageType.Backdrop)
|
||||
{
|
||||
return BackdropImagePaths[imageIndex];
|
||||
return BackdropImagePaths.Count > imageIndex ? BackdropImagePaths[imageIndex] : null;
|
||||
}
|
||||
|
||||
if (imageType == ImageType.Screenshot)
|
||||
{
|
||||
var hasScreenshots = (IHasScreenshots)this;
|
||||
return hasScreenshots.ScreenshotImagePaths[imageIndex];
|
||||
return hasScreenshots.ScreenshotImagePaths.Count > imageIndex ? hasScreenshots.ScreenshotImagePaths[imageIndex] : null;
|
||||
}
|
||||
|
||||
if (imageType == ImageType.Chapter)
|
||||
@@ -1611,7 +1584,9 @@ namespace MediaBrowser.Controller.Entities
|
||||
return ItemRepository.GetChapter(Id, imageIndex).ImagePath;
|
||||
}
|
||||
|
||||
return GetImage(imageType);
|
||||
string val;
|
||||
Images.TryGetValue(imageType, out val);
|
||||
return val;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1658,5 +1633,21 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
return new[] { Path };
|
||||
}
|
||||
|
||||
public Task SwapImages(ImageType type, int index1, int index2)
|
||||
{
|
||||
if (type != ImageType.Screenshot && type != ImageType.Backdrop)
|
||||
{
|
||||
throw new ArgumentException("The change index operation is only applicable to backdrops and screenshots");
|
||||
}
|
||||
|
||||
var file1 = GetImagePath(type, index1);
|
||||
var file2 = GetImagePath(type, index2);
|
||||
|
||||
FileSystem.SwapFiles(file1, file2);
|
||||
|
||||
// Directory watchers should repeat this, but do a quick refresh first
|
||||
return RefreshMetadata(CancellationToken.None, forceSave: true, allowSlowProviders: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
97
MediaBrowser.Controller/Entities/IHasImages.cs
Normal file
97
MediaBrowser.Controller/Entities/IHasImages.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
public interface IHasImages
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the name.
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path.
|
||||
/// </summary>
|
||||
/// <value>The path.</value>
|
||||
string Path { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the identifier.
|
||||
/// </summary>
|
||||
/// <value>The identifier.</value>
|
||||
Guid Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the image path.
|
||||
/// </summary>
|
||||
/// <param name="imageType">Type of the image.</param>
|
||||
/// <param name="imageIndex">Index of the image.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
string GetImagePath(ImageType imageType, int imageIndex);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the image date modified.
|
||||
/// </summary>
|
||||
/// <param name="imagePath">The image path.</param>
|
||||
/// <returns>DateTime.</returns>
|
||||
DateTime GetImageDateModified(string imagePath);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the image.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <param name="index">The index.</param>
|
||||
/// <param name="path">The path.</param>
|
||||
void SetImagePath(ImageType type, int index, string path);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified type has image.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <param name="imageIndex">Index of the image.</param>
|
||||
/// <returns><c>true</c> if the specified type has image; otherwise, <c>false</c>.</returns>
|
||||
bool HasImage(ImageType type, int imageIndex);
|
||||
|
||||
/// <summary>
|
||||
/// Swaps the images.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <param name="index1">The index1.</param>
|
||||
/// <param name="index2">The index2.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SwapImages(ImageType type, int index1, int index2);
|
||||
}
|
||||
|
||||
public static class HasImagesExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the image path.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="imageType">Type of the image.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string GetImagePath(this IHasImages item, ImageType imageType)
|
||||
{
|
||||
return item.GetImagePath(imageType, 0);
|
||||
}
|
||||
|
||||
public static bool HasImage(this IHasImages item, ImageType imageType)
|
||||
{
|
||||
return item.HasImage(imageType, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the image path.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="imageType">Type of the image.</param>
|
||||
/// <param name="path">The path.</param>
|
||||
public static void SetImagePath(this IHasImages item, ImageType imageType, string path)
|
||||
{
|
||||
item.SetImagePath(imageType, 0, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
15
MediaBrowser.Controller/Entities/IHasUserData.cs
Normal file
15
MediaBrowser.Controller/Entities/IHasUserData.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface IHasUserData
|
||||
/// </summary>
|
||||
public interface IHasUserData
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the user data key.
|
||||
/// </summary>
|
||||
/// <returns>System.String.</returns>
|
||||
string GetUserDataKey();
|
||||
}
|
||||
}
|
||||
@@ -183,7 +183,9 @@ namespace MediaBrowser.Controller.Entities.TV
|
||||
episodes = episodes.Where(i => !i.IsVirtualUnaired);
|
||||
}
|
||||
|
||||
return LibraryManager.Sort(episodes, user, new[] { ItemSortBy.AiredEpisodeOrder }, SortOrder.Ascending)
|
||||
var sortBy = seasonNumber == 0 ? ItemSortBy.SortName : ItemSortBy.AiredEpisodeOrder;
|
||||
|
||||
return LibraryManager.Sort(episodes, user, new[] { sortBy }, SortOrder.Ascending)
|
||||
.Cast<Episode>();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user