completed multiple movie in folder support

This commit is contained in:
Luke Pulverenti 2013-08-15 15:09:52 -04:00
parent 34bf41721a
commit 11c3778053
8 changed files with 121 additions and 164 deletions

View file

@ -55,6 +55,8 @@ namespace MediaBrowser.Controller.Entities
public const string ThemeVideosFolderName = "backdrops"; public const string ThemeVideosFolderName = "backdrops";
public const string XbmcTrailerFileSuffix = "-trailer"; public const string XbmcTrailerFileSuffix = "-trailer";
public bool IsInMixedFolder { get; set; }
private string _name; private string _name;
/// <summary> /// <summary>
/// Gets or sets the name. /// Gets or sets the name.

View file

@ -24,11 +24,6 @@ namespace MediaBrowser.Controller.Entities
/// <value>The game system.</value> /// <value>The game system.</value>
public string GameSystem { get; set; } public string GameSystem { get; set; }
/// <summary>
/// Returns true if the game is combined with other games in the same folder
/// </summary>
public bool IsInMixedFolder { get; set; }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -36,18 +31,7 @@ namespace MediaBrowser.Controller.Entities
{ {
get get
{ {
var directoryName = System.IO.Path.GetDirectoryName(Path); return System.IO.Path.GetDirectoryName(Path);
if (IsInMixedFolder)
{
// It's a file
var baseMetaPath = System.IO.Path.Combine(directoryName, "metadata");
var fileName = System.IO.Path.GetFileNameWithoutExtension(Path);
return fileName != null ? System.IO.Path.Combine(baseMetaPath, fileName) : null;
}
return directoryName;
} }
} }

View file

@ -65,8 +65,6 @@ namespace MediaBrowser.Controller.Entities
return GetPlayableStreamFiles(Path); return GetPlayableStreamFiles(Path);
} }
public bool IsInMixedFolder { get; set; }
/// <summary> /// <summary>
/// Should be overridden to return the proper folder where metadata lives /// Should be overridden to return the proper folder where metadata lives
/// </summary> /// </summary>

View file

@ -1,5 +1,6 @@
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
@ -38,7 +39,16 @@ namespace MediaBrowser.Providers
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
public override bool Supports(BaseItem item) public override bool Supports(BaseItem item)
{ {
return item.LocationType == LocationType.FileSystem && item.ResolveArgs.IsDirectory; if (item.LocationType == LocationType.FileSystem)
{
if (item.ResolveArgs.IsDirectory)
{
return true;
}
return item.IsInMixedFolder && !(item is Episode);
}
return false;
} }
/// <summary> /// <summary>
@ -85,34 +95,48 @@ namespace MediaBrowser.Providers
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
var args = GetResolveArgsContainingImages(item);
// Make sure current image paths still exist // Make sure current image paths still exist
ValidateImages(item); ValidateImages(item, args);
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
// Make sure current backdrop paths still exist // Make sure current backdrop paths still exist
ValidateBackdrops(item); ValidateBackdrops(item, args);
ValidateScreenshots(item, args);
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
PopulateBaseItemImages(item); PopulateBaseItemImages(item, args);
SetLastRefreshed(item, DateTime.UtcNow); SetLastRefreshed(item, DateTime.UtcNow);
return TrueTaskResult; return TrueTaskResult;
} }
private ItemResolveArgs GetResolveArgsContainingImages(BaseItem item)
{
if (item.IsInMixedFolder)
{
return item.Parent.ResolveArgs;
}
return item.ResolveArgs;
}
/// <summary> /// <summary>
/// Validates that images within the item are still on the file system /// Validates that images within the item are still on the file system
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
private void ValidateImages(BaseItem item) /// <param name="args">The args.</param>
private void ValidateImages(BaseItem item, ItemResolveArgs args)
{ {
// Only validate paths from the same directory - need to copy to a list because we are going to potentially modify the collection below // Only validate paths from the same directory - need to copy to a list because we are going to potentially modify the collection below
var deletedKeys = item.Images.ToList().Where(image => var deletedKeys = item.Images.ToList().Where(image =>
{ {
var path = image.Value; var path = image.Value;
return IsInMetaLocation(item, path) && item.ResolveArgs.GetMetaFileByPath(path) == null; return IsInMetaLocation(item, path) && args.GetMetaFileByPath(path) == null;
}).Select(i => i.Key).ToList(); }).Select(i => i.Key).ToList();
@ -127,15 +151,11 @@ namespace MediaBrowser.Providers
/// Validates that backdrops within the item are still on the file system /// Validates that backdrops within the item are still on the file system
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
private void ValidateBackdrops(BaseItem item) /// <param name="args">The args.</param>
private void ValidateBackdrops(BaseItem item, ItemResolveArgs args)
{ {
if (item.BackdropImagePaths == null)
{
return;
}
// Only validate paths from the same directory - need to copy to a list because we are going to potentially modify the collection below // Only validate paths from the same directory - need to copy to a list because we are going to potentially modify the collection below
var deletedImages = item.BackdropImagePaths.Where(path => IsInMetaLocation(item, path) && item.ResolveArgs.GetMetaFileByPath(path) == null).ToList(); var deletedImages = item.BackdropImagePaths.Where(path => IsInMetaLocation(item, path) && args.GetMetaFileByPath(path) == null).ToList();
// Now remove them from the dictionary // Now remove them from the dictionary
foreach (var path in deletedImages) foreach (var path in deletedImages)
@ -144,6 +164,23 @@ namespace MediaBrowser.Providers
} }
} }
/// <summary>
/// Validates the screenshots.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="args">The args.</param>
private void ValidateScreenshots(BaseItem item, ItemResolveArgs args)
{
// Only validate paths from the same directory - need to copy to a list because we are going to potentially modify the collection below
var deletedImages = item.ScreenshotImagePaths.Where(path => IsInMetaLocation(item, path) && args.GetMetaFileByPath(path) == null).ToList();
// Now remove them from the dictionary
foreach (var path in deletedImages)
{
item.ScreenshotImagePaths.Remove(path);
}
}
/// <summary> /// <summary>
/// Determines whether [is in same directory] [the specified item]. /// Determines whether [is in same directory] [the specified item].
/// </summary> /// </summary>
@ -159,24 +196,48 @@ namespace MediaBrowser.Providers
/// Gets the image. /// Gets the image.
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
/// <param name="args">The args.</param>
/// <param name="filenameWithoutExtension">The filename without extension.</param> /// <param name="filenameWithoutExtension">The filename without extension.</param>
/// <returns>FileSystemInfo.</returns> /// <returns>FileSystemInfo.</returns>
protected virtual FileSystemInfo GetImage(BaseItem item, string filenameWithoutExtension) protected virtual FileSystemInfo GetImage(BaseItem item, ItemResolveArgs args, string filenameWithoutExtension)
{ {
return BaseItem.SupportedImageExtensions.Select(i => item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.ResolveArgs.Path, filenameWithoutExtension + i))).FirstOrDefault(i => i != null); return BaseItem.SupportedImageExtensions
.Select(i => args.GetMetaFileByPath(GetFullImagePath(item, args, filenameWithoutExtension, i)))
.FirstOrDefault(i => i != null);
}
protected virtual string GetFullImagePath(BaseItem item, ItemResolveArgs args, string filenameWithoutExtension, string extension)
{
var path = item.MetaLocation;
if (item.IsInMixedFolder)
{
var pathFilenameWithoutExtension = Path.GetFileNameWithoutExtension(item.Path);
// If the image filename and path file name match, just look for an image using the same full path as the item
if (string.Equals(pathFilenameWithoutExtension, filenameWithoutExtension))
{
return Path.ChangeExtension(item.Path, extension);
}
return Path.Combine(path, pathFilenameWithoutExtension + "-" + filenameWithoutExtension + extension);
}
return Path.Combine(path, filenameWithoutExtension + extension);
} }
/// <summary> /// <summary>
/// Fills in image paths based on files win the folder /// Fills in image paths based on files win the folder
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
private void PopulateBaseItemImages(BaseItem item) /// <param name="args">The args.</param>
private void PopulateBaseItemImages(BaseItem item, ItemResolveArgs args)
{ {
// Primary Image // Primary Image
var image = GetImage(item, "folder") ?? var image = GetImage(item, args, "folder") ??
GetImage(item, "poster") ?? GetImage(item, args, "poster") ??
GetImage(item, "cover") ?? GetImage(item, args, "cover") ??
GetImage(item, "default"); GetImage(item, args, "default");
// Look for a file with the same name as the item // Look for a file with the same name as the item
if (image == null) if (image == null)
@ -185,7 +246,7 @@ namespace MediaBrowser.Providers
if (!string.IsNullOrEmpty(name)) if (!string.IsNullOrEmpty(name))
{ {
image = GetImage(item, name); image = GetImage(item, args, name);
} }
} }
@ -195,7 +256,7 @@ namespace MediaBrowser.Providers
} }
// Logo Image // Logo Image
image = GetImage(item, "logo"); image = GetImage(item, args, "logo");
if (image != null) if (image != null)
{ {
@ -203,7 +264,7 @@ namespace MediaBrowser.Providers
} }
// Banner Image // Banner Image
image = GetImage(item, "banner"); image = GetImage(item, args, "banner");
if (image != null) if (image != null)
{ {
@ -211,7 +272,7 @@ namespace MediaBrowser.Providers
} }
// Clearart // Clearart
image = GetImage(item, "clearart"); image = GetImage(item, args, "clearart");
if (image != null) if (image != null)
{ {
@ -219,7 +280,7 @@ namespace MediaBrowser.Providers
} }
// Disc // Disc
image = GetImage(item, "disc"); image = GetImage(item, args, "disc");
if (image != null) if (image != null)
{ {
@ -227,7 +288,7 @@ namespace MediaBrowser.Providers
} }
// Thumbnail Image // Thumbnail Image
image = GetImage(item, "thumb"); image = GetImage(item, args, "thumb");
if (image != null) if (image != null)
{ {
@ -235,7 +296,7 @@ namespace MediaBrowser.Providers
} }
// Box Image // Box Image
image = GetImage(item, "box"); image = GetImage(item, args, "box");
if (image != null) if (image != null)
{ {
@ -243,7 +304,7 @@ namespace MediaBrowser.Providers
} }
// BoxRear Image // BoxRear Image
image = GetImage(item, "boxrear"); image = GetImage(item, args, "boxrear");
if (image != null) if (image != null)
{ {
@ -251,7 +312,7 @@ namespace MediaBrowser.Providers
} }
// Thumbnail Image // Thumbnail Image
image = GetImage(item, "menu"); image = GetImage(item, args, "menu");
if (image != null) if (image != null)
{ {
@ -259,10 +320,10 @@ namespace MediaBrowser.Providers
} }
// Backdrop Image // Backdrop Image
PopulateBackdrops(item); PopulateBackdrops(item, args);
// Screenshot Image // Screenshot Image
image = GetImage(item, "screenshot"); image = GetImage(item, args, "screenshot");
var screenshotFiles = new List<string>(); var screenshotFiles = new List<string>();
@ -275,7 +336,7 @@ namespace MediaBrowser.Providers
for (var i = 1; i <= 20; i++) for (var i = 1; i <= 20; i++)
{ {
// Screenshot Image // Screenshot Image
image = GetImage(item, "screenshot" + i); image = GetImage(item, args, "screenshot" + i);
if (image != null) if (image != null)
{ {
@ -302,15 +363,16 @@ namespace MediaBrowser.Providers
/// Populates the backdrops. /// Populates the backdrops.
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
private void PopulateBackdrops(BaseItem item) /// <param name="args">The args.</param>
private void PopulateBackdrops(BaseItem item, ItemResolveArgs args)
{ {
var backdropFiles = new List<string>(); var backdropFiles = new List<string>();
PopulateBackdrops(item, backdropFiles, "backdrop", "backdrop"); PopulateBackdrops(item, args, backdropFiles, "backdrop", "backdrop");
// Support plex/xbmc conventions // Support plex/xbmc conventions
PopulateBackdrops(item, backdropFiles, "fanart", "fanart-"); PopulateBackdrops(item, args, backdropFiles, "fanart", "fanart-");
PopulateBackdrops(item, backdropFiles, "background", "background-"); PopulateBackdrops(item, args, backdropFiles, "background", "background-");
if (backdropFiles.Count > 0) if (backdropFiles.Count > 0)
{ {
@ -322,12 +384,13 @@ namespace MediaBrowser.Providers
/// Populates the backdrops. /// Populates the backdrops.
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
/// <param name="args">The args.</param>
/// <param name="backdropFiles">The backdrop files.</param> /// <param name="backdropFiles">The backdrop files.</param>
/// <param name="filename">The filename.</param> /// <param name="filename">The filename.</param>
/// <param name="numberedSuffix">The numbered suffix.</param> /// <param name="numberedSuffix">The numbered suffix.</param>
private void PopulateBackdrops(BaseItem item, List<string> backdropFiles, string filename, string numberedSuffix) private void PopulateBackdrops(BaseItem item, ItemResolveArgs args, List<string> backdropFiles, string filename, string numberedSuffix)
{ {
var image = GetImage(item, filename); var image = GetImage(item, args, filename);
if (image != null) if (image != null)
{ {
@ -338,7 +401,7 @@ namespace MediaBrowser.Providers
for (var i = 1; i <= 20; i++) for (var i = 1; i <= 20; i++)
{ {
// Backdrop Image // Backdrop Image
image = GetImage(item, numberedSuffix + i); image = GetImage(item, args, numberedSuffix + i);
if (image != null) if (image != null)
{ {

View file

@ -1,95 +0,0 @@
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Providers
{
class ImageFromMixedMediaLocationProvider : BaseMetadataProvider
{
public ImageFromMixedMediaLocationProvider(ILogManager logManager, IServerConfigurationManager configurationManager)
: base(logManager, configurationManager)
{
}
public override ItemUpdateType ItemUpdateType
{
get
{
return ItemUpdateType.ImageUpdate;
}
}
/// <summary>
/// Supportses the specified item.
/// </summary>
/// <param name="item">The item.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
public override bool Supports(BaseItem item)
{
if (item.LocationType != LocationType.FileSystem || item.ResolveArgs.IsDirectory)
{
return false;
}
var video = item as Video;
if (video != null && !(item is Episode))
{
return video.IsInMixedFolder;
}
var game = item as Game;
if (game != null)
{
return game.IsInMixedFolder;
}
return false;
}
/// <summary>
/// Gets the priority.
/// </summary>
/// <value>The priority.</value>
public override MetadataProviderPriority Priority
{
get { return MetadataProviderPriority.First; }
}
/// <summary>
/// Returns true or false indicating if the provider should refresh when the contents of it's directory changes
/// </summary>
/// <value><c>true</c> if [refresh on file system stamp change]; otherwise, <c>false</c>.</value>
protected override bool RefreshOnFileSystemStampChange
{
get
{
return true;
}
}
/// <summary>
/// Gets the filestamp extensions.
/// </summary>
/// <value>The filestamp extensions.</value>
protected override string[] FilestampExtensions
{
get
{
return BaseItem.SupportedImageExtensions;
}
}
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
return TrueTaskResult;
}
}
}

View file

@ -159,9 +159,10 @@ namespace MediaBrowser.Providers
/// Gets the image. /// Gets the image.
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
/// <param name="args">The args.</param>
/// <param name="filenameWithoutExtension">The filename without extension.</param> /// <param name="filenameWithoutExtension">The filename without extension.</param>
/// <returns>FileSystemInfo.</returns> /// <returns>FileSystemInfo.</returns>
protected override FileSystemInfo GetImage(BaseItem item, string filenameWithoutExtension) protected override FileSystemInfo GetImage(BaseItem item, ItemResolveArgs args, string filenameWithoutExtension)
{ {
var location = GetLocation(item); var location = GetLocation(item);

View file

@ -52,7 +52,6 @@
<Compile Include="FolderProviderFromXml.cs" /> <Compile Include="FolderProviderFromXml.cs" />
<Compile Include="Games\GameProviderFromXml.cs" /> <Compile Include="Games\GameProviderFromXml.cs" />
<Compile Include="ImageFromMediaLocationProvider.cs" /> <Compile Include="ImageFromMediaLocationProvider.cs" />
<Compile Include="ImageFromMixedMediaLocationProvider.cs" />
<Compile Include="ImagesByNameProvider.cs" /> <Compile Include="ImagesByNameProvider.cs" />
<Compile Include="MediaInfo\AudioImageProvider.cs" /> <Compile Include="MediaInfo\AudioImageProvider.cs" />
<Compile Include="MediaInfo\BaseFFProbeProvider.cs" /> <Compile Include="MediaInfo\BaseFFProbeProvider.cs" />

View file

@ -242,16 +242,9 @@ namespace MediaBrowser.Server.Implementations.Providers
if (saveLocally) if (saveLocally)
{ {
if (!(item is Episode)) if (item.IsInMixedFolder && !(item is Episode))
{ {
var video = item as Video; path = GetSavePathForItemInMixedFolder(item, type, filename, extension);
if (video != null && video.IsInMixedFolder)
{
var folder = Path.GetDirectoryName(video.Path);
path = Path.Combine(folder, Path.GetFileNameWithoutExtension(video.Path) + "-" + filename);
}
} }
if (string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(item.MetaLocation)) if (string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(item.MetaLocation))
@ -260,6 +253,7 @@ namespace MediaBrowser.Server.Implementations.Providers
} }
} }
// None of the save local conditions passed, so store it in our internal folders
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
{ {
path = _remoteImageCache.GetResourcePath(item.GetType().FullName + item.Id, filename); path = _remoteImageCache.GetResourcePath(item.GetType().FullName + item.Id, filename);
@ -274,5 +268,16 @@ namespace MediaBrowser.Server.Implementations.Providers
return path; return path;
} }
private string GetSavePathForItemInMixedFolder(BaseItem item, ImageType type, string imageFilename, string extension)
{
if (type == ImageType.Primary)
{
return Path.ChangeExtension(item.Path, extension);
}
var folder = Path.GetDirectoryName(item.Path);
return Path.Combine(folder, Path.GetFileNameWithoutExtension(item.Path) + "-" + imageFilename);
}
} }
} }