2014-07-26 17:30:15 +00:00
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-06-30 03:04:50 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
2014-07-12 19:05:35 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2015-10-04 04:23:11 +00:00
|
|
|
|
using CommonIO;
|
2014-02-04 20:19:29 +00:00
|
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
|
namespace MediaBrowser.LocalMetadata.Images
|
2014-02-04 20:19:29 +00:00
|
|
|
|
{
|
2015-04-11 01:42:37 +00:00
|
|
|
|
public class EpisodeLocalLocalImageProvider : ILocalImageFileProvider, IHasOrder
|
2014-02-04 20:19:29 +00:00
|
|
|
|
{
|
2014-07-26 17:30:15 +00:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
|
|
|
|
|
|
public EpisodeLocalLocalImageProvider(IFileSystem fileSystem)
|
|
|
|
|
{
|
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 20:19:29 +00:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Local Images"; }
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-11 01:42:37 +00:00
|
|
|
|
public int Order
|
|
|
|
|
{
|
|
|
|
|
get { return 0; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 20:19:29 +00:00
|
|
|
|
public bool Supports(IHasImages item)
|
|
|
|
|
{
|
2014-02-10 20:11:46 +00:00
|
|
|
|
return item is Episode && item.SupportsLocalMetadata;
|
2014-02-04 20:19:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-10 18:39:41 +00:00
|
|
|
|
public List<LocalImageInfo> GetImages(IHasImages item, IDirectoryService directoryService)
|
2014-02-08 20:02:35 +00:00
|
|
|
|
{
|
2014-02-08 22:38:02 +00:00
|
|
|
|
var parentPath = Path.GetDirectoryName(item.Path);
|
|
|
|
|
|
2014-10-25 18:32:58 +00:00
|
|
|
|
var parentPathFiles = directoryService.GetFileSystemEntries(parentPath)
|
|
|
|
|
.ToList();
|
2014-02-08 22:38:02 +00:00
|
|
|
|
|
2014-07-26 17:30:15 +00:00
|
|
|
|
var nameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(item.Path);
|
2014-02-08 22:38:02 +00:00
|
|
|
|
|
|
|
|
|
var files = GetFilesFromParentFolder(nameWithoutExtension, parentPathFiles);
|
|
|
|
|
|
|
|
|
|
if (files.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
return files;
|
|
|
|
|
}
|
2014-02-08 20:02:35 +00:00
|
|
|
|
|
2014-02-08 22:38:02 +00:00
|
|
|
|
var metadataPath = Path.Combine(parentPath, "metadata");
|
2014-02-08 20:02:35 +00:00
|
|
|
|
|
2014-02-08 22:38:02 +00:00
|
|
|
|
if (parentPathFiles.Any(i => string.Equals(i.FullName, metadataPath, StringComparison.OrdinalIgnoreCase)))
|
2014-02-08 20:02:35 +00:00
|
|
|
|
{
|
2014-02-08 22:38:02 +00:00
|
|
|
|
return GetFilesFromParentFolder(nameWithoutExtension, directoryService.GetFiles(metadataPath));
|
2014-02-08 20:02:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-08 22:38:02 +00:00
|
|
|
|
return new List<LocalImageInfo>();
|
2014-02-08 20:02:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-04 03:38:46 +00:00
|
|
|
|
private List<LocalImageInfo> GetFilesFromParentFolder(string filenameWithoutExtension, IEnumerable<FileSystemMetadata> parentPathFiles)
|
2014-02-04 20:19:29 +00:00
|
|
|
|
{
|
2014-02-08 22:38:02 +00:00
|
|
|
|
var thumbName = filenameWithoutExtension + "-thumb";
|
2014-02-04 20:19:29 +00:00
|
|
|
|
|
2014-02-08 22:38:02 +00:00
|
|
|
|
return parentPathFiles
|
|
|
|
|
.Where(i =>
|
|
|
|
|
{
|
2014-07-12 19:05:35 +00:00
|
|
|
|
if ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (BaseItem.SupportedImageExtensions.Contains(i.Extension, StringComparer.OrdinalIgnoreCase))
|
2014-02-08 22:38:02 +00:00
|
|
|
|
{
|
2014-07-26 17:30:15 +00:00
|
|
|
|
var currentNameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(i);
|
2014-02-04 20:19:29 +00:00
|
|
|
|
|
2014-02-08 22:38:02 +00:00
|
|
|
|
if (string.Equals(filenameWithoutExtension, currentNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-02-08 20:02:35 +00:00
|
|
|
|
|
2014-02-08 22:38:02 +00:00
|
|
|
|
if (string.Equals(thumbName, currentNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-08 20:02:35 +00:00
|
|
|
|
|
2014-02-08 22:38:02 +00:00
|
|
|
|
return false;
|
|
|
|
|
})
|
|
|
|
|
.Select(i => new LocalImageInfo
|
|
|
|
|
{
|
2015-10-04 03:38:46 +00:00
|
|
|
|
FileInfo = i,
|
2014-02-08 22:38:02 +00:00
|
|
|
|
Type = ImageType.Primary
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
2014-02-04 20:19:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|