aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Entities/BaseItem.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Controller/Entities/BaseItem.cs')
-rw-r--r--MediaBrowser.Controller/Entities/BaseItem.cs142
1 files changed, 102 insertions, 40 deletions
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs
index 541887598..a02369b2c 100644
--- a/MediaBrowser.Controller/Entities/BaseItem.cs
+++ b/MediaBrowser.Controller/Entities/BaseItem.cs
@@ -7,6 +7,7 @@ using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Resolvers;
+using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System;
@@ -22,7 +23,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 +133,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>
@@ -956,6 +957,66 @@ namespace MediaBrowser.Controller.Entities
}
/// <summary>
+ /// Gets the preferred metadata language.
+ /// </summary>
+ /// <returns>System.String.</returns>
+ public string GetPreferredMetadataLanguage()
+ {
+ string lang = null;
+
+ var hasLang = this as IHasPreferredMetadataLanguage;
+
+ if (hasLang != null)
+ {
+ lang = hasLang.PreferredMetadataLanguage;
+ }
+
+ if (string.IsNullOrEmpty(lang))
+ {
+ lang = Parents.OfType<IHasPreferredMetadataLanguage>()
+ .Select(i => i.PreferredMetadataLanguage)
+ .FirstOrDefault(i => !string.IsNullOrEmpty(i));
+ }
+
+ if (string.IsNullOrEmpty(lang))
+ {
+ lang = ConfigurationManager.Configuration.PreferredMetadataLanguage;
+ }
+
+ return lang;
+ }
+
+ /// <summary>
+ /// Gets the preferred metadata language.
+ /// </summary>
+ /// <returns>System.String.</returns>
+ public string GetPreferredMetadataCountryCode()
+ {
+ string lang = null;
+
+ var hasLang = this as IHasPreferredMetadataLanguage;
+
+ if (hasLang != null)
+ {
+ lang = hasLang.PreferredMetadataCountryCode;
+ }
+
+ if (string.IsNullOrEmpty(lang))
+ {
+ lang = Parents.OfType<IHasPreferredMetadataLanguage>()
+ .Select(i => i.PreferredMetadataCountryCode)
+ .FirstOrDefault(i => !string.IsNullOrEmpty(i));
+ }
+
+ if (string.IsNullOrEmpty(lang))
+ {
+ lang = ConfigurationManager.Configuration.MetadataCountryCode;
+ }
+
+ return lang;
+ }
+
+ /// <summary>
/// Determines if a given user has access to this item
/// </summary>
/// <param name="user">The user.</param>
@@ -985,7 +1046,7 @@ namespace MediaBrowser.Controller.Entities
if (string.IsNullOrEmpty(rating))
{
- return !user.Configuration.BlockNotRated;
+ return !GetBlockUnratedValue(user.Configuration);
}
var value = localizationManager.GetRatingLevel(rating);
@@ -1000,6 +1061,16 @@ namespace MediaBrowser.Controller.Entities
}
/// <summary>
+ /// Gets the block unrated value.
+ /// </summary>
+ /// <param name="config">The configuration.</param>
+ /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
+ protected virtual bool GetBlockUnratedValue(UserConfiguration config)
+ {
+ return config.BlockNotRated;
+ }
+
+ /// <summary>
/// Determines if this folder should be visible to a given user.
/// Default is just parental allowed. Can be overridden for more functionality.
/// </summary>
@@ -1310,31 +1381,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 +1395,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 +1467,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 +1641,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 +1655,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 +1704,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);
+ }
}
}