diff options
| author | Stephen <snazy2000@btinternet.com> | 2014-06-30 06:20:24 +0100 |
|---|---|---|
| committer | Stephen <snazy2000@btinternet.com> | 2014-06-30 06:20:24 +0100 |
| commit | 2a9e4778124de3103bd4a50f806a3694b57d3c6a (patch) | |
| tree | 0275788f3b9706b26441edf48a0b4975cc02ee5d /MediaBrowser.LocalMetadata/Images/EpisodeLocalImageProvider.cs | |
| parent | 608ebf4829e7e394170bb2dec8a33c83600e9c08 (diff) | |
| parent | 62d98551edf421ba50f2eadf95d6c3d1fb1d20ae (diff) | |
Merge pull request #1 from MediaBrowser/master
update
Diffstat (limited to 'MediaBrowser.LocalMetadata/Images/EpisodeLocalImageProvider.cs')
| -rw-r--r-- | MediaBrowser.LocalMetadata/Images/EpisodeLocalImageProvider.cs | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/MediaBrowser.LocalMetadata/Images/EpisodeLocalImageProvider.cs b/MediaBrowser.LocalMetadata/Images/EpisodeLocalImageProvider.cs new file mode 100644 index 0000000000..f1e7426aad --- /dev/null +++ b/MediaBrowser.LocalMetadata/Images/EpisodeLocalImageProvider.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Entities; + +namespace MediaBrowser.LocalMetadata.Images +{ + public class EpisodeLocalLocalImageProvider : ILocalImageFileProvider + { + public string Name + { + get { return "Local Images"; } + } + + public bool Supports(IHasImages item) + { + return item is Episode && item.SupportsLocalMetadata; + } + + 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 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(); + } + } +} |
