aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Entities/BaseItem.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-10-22 15:03:21 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-10-22 15:03:21 -0400
commit32cb872b06830b07d27c52ecad9695c669783730 (patch)
tree0c776cfa04ecd8cc6d0f726b7359caeeccba1f11 /MediaBrowser.Controller/Entities/BaseItem.cs
parent96fd6459b2c01c535ae5d0090861f838d45c5c47 (diff)
support backdrops from multiple sources
Diffstat (limited to 'MediaBrowser.Controller/Entities/BaseItem.cs')
-rw-r--r--MediaBrowser.Controller/Entities/BaseItem.cs128
1 files changed, 108 insertions, 20 deletions
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs
index 3459c25976..6832ca7141 100644
--- a/MediaBrowser.Controller/Entities/BaseItem.cs
+++ b/MediaBrowser.Controller/Entities/BaseItem.cs
@@ -47,6 +47,7 @@ namespace MediaBrowser.Controller.Entities
LockedFields = new List<MetadataFields>();
Taglines = new List<string>();
RemoteTrailers = new List<MediaUrl>();
+ ImageSources = new List<ImageSourceInfo>();
}
/// <summary>
@@ -234,23 +235,6 @@ namespace MediaBrowser.Controller.Entities
public List<MetadataFields> LockedFields { get; set; }
/// <summary>
- /// Determines whether the item has a saved local image of the specified name (jpg or png).
- /// </summary>
- /// <param name="name">The name.</param>
- /// <returns><c>true</c> if [has local image] [the specified item]; otherwise, <c>false</c>.</returns>
- /// <exception cref="System.ArgumentNullException">name</exception>
- public bool HasLocalImage(string name)
- {
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentNullException("name");
- }
-
- return ResolveArgs.ContainsMetaFileByName(name + ".jpg") ||
- ResolveArgs.ContainsMetaFileByName(name + ".png");
- }
-
- /// <summary>
/// Should be overridden to return the proper folder where metadata lives
/// </summary>
/// <value>The meta location.</value>
@@ -537,6 +521,12 @@ namespace MediaBrowser.Controller.Entities
public List<string> BackdropImagePaths { get; set; }
/// <summary>
+ /// Gets or sets the backdrop image sources.
+ /// </summary>
+ /// <value>The backdrop image sources.</value>
+ public List<ImageSourceInfo> ImageSources { get; set; }
+
+ /// <summary>
/// Gets or sets the screenshot image paths.
/// </summary>
/// <value>The screenshot image paths.</value>
@@ -1508,8 +1498,10 @@ namespace MediaBrowser.Controller.Entities
BackdropImagePaths.Remove(file);
+ RemoveImageSourceForPath(file);
+
// Delete the source file
- File.Delete(file);
+ DeleteImagePath(file);
}
else if (type == ImageType.Screenshot)
{
@@ -1523,12 +1515,12 @@ namespace MediaBrowser.Controller.Entities
ScreenshotImagePaths.Remove(file);
// Delete the source file
- File.Delete(file);
+ DeleteImagePath(file);
}
else
{
// Delete the source file
- File.Delete(GetImage(type));
+ DeleteImagePath(GetImage(type));
// Remove it from the item
SetImage(type, null);
@@ -1539,6 +1531,26 @@ namespace MediaBrowser.Controller.Entities
}
/// <summary>
+ /// Deletes the image path.
+ /// </summary>
+ /// <param name="path">The path.</param>
+ private void DeleteImagePath(string path)
+ {
+ var currentFile = new FileInfo(path);
+
+ // This will fail if the file is hidden
+ if (currentFile.Exists)
+ {
+ if ((currentFile.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
+ {
+ currentFile.Attributes &= ~FileAttributes.Hidden;
+ }
+
+ currentFile.Delete();
+ }
+ }
+
+ /// <summary>
/// Validates that images within the item are still on the file system
/// </summary>
public void ValidateImages()
@@ -1570,7 +1582,83 @@ namespace MediaBrowser.Controller.Entities
foreach (var path in deletedImages)
{
BackdropImagePaths.Remove(path);
+
+ RemoveImageSourceForPath(path);
+ }
+ }
+
+ /// <summary>
+ /// Adds the image source.
+ /// </summary>
+ /// <param name="path">The path.</param>
+ /// <param name="url">The URL.</param>
+ public void AddImageSource(string path, string url)
+ {
+ RemoveImageSourceForPath(path);
+
+ var pathMd5 = path.ToLower().GetMD5();
+
+ ImageSources.Add(new ImageSourceInfo
+ {
+ ImagePathMD5 = pathMd5,
+ ImageUrlMD5 = url.ToLower().GetMD5()
+ });
+ }
+
+ /// <summary>
+ /// Gets the image source info.
+ /// </summary>
+ /// <param name="path">The path.</param>
+ /// <returns>ImageSourceInfo.</returns>
+ public ImageSourceInfo GetImageSourceInfo(string path)
+ {
+ if (ImageSources.Count == 0)
+ {
+ return null;
+ }
+
+ var pathMd5 = path.ToLower().GetMD5();
+
+ return ImageSources.FirstOrDefault(i => i.ImagePathMD5 == pathMd5);
+ }
+
+ /// <summary>
+ /// Removes the image source for path.
+ /// </summary>
+ /// <param name="path">The path.</param>
+ public void RemoveImageSourceForPath(string path)
+ {
+ if (ImageSources.Count == 0)
+ {
+ return;
}
+
+ var pathMd5 = path.ToLower().GetMD5();
+
+ // Remove existing
+ foreach (var entry in ImageSources
+ .Where(i => i.ImagePathMD5 == pathMd5)
+ .ToList())
+ {
+ ImageSources.Remove(entry);
+ }
+ }
+
+ /// <summary>
+ /// Determines whether [contains image with source URL] [the specified URL].
+ /// </summary>
+ /// <param name="url">The URL.</param>
+ /// <returns><c>true</c> if [contains image with source URL] [the specified URL]; otherwise, <c>false</c>.</returns>
+ public bool ContainsImageWithSourceUrl(string url)
+ {
+ if (ImageSources.Count == 0)
+ {
+ return false;
+ }
+
+ var md5 = url.ToLower().GetMD5();
+
+ return ImageSources.Any(i => i.ImageUrlMD5 == md5);
}
/// <summary>