aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Providers/TV/EpisodeLocalImageProvider.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Providers/TV/EpisodeLocalImageProvider.cs')
-rw-r--r--MediaBrowser.Providers/TV/EpisodeLocalImageProvider.cs84
1 files changed, 53 insertions, 31 deletions
diff --git a/MediaBrowser.Providers/TV/EpisodeLocalImageProvider.cs b/MediaBrowser.Providers/TV/EpisodeLocalImageProvider.cs
index 96e8f3158..1ec0e0f48 100644
--- a/MediaBrowser.Providers/TV/EpisodeLocalImageProvider.cs
+++ b/MediaBrowser.Providers/TV/EpisodeLocalImageProvider.cs
@@ -9,7 +9,7 @@ using System.Linq;
namespace MediaBrowser.Providers.TV
{
- public class EpisodeLocalImageProvider : IImageFileProvider
+ public class EpisodeLocalLocalImageProvider : ILocalImageFileProvider
{
public string Name
{
@@ -18,42 +18,64 @@ namespace MediaBrowser.Providers.TV
public bool Supports(IHasImages item)
{
- return item is Episode && item.LocationType == LocationType.FileSystem;
+ return item is Episode && item.SupportsLocalMetadata;
}
- public List<LocalImageInfo> GetImages(IHasImages item)
+ public List<LocalImageInfo> GetImages(IHasImages item, IDirectoryService directoryService)
{
var parentPath = Path.GetDirectoryName(item.Path);
+ var parentPathFiles = directoryService.GetFileSystemEntries(parentPath);
+
var nameWithoutExtension = Path.GetFileNameWithoutExtension(item.Path);
- var thumbName = nameWithoutExtension + "-thumb";
-
- return Directory.EnumerateFiles(parentPath, "*", SearchOption.AllDirectories)
- .Where(i =>
- {
- if (BaseItem.SupportedImageExtensions.Contains(Path.GetExtension(i) ?? string.Empty))
- {
- var currentNameWithoutExtension = Path.GetFileNameWithoutExtension(i);
-
- if (string.Equals(nameWithoutExtension, currentNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
- {
- return true;
- }
-
- if (string.Equals(thumbName, currentNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
- {
- return true;
- }
- }
-
- return false;
- })
- .Select(i => new LocalImageInfo
- {
- Path = i,
- Type = ImageType.Primary
- })
- .ToList();
+
+ var files = GetFilesFromParentFolder(nameWithoutExtension, parentPathFiles);
+
+ if (files.Count > 0)
+ {
+ return files;
+ }
+
+ var metadataPath = Path.Combine(parentPath, "metadata");
+
+ if (parentPathFiles.Any(i => string.Equals(i.FullName, metadataPath, StringComparison.OrdinalIgnoreCase)))
+ {
+ return GetFilesFromParentFolder(nameWithoutExtension, directoryService.GetFiles(metadataPath));
+ }
+
+ return new List<LocalImageInfo>();
+ }
+
+ private List<LocalImageInfo> GetFilesFromParentFolder(string filenameWithoutExtension, IEnumerable<FileSystemInfo> parentPathFiles)
+ {
+ var thumbName = filenameWithoutExtension + "-thumb";
+
+ return parentPathFiles
+ .Where(i =>
+ {
+ if (BaseItem.SupportedImageExtensions.Contains(i.Extension))
+ {
+ var currentNameWithoutExtension = Path.GetFileNameWithoutExtension(i.Name);
+
+ if (string.Equals(filenameWithoutExtension, currentNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
+ {
+ return true;
+ }
+
+ if (string.Equals(thumbName, currentNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ })
+ .Select(i => new LocalImageInfo
+ {
+ FileInfo = (FileInfo)i,
+ Type = ImageType.Primary
+ })
+ .ToList();
}
}
}