resolve mixed folder detection

pull/702/head
Luke Pulverenti 10 years ago
parent 56f6b0335c
commit 5eb44c42c5

@ -53,16 +53,6 @@ namespace MediaBrowser.Controller.Entities
public static string ThemeSongFilename = "theme"; public static string ThemeSongFilename = "theme";
public static string ThemeVideosFolderName = "backdrops"; public static string ThemeVideosFolderName = "backdrops";
public static List<KeyValuePair<string, ExtraType>> ExtraSuffixes = new List<KeyValuePair<string, ExtraType>>
{
new KeyValuePair<string,ExtraType>("-trailer", ExtraType.Trailer),
new KeyValuePair<string,ExtraType>("-deleted", ExtraType.DeletedScene),
new KeyValuePair<string,ExtraType>("-behindthescenes", ExtraType.BehindTheScenes),
new KeyValuePair<string,ExtraType>("-interview", ExtraType.Interview),
new KeyValuePair<string,ExtraType>("-scene", ExtraType.Scene),
new KeyValuePair<string,ExtraType>("-sample", ExtraType.Sample)
};
public List<ItemImageInfo> ImageInfos { get; set; } public List<ItemImageInfo> ImageInfos { get; set; }
[IgnoreDataMember] [IgnoreDataMember]
@ -618,7 +608,9 @@ namespace MediaBrowser.Controller.Entities
.Where(i => string.Equals(FileSystem.GetFileNameWithoutExtension(i), ThemeSongFilename, StringComparison.OrdinalIgnoreCase)) .Where(i => string.Equals(FileSystem.GetFileNameWithoutExtension(i), ThemeSongFilename, StringComparison.OrdinalIgnoreCase))
); );
return LibraryManager.ResolvePaths<Audio.Audio>(files, directoryService, null).Select(audio => return LibraryManager.ResolvePaths(files, directoryService, null)
.OfType<Audio.Audio>()
.Select(audio =>
{ {
// Try to retrieve it from the db. If we don't find it, use the resolved version // Try to retrieve it from the db. If we don't find it, use the resolved version
var dbItem = LibraryManager.GetItemById(audio.Id) as Audio.Audio; var dbItem = LibraryManager.GetItemById(audio.Id) as Audio.Audio;
@ -628,10 +620,7 @@ namespace MediaBrowser.Controller.Entities
audio = dbItem; audio = dbItem;
} }
if (audio != null)
{
audio.ExtraType = ExtraType.ThemeSong; audio.ExtraType = ExtraType.ThemeSong;
}
return audio; return audio;
@ -649,7 +638,9 @@ namespace MediaBrowser.Controller.Entities
.Where(i => string.Equals(i.Name, ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase)) .Where(i => string.Equals(i.Name, ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
.SelectMany(i => i.EnumerateFiles("*", SearchOption.TopDirectoryOnly)); .SelectMany(i => i.EnumerateFiles("*", SearchOption.TopDirectoryOnly));
return LibraryManager.ResolvePaths<Video>(files, directoryService, null).Select(item => return LibraryManager.ResolvePaths(files, directoryService, null)
.OfType<Video>()
.Select(item =>
{ {
// Try to retrieve it from the db. If we don't find it, use the resolved version // Try to retrieve it from the db. If we don't find it, use the resolved version
var dbItem = LibraryManager.GetItemById(item.Id) as Video; var dbItem = LibraryManager.GetItemById(item.Id) as Video;
@ -659,10 +650,7 @@ namespace MediaBrowser.Controller.Entities
item = dbItem; item = dbItem;
} }
if (item != null)
{
item.ExtraType = ExtraType.ThemeVideo; item.ExtraType = ExtraType.ThemeVideo;
}
return item; return item;

@ -696,7 +696,7 @@ namespace MediaBrowser.Controller.Entities
{ {
var collectionType = LibraryManager.FindCollectionType(this); var collectionType = LibraryManager.FindCollectionType(this);
return LibraryManager.ResolvePaths<BaseItem>(GetFileSystemChildren(directoryService), directoryService, this, collectionType); return LibraryManager.ResolvePaths(GetFileSystemChildren(directoryService), directoryService, this, collectionType);
} }
/// <summary> /// <summary>
@ -741,6 +741,12 @@ namespace MediaBrowser.Controller.Entities
private BaseItem RetrieveChild(BaseItem child) private BaseItem RetrieveChild(BaseItem child)
{ {
if (child.Id == Guid.Empty)
{
Logger.Error("Item found with empty Id: " + (child.Path ?? child.Name));
return null;
}
var item = LibraryManager.GetMemoryItemById(child.Id); var item = LibraryManager.GetMemoryItemById(child.Id);
if (item != null) if (item != null)

@ -24,7 +24,9 @@ namespace MediaBrowser.Controller.Library
/// <param name="parent">The parent.</param> /// <param name="parent">The parent.</param>
/// <param name="collectionType">Type of the collection.</param> /// <param name="collectionType">Type of the collection.</param>
/// <returns>BaseItem.</returns> /// <returns>BaseItem.</returns>
BaseItem ResolvePath(FileSystemInfo fileInfo, Folder parent = null, string collectionType = null); BaseItem ResolvePath(FileSystemInfo fileInfo,
Folder parent = null,
string collectionType = null);
/// <summary> /// <summary>
/// Resolves a set of files into a list of BaseItem /// Resolves a set of files into a list of BaseItem
@ -35,8 +37,10 @@ namespace MediaBrowser.Controller.Library
/// <param name="parent">The parent.</param> /// <param name="parent">The parent.</param>
/// <param name="collectionType">Type of the collection.</param> /// <param name="collectionType">Type of the collection.</param>
/// <returns>List{``0}.</returns> /// <returns>List{``0}.</returns>
List<T> ResolvePaths<T>(IEnumerable<FileSystemInfo> files, IDirectoryService directoryService, Folder parent, string collectionType = null) IEnumerable<BaseItem> ResolvePaths(IEnumerable<FileSystemInfo> files,
where T : BaseItem; IDirectoryService directoryService,
Folder parent, string
collectionType = null);
/// <summary> /// <summary>
/// Gets the root folder. /// Gets the root folder.

@ -1,5 +1,8 @@
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using System.Collections.Generic;
using System.IO;
namespace MediaBrowser.Controller.Resolvers namespace MediaBrowser.Controller.Resolvers
{ {
@ -20,4 +23,24 @@ namespace MediaBrowser.Controller.Resolvers
/// <value>The priority.</value> /// <value>The priority.</value>
ResolverPriority Priority { get; } ResolverPriority Priority { get; }
} }
public interface IMultiItemResolver
{
MultiItemResolverResult ResolveMultiple(Folder parent,
List<FileSystemInfo> files,
string collectionType,
IDirectoryService directoryService);
}
public class MultiItemResolverResult
{
public List<BaseItem> Items { get; set; }
public List<FileSystemInfo> ExtraFiles { get; set; }
public MultiItemResolverResult()
{
Items = new List<BaseItem>();
ExtraFiles = new List<FileSystemInfo>();
}
}
} }

@ -213,14 +213,15 @@ namespace MediaBrowser.Dlna.ContentDirectory
var serverItem = GetItemFromObjectId(id, user); var serverItem = GetItemFromObjectId(id, user);
var item = serverItem.Item; var item = serverItem.Item;
var totalCount = 0; int totalCount;
if (string.Equals(flag, "BrowseMetadata")) if (string.Equals(flag, "BrowseMetadata"))
{ {
totalCount = 1;
if (item.IsFolder || serverItem.StubType.HasValue) if (item.IsFolder || serverItem.StubType.HasValue)
{ {
var childrenResult = (await GetUserItems(item, serverItem.StubType, user, sortCriteria, start, requested).ConfigureAwait(false)); var childrenResult = (await GetUserItems(item, serverItem.StubType, user, sortCriteria, start, requested).ConfigureAwait(false));
totalCount = 1;
result.DocumentElement.AppendChild(_didlBuilder.GetFolderElement(result, item, serverItem.StubType, null, childrenResult.TotalRecordCount, filter, id)); result.DocumentElement.AppendChild(_didlBuilder.GetFolderElement(result, item, serverItem.StubType, null, childrenResult.TotalRecordCount, filter, id));
} }

@ -95,11 +95,6 @@ namespace MediaBrowser.Server.Implementations.Library
{ {
return true; return true;
} }
if (BaseItem.ExtraSuffixes.Any(i => filename.IndexOf(i.Key, StringComparison.OrdinalIgnoreCase) != -1))
{
return true;
}
} }
// Ignore samples // Ignore samples

@ -26,79 +26,5 @@ namespace MediaBrowser.Server.Implementations.Library
".wd_tv" ".wd_tv"
}; };
/// <summary>
/// Ensures DateCreated and DateModified have values
/// </summary>
/// <param name="fileSystem">The file system.</param>
/// <param name="item">The item.</param>
/// <param name="args">The args.</param>
/// <param name="includeCreationTime">if set to <c>true</c> [include creation time].</param>
public static void EnsureDates(IFileSystem fileSystem, BaseItem item, ItemResolveArgs args, bool includeCreationTime)
{
if (fileSystem == null)
{
throw new ArgumentNullException("fileSystem");
}
if (item == null)
{
throw new ArgumentNullException("item");
}
if (args == null)
{
throw new ArgumentNullException("args");
}
// See if a different path came out of the resolver than what went in
if (!string.Equals(args.Path, item.Path, StringComparison.OrdinalIgnoreCase))
{
var childData = args.IsDirectory ? args.GetFileSystemEntryByPath(item.Path) : null;
if (childData != null)
{
if (includeCreationTime)
{
SetDateCreated(item, fileSystem, childData);
}
item.DateModified = fileSystem.GetLastWriteTimeUtc(childData);
}
else
{
var fileData = fileSystem.GetFileSystemInfo(item.Path);
if (fileData.Exists)
{
if (includeCreationTime)
{
SetDateCreated(item, fileSystem, fileData);
}
item.DateModified = fileSystem.GetLastWriteTimeUtc(fileData);
}
}
}
else
{
if (includeCreationTime)
{
SetDateCreated(item, fileSystem, args.FileInfo);
}
item.DateModified = fileSystem.GetLastWriteTimeUtc(args.FileInfo);
}
}
private static void SetDateCreated(BaseItem item, IFileSystem fileSystem, FileSystemInfo info)
{
var config = BaseItem.ConfigurationManager.GetMetadataConfiguration();
if (config.UseFileCreationTimeForDateAdded)
{
item.DateCreated = fileSystem.GetCreationTimeUtc(info);
}
else
{
item.DateCreated = DateTime.UtcNow;
}
}
} }
} }

@ -466,29 +466,30 @@ namespace MediaBrowser.Server.Implementations.Library
/// </summary> /// </summary>
/// <param name="args">The args.</param> /// <param name="args">The args.</param>
/// <returns>BaseItem.</returns> /// <returns>BaseItem.</returns>
public BaseItem ResolveItem(ItemResolveArgs args) private BaseItem ResolveItem(ItemResolveArgs args)
{ {
var item = EntityResolvers.Select(r => var item = EntityResolvers.Select(r => Resolve(args, r))
.FirstOrDefault(i => i != null);
if (item != null)
{
ResolverHelper.SetInitialItemValues(item, args, _fileSystem, this);
}
return item;
}
private BaseItem Resolve(ItemResolveArgs args, IItemResolver resolver)
{ {
try try
{ {
return r.ResolvePath(args); return resolver.ResolvePath(args);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.ErrorException("Error in {0} resolving {1}", ex, r.GetType().Name, args.Path); _logger.ErrorException("Error in {0} resolving {1}", ex, resolver.GetType().Name, args.Path);
return null; return null;
} }
}).FirstOrDefault(i => i != null);
if (item != null)
{
ResolverHelper.SetInitialItemValues(item, args, _fileSystem, this);
}
return item;
} }
public Guid GetNewItemId(string key, Type type) public Guid GetNewItemId(string key, Type type)
@ -565,7 +566,7 @@ namespace MediaBrowser.Server.Implementations.Library
return ResolvePath(fileInfo, new DirectoryService(_logger), parent, collectionType); return ResolvePath(fileInfo, new DirectoryService(_logger), parent, collectionType);
} }
public BaseItem ResolvePath(FileSystemInfo fileInfo, IDirectoryService directoryService, Folder parent = null, string collectionType = null) private BaseItem ResolvePath(FileSystemInfo fileInfo, IDirectoryService directoryService, Folder parent = null, string collectionType = null)
{ {
if (fileInfo == null) if (fileInfo == null)
{ {
@ -645,23 +646,50 @@ namespace MediaBrowser.Server.Implementations.Library
return !args.ContainsFileSystemEntryByName(".ignore"); return !args.ContainsFileSystemEntryByName(".ignore");
} }
public List<T> ResolvePaths<T>(IEnumerable<FileSystemInfo> files, IDirectoryService directoryService, Folder parent, string collectionType = null) public IEnumerable<BaseItem> ResolvePaths(IEnumerable<FileSystemInfo> files, IDirectoryService directoryService, Folder parent, string collectionType)
where T : BaseItem {
var fileList = files.ToList();
if (parent != null)
{
var multiItemResolvers = EntityResolvers.OfType<IMultiItemResolver>();
foreach (var resolver in multiItemResolvers)
{
var result = resolver.ResolveMultiple(parent, fileList, collectionType, directoryService);
if (result != null && result.Items.Count > 0)
{
var items = new List<BaseItem>();
items.AddRange(result.Items);
foreach (var item in items)
{
ResolverHelper.SetInitialItemValues(item, parent, _fileSystem, this, directoryService);
}
items.AddRange(ResolveFileList(result.ExtraFiles, directoryService, parent, collectionType));
return items;
}
}
}
return ResolveFileList(fileList, directoryService, parent, collectionType);
}
private IEnumerable<BaseItem> ResolveFileList(IEnumerable<FileSystemInfo> fileList, IDirectoryService directoryService, Folder parent, string collectionType)
{ {
return files.Select(f => return fileList.Select(f =>
{ {
try try
{ {
return ResolvePath(f, directoryService, parent, collectionType) as T; return ResolvePath(f, directoryService, parent, collectionType);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.ErrorException("Error resolving path {0}", ex, f.FullName); _logger.ErrorException("Error resolving path {0}", ex, f.FullName);
return null; return null;
} }
}).Where(i => i != null);
}).Where(i => i != null)
.ToList();
} }
/// <summary> /// <summary>
@ -1724,7 +1752,9 @@ namespace MediaBrowser.Server.Implementations.Library
files.AddRange(currentVideo.Extras.Where(i => string.Equals(i.ExtraType, "trailer", StringComparison.OrdinalIgnoreCase)).Select(i => new FileInfo(i.Path))); files.AddRange(currentVideo.Extras.Where(i => string.Equals(i.ExtraType, "trailer", StringComparison.OrdinalIgnoreCase)).Select(i => new FileInfo(i.Path)));
} }
return ResolvePaths<Video>(files, directoryService, null).Select(video => return ResolvePaths(files, directoryService, null, null)
.OfType<Video>()
.Select(video =>
{ {
// Try to retrieve it from the db. If we don't find it, use the resolved version // Try to retrieve it from the db. If we don't find it, use the resolved version
var dbItem = GetItemById(video.Id) as Video; var dbItem = GetItemById(video.Id) as Video;
@ -1775,7 +1805,9 @@ namespace MediaBrowser.Server.Implementations.Library
files.AddRange(currentVideo.Extras.Where(i => !string.Equals(i.ExtraType, "trailer", StringComparison.OrdinalIgnoreCase)).Select(i => new FileInfo(i.Path))); files.AddRange(currentVideo.Extras.Where(i => !string.Equals(i.ExtraType, "trailer", StringComparison.OrdinalIgnoreCase)).Select(i => new FileInfo(i.Path)));
} }
return ResolvePaths<Video>(files, directoryService, null).Select(video => return ResolvePaths(files, directoryService, null, null)
.OfType<Video>()
.Select(video =>
{ {
// Try to retrieve it from the db. If we don't find it, use the resolved version // Try to retrieve it from the db. If we don't find it, use the resolved version
var dbItem = GetItemById(video.Id) as Video; var dbItem = GetItemById(video.Id) as Video;
@ -1795,7 +1827,7 @@ namespace MediaBrowser.Server.Implementations.Library
private void SetExtraTypeFromFilename(Video item) private void SetExtraTypeFromFilename(Video item)
{ {
var resolver = new ExtraResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger()); var resolver = new ExtraResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger(), new RegexProvider());
var result = resolver.GetExtraInfo(item.Path); var result = resolver.GetExtraInfo(item.Path);

@ -1,6 +1,7 @@
using MediaBrowser.Common.IO; using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -13,12 +14,55 @@ namespace MediaBrowser.Server.Implementations.Library
/// </summary> /// </summary>
public static class ResolverHelper public static class ResolverHelper
{ {
/// <summary>
/// Sets the initial item values.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="parent">The parent.</param>
/// <param name="fileSystem">The file system.</param>
/// <param name="libraryManager">The library manager.</param>
/// <param name="directoryService">The directory service.</param>
/// <exception cref="System.ArgumentException">Item must have a path</exception>
public static void SetInitialItemValues(BaseItem item, Folder parent, IFileSystem fileSystem, ILibraryManager libraryManager, IDirectoryService directoryService)
{
// This version of the below method has no ItemResolveArgs, so we have to require the path already being set
if (string.IsNullOrWhiteSpace(item.Path))
{
throw new ArgumentException("Item must have a Path");
}
// If the resolver didn't specify this
if (parent != null)
{
item.Parent = parent;
}
item.Id = libraryManager.GetNewItemId(item.Path, item.GetType());
// If the resolver didn't specify this
if (string.IsNullOrEmpty(item.DisplayMediaType))
{
item.DisplayMediaType = item.GetType().Name;
}
item.IsLocked = item.Path.IndexOf("[dontfetchmeta]", StringComparison.OrdinalIgnoreCase) != -1 ||
item.Parents.Any(i => i.IsLocked);
// Make sure DateCreated and DateModified have values
var fileInfo = directoryService.GetFile(item.Path);
item.DateModified = fileSystem.GetLastWriteTimeUtc(fileInfo);
SetDateCreated(item, fileSystem, fileInfo);
EnsureName(item, fileInfo);
}
/// <summary> /// <summary>
/// Sets the initial item values. /// Sets the initial item values.
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
/// <param name="args">The args.</param> /// <param name="args">The args.</param>
/// <param name="fileSystem">The file system.</param> /// <param name="fileSystem">The file system.</param>
/// <param name="libraryManager">The library manager.</param>
public static void SetInitialItemValues(BaseItem item, ItemResolveArgs args, IFileSystem fileSystem, ILibraryManager libraryManager) public static void SetInitialItemValues(BaseItem item, ItemResolveArgs args, IFileSystem fileSystem, ILibraryManager libraryManager)
{ {
// If the resolver didn't specify this // If the resolver didn't specify this
@ -42,27 +86,26 @@ namespace MediaBrowser.Server.Implementations.Library
} }
// Make sure the item has a name // Make sure the item has a name
EnsureName(item, args); EnsureName(item, args.FileInfo);
item.IsLocked = item.Path.IndexOf("[dontfetchmeta]", StringComparison.OrdinalIgnoreCase) != -1 || item.IsLocked = item.Path.IndexOf("[dontfetchmeta]", StringComparison.OrdinalIgnoreCase) != -1 ||
item.Parents.Any(i => i.IsLocked); item.Parents.Any(i => i.IsLocked);
// Make sure DateCreated and DateModified have values // Make sure DateCreated and DateModified have values
EntityResolutionHelper.EnsureDates(fileSystem, item, args, true); EnsureDates(fileSystem, item, args, true);
} }
/// <summary> /// <summary>
/// Ensures the name. /// Ensures the name.
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
/// <param name="args">The arguments.</param> /// <param name="fileInfo">The file information.</param>
private static void EnsureName(BaseItem item, ItemResolveArgs args) private static void EnsureName(BaseItem item, FileSystemInfo fileInfo)
{ {
// If the subclass didn't supply a name, add it here // If the subclass didn't supply a name, add it here
if (string.IsNullOrEmpty(item.Name) && !string.IsNullOrEmpty(item.Path)) if (string.IsNullOrEmpty(item.Name) && !string.IsNullOrEmpty(item.Path))
{ {
//we use our resolve args name here to get the name of the containg folder, not actual video file item.Name = GetDisplayName(fileInfo.Name, (fileInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory);
item.Name = GetDisplayName(args.FileInfo.Name, (args.FileInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory);
} }
} }
@ -74,10 +117,7 @@ namespace MediaBrowser.Server.Implementations.Library
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
private static string GetDisplayName(string path, bool isDirectory) private static string GetDisplayName(string path, bool isDirectory)
{ {
//first just get the file or directory name return isDirectory ? Path.GetFileName(path) : Path.GetFileNameWithoutExtension(path);
var fn = isDirectory ? Path.GetFileName(path) : Path.GetFileNameWithoutExtension(path);
return fn;
} }
/// <summary> /// <summary>
@ -90,5 +130,79 @@ namespace MediaBrowser.Server.Implementations.Library
var output = MbNameRegex.Replace(inputString, string.Empty).Trim(); var output = MbNameRegex.Replace(inputString, string.Empty).Trim();
return Regex.Replace(output, @"\s+", " "); return Regex.Replace(output, @"\s+", " ");
} }
/// <summary>
/// Ensures DateCreated and DateModified have values
/// </summary>
/// <param name="fileSystem">The file system.</param>
/// <param name="item">The item.</param>
/// <param name="args">The args.</param>
/// <param name="includeCreationTime">if set to <c>true</c> [include creation time].</param>
private static void EnsureDates(IFileSystem fileSystem, BaseItem item, ItemResolveArgs args, bool includeCreationTime)
{
if (fileSystem == null)
{
throw new ArgumentNullException("fileSystem");
}
if (item == null)
{
throw new ArgumentNullException("item");
}
if (args == null)
{
throw new ArgumentNullException("args");
}
// See if a different path came out of the resolver than what went in
if (!string.Equals(args.Path, item.Path, StringComparison.OrdinalIgnoreCase))
{
var childData = args.IsDirectory ? args.GetFileSystemEntryByPath(item.Path) : null;
if (childData != null)
{
if (includeCreationTime)
{
SetDateCreated(item, fileSystem, childData);
}
item.DateModified = fileSystem.GetLastWriteTimeUtc(childData);
}
else
{
var fileData = fileSystem.GetFileSystemInfo(item.Path);
if (fileData.Exists)
{
if (includeCreationTime)
{
SetDateCreated(item, fileSystem, fileData);
}
item.DateModified = fileSystem.GetLastWriteTimeUtc(fileData);
}
}
}
else
{
if (includeCreationTime)
{
SetDateCreated(item, fileSystem, args.FileInfo);
}
item.DateModified = fileSystem.GetLastWriteTimeUtc(args.FileInfo);
}
}
private static void SetDateCreated(BaseItem item, IFileSystem fileSystem, FileSystemInfo info)
{
var config = BaseItem.ConfigurationManager.GetMetadataConfiguration();
if (config.UseFileCreationTimeForDateAdded)
{
item.DateCreated = fileSystem.GetCreationTimeUtc(info);
}
else
{
item.DateCreated = DateTime.UtcNow;
}
}
} }
} }

@ -1,10 +1,12 @@
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Naming.Common; using MediaBrowser.Naming.Common;
using MediaBrowser.Naming.Video; using MediaBrowser.Naming.Video;
using System; using System;
using System.IO; using System.IO;
using System.Linq;
namespace MediaBrowser.Server.Implementations.Library.Resolvers namespace MediaBrowser.Server.Implementations.Library.Resolvers
{ {
@ -29,7 +31,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
/// <returns>`0.</returns> /// <returns>`0.</returns>
protected override T Resolve(ItemResolveArgs args) protected override T Resolve(ItemResolveArgs args)
{ {
return ResolveVideo<T>(args, true); return ResolveVideo<T>(args, false);
} }
/// <summary> /// <summary>
@ -96,14 +98,9 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
if (video != null) if (video != null)
{ {
if (parseName) video.Name = parseName ?
{ videoInfo.Name :
video.Name = videoInfo.Name; Path.GetFileName(args.Path);
}
else
{
video.Name = Path.GetFileName(args.Path);
}
Set3DFormat(video, videoInfo); Set3DFormat(video, videoInfo);
} }
@ -119,35 +116,43 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
return null; return null;
} }
var isShortcut = string.Equals(videoInfo.Container, "strm", StringComparison.OrdinalIgnoreCase); if (LibraryManager.IsVideoFile(args.Path) || videoInfo.IsStub)
if (LibraryManager.IsVideoFile(args.Path) || videoInfo.IsStub || isShortcut)
{ {
var type = string.Equals(videoInfo.Container, "iso", StringComparison.OrdinalIgnoreCase) || string.Equals(videoInfo.Container, "img", StringComparison.OrdinalIgnoreCase) ?
VideoType.Iso :
VideoType.VideoFile;
var path = args.Path; var path = args.Path;
var video = new TVideoType var video = new TVideoType
{ {
VideoType = type,
Path = path, Path = path,
IsInMixedFolder = true, IsInMixedFolder = true,
IsPlaceHolder = videoInfo.IsStub,
IsShortcut = isShortcut,
ProductionYear = videoInfo.Year ProductionYear = videoInfo.Year
}; };
if (parseName) SetVideoType(video, videoInfo);
{
video.Name = videoInfo.Name; video.Name = parseName ?
videoInfo.Name :
Path.GetFileNameWithoutExtension(args.Path);
Set3DFormat(video, videoInfo);
return video;
} }
else
{
video.Name = Path.GetFileNameWithoutExtension(path);
} }
return null;
}
protected void SetVideoType(Video video, VideoFileInfo videoInfo)
{
var extension = Path.GetExtension(video.Path);
video.VideoType = string.Equals(extension, ".iso", StringComparison.OrdinalIgnoreCase) ||
string.Equals(extension, ".img", StringComparison.OrdinalIgnoreCase) ?
VideoType.Iso :
VideoType.VideoFile;
video.IsShortcut = string.Equals(extension, ".strm", StringComparison.OrdinalIgnoreCase);
video.IsPlaceHolder = videoInfo.IsStub;
if (videoInfo.IsStub) if (videoInfo.IsStub)
{ {
if (string.Equals(videoInfo.StubType, "dvd", StringComparison.OrdinalIgnoreCase)) if (string.Equals(videoInfo.StubType, "dvd", StringComparison.OrdinalIgnoreCase))
@ -163,51 +168,56 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
video.VideoType = VideoType.BluRay; video.VideoType = VideoType.BluRay;
} }
} }
Set3DFormat(video, videoInfo);
return video;
}
}
return null;
} }
private void Set3DFormat(Video video, VideoFileInfo videoInfo) protected void Set3DFormat(Video video, bool is3D, string format3D)
{ {
if (videoInfo.Is3D) if (is3D)
{ {
if (string.Equals(videoInfo.Format3D, "fsbs", StringComparison.OrdinalIgnoreCase)) if (string.Equals(format3D, "fsbs", StringComparison.OrdinalIgnoreCase))
{ {
video.Video3DFormat = Video3DFormat.FullSideBySide; video.Video3DFormat = Video3DFormat.FullSideBySide;
} }
else if (string.Equals(videoInfo.Format3D, "ftab", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(format3D, "ftab", StringComparison.OrdinalIgnoreCase))
{ {
video.Video3DFormat = Video3DFormat.FullTopAndBottom; video.Video3DFormat = Video3DFormat.FullTopAndBottom;
} }
else if (string.Equals(videoInfo.Format3D, "hsbs", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(format3D, "hsbs", StringComparison.OrdinalIgnoreCase))
{ {
video.Video3DFormat = Video3DFormat.HalfSideBySide; video.Video3DFormat = Video3DFormat.HalfSideBySide;
} }
else if (string.Equals(videoInfo.Format3D, "htab", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(format3D, "htab", StringComparison.OrdinalIgnoreCase))
{ {
video.Video3DFormat = Video3DFormat.HalfTopAndBottom; video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
} }
else if (string.Equals(videoInfo.Format3D, "sbs", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(format3D, "sbs", StringComparison.OrdinalIgnoreCase))
{ {
video.Video3DFormat = Video3DFormat.HalfSideBySide; video.Video3DFormat = Video3DFormat.HalfSideBySide;
} }
else if (string.Equals(videoInfo.Format3D, "sbs3d", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(format3D, "sbs3d", StringComparison.OrdinalIgnoreCase))
{ {
video.Video3DFormat = Video3DFormat.HalfSideBySide; video.Video3DFormat = Video3DFormat.HalfSideBySide;
} }
else if (string.Equals(videoInfo.Format3D, "tab", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(format3D, "tab", StringComparison.OrdinalIgnoreCase))
{ {
video.Video3DFormat = Video3DFormat.HalfTopAndBottom; video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
} }
} }
} }
protected void Set3DFormat(Video video, VideoFileInfo videoInfo)
{
Set3DFormat(video, videoInfo.Is3D, videoInfo.Format3D);
}
protected void Set3DFormat(Video video)
{
var resolver = new Format3DParser(new ExtendedNamingOptions(), new Naming.Logging.NullLogger());
var result = resolver.Parse(video.Path);
Set3DFormat(video, result.Is3D, result.Format3D);
}
/// <summary> /// <summary>
/// Determines whether [is DVD directory] [the specified directory name]. /// Determines whether [is DVD directory] [the specified directory name].
/// </summary> /// </summary>
@ -227,5 +237,15 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
{ {
return string.Equals(directoryName, "bdmv", StringComparison.OrdinalIgnoreCase); return string.Equals(directoryName, "bdmv", StringComparison.OrdinalIgnoreCase);
} }
protected bool IsBluRayContainer(string path, IDirectoryService directoryService)
{
return directoryService.GetDirectories(path).Any(i => IsBluRayDirectory(i.Name));
}
protected bool IsDvdContainer(string path, IDirectoryService directoryService)
{
return directoryService.GetDirectories(path).Any(i => IsDvdDirectory(i.Name));
}
} }
} }

@ -1,5 +1,4 @@
using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
@ -38,7 +37,8 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
return null; return null;
} }
if (filename.IndexOf("[boxset]", StringComparison.OrdinalIgnoreCase) != -1 || args.ContainsFileSystemEntryByName("collection.xml")) if (filename.IndexOf("[boxset]", StringComparison.OrdinalIgnoreCase) != -1 ||
args.ContainsFileSystemEntryByName("collection.xml"))
{ {
return new BoxSet return new BoxSet
{ {

@ -2,12 +2,14 @@
using MediaBrowser.Controller; using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Resolvers; using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using MediaBrowser.Naming.Common; using MediaBrowser.Naming.Common;
using MediaBrowser.Naming.IO;
using MediaBrowser.Naming.Video; using MediaBrowser.Naming.Video;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -19,13 +21,14 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
/// <summary> /// <summary>
/// Class MovieResolver /// Class MovieResolver
/// </summary> /// </summary>
public class MovieResolver : BaseVideoResolver<Video> public class MovieResolver : BaseVideoResolver<Video>, IMultiItemResolver
{ {
private readonly IServerApplicationPaths _applicationPaths; private readonly IServerApplicationPaths _applicationPaths;
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
public MovieResolver(ILibraryManager libraryManager, IServerApplicationPaths applicationPaths, ILogger logger, IFileSystem fileSystem) : base(libraryManager) public MovieResolver(ILibraryManager libraryManager, IServerApplicationPaths applicationPaths, ILogger logger, IFileSystem fileSystem)
: base(libraryManager)
{ {
_applicationPaths = applicationPaths; _applicationPaths = applicationPaths;
_logger = logger; _logger = logger;
@ -43,10 +46,107 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
// Give plugins a chance to catch iso's first // Give plugins a chance to catch iso's first
// Also since we have to loop through child files looking for videos, // Also since we have to loop through child files looking for videos,
// see if we can avoid some of that by letting other resolvers claim folders first // see if we can avoid some of that by letting other resolvers claim folders first
return ResolverPriority.Second; // Also run after series resolver
return ResolverPriority.Third;
} }
} }
public MultiItemResolverResult ResolveMultiple(Folder parent,
List<FileSystemInfo> files,
string collectionType,
IDirectoryService directoryService)
{
if (IsInvalid(parent, collectionType, files))
{
return null;
}
if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
{
return ResolveVideos<MusicVideo>(parent, files, directoryService, collectionType);
}
if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
{
return ResolveVideos<Video>(parent, files, directoryService, collectionType);
}
if (string.IsNullOrEmpty(collectionType))
{
// Owned items should just use the plain video type
if (parent == null)
{
return ResolveVideos<Video>(parent, files, directoryService, collectionType);
}
return ResolveVideos<Movie>(parent, files, directoryService, collectionType);
}
if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) ||
string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
{
return ResolveVideos<Movie>(parent, files, directoryService, collectionType);
}
return null;
}
private MultiItemResolverResult ResolveVideos<T>(Folder parent, IEnumerable<FileSystemInfo> fileSystemEntries, IDirectoryService directoryService, string collectionType)
where T : Video, new()
{
var files = new List<FileSystemInfo>();
var videos = new List<BaseItem>();
var leftOver = new List<FileSystemInfo>();
// Loop through each child file/folder and see if we find a video
foreach (var child in fileSystemEntries)
{
if ((child.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
{
leftOver.Add(child);
}
else
{
files.Add(child);
}
}
var resolver = new VideoListResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger());
var resolverResult = resolver.Resolve(files.Select(i => new PortableFileInfo
{
FullName = i.FullName,
Type = FileInfoType.File
}).ToList());
var result = new MultiItemResolverResult
{
ExtraFiles = leftOver,
Items = videos
};
foreach (var video in resolverResult)
{
var firstVideo = video.Files.First();
var videoItem = new T
{
Path = video.Files[0].Path,
IsInMixedFolder = true,
ProductionYear = video.Year,
Name = video.Name,
AdditionalParts = video.Files.Skip(1).Select(i => i.Path).ToList()
};
SetVideoType(videoItem, firstVideo);
Set3DFormat(videoItem, firstVideo);
result.Items.Add(videoItem);
}
return result;
}
/// <summary> /// <summary>
/// Resolves the specified args. /// Resolves the specified args.
/// </summary> /// </summary>
@ -54,28 +154,24 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
/// <returns>Video.</returns> /// <returns>Video.</returns>
protected override Video Resolve(ItemResolveArgs args) protected override Video Resolve(ItemResolveArgs args)
{ {
// Avoid expensive tests against VF's and all their children by not allowing this var collectionType = args.GetCollectionType();
if (args.Parent != null)
{ if (IsInvalid(args.Parent, collectionType, args.FileSystemChildren))
if (args.Parent.IsRoot)
{ {
return null; return null;
} }
}
var collectionType = args.GetCollectionType();
// Find movies with their own folders // Find movies with their own folders
if (args.IsDirectory) if (args.IsDirectory)
{ {
if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
{ {
return FindMovie<MusicVideo>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, false, collectionType); return FindMovie<MusicVideo>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType);
} }
if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase)) if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
{ {
return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, false, collectionType); return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType);
} }
if (string.IsNullOrEmpty(collectionType)) if (string.IsNullOrEmpty(collectionType))
@ -83,7 +179,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
// Owned items should just use the plain video type // Owned items should just use the plain video type
if (args.Parent == null) if (args.Parent == null)
{ {
return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, false, collectionType); return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType);
} }
// Since the looping is expensive, this is an optimization to help us avoid it // Since the looping is expensive, this is an optimization to help us avoid it
@ -92,21 +188,20 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
return null; return null;
} }
return FindMovie<Movie>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, true, collectionType); return FindMovie<Movie>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType);
} }
if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) || if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) ||
string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase)) string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
{ {
return FindMovie<Movie>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, true, collectionType); return FindMovie<Movie>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType);
} }
return null; return null;
} }
var filename = Path.GetFileName(args.Path); // Owned items will be caught by the plain video resolver
// Don't misidentify extras or trailers if (args.Parent == null)
if (BaseItem.ExtraSuffixes.Any(i => filename.IndexOf(i.Key, StringComparison.OrdinalIgnoreCase) != -1))
{ {
return null; return null;
} }
@ -115,7 +210,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
{ {
item = ResolveVideo<MusicVideo>(args, true); item = ResolveVideo<MusicVideo>(args, false);
} }
// To find a movie file, the collection type must be movies or boxsets // To find a movie file, the collection type must be movies or boxsets
@ -125,6 +220,15 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
item = ResolveVideo<Movie>(args, true); item = ResolveVideo<Movie>(args, true);
} }
else if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
{
item = ResolveVideo<Video>(args, false);
}
else if (string.IsNullOrEmpty(collectionType))
{
item = ResolveVideo<Movie>(args, false);
}
if (item != null) if (item != null)
{ {
item.IsInMixedFolder = true; item.IsInMixedFolder = true;
@ -170,17 +274,14 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
/// <param name="parent">The parent.</param> /// <param name="parent">The parent.</param>
/// <param name="fileSystemEntries">The file system entries.</param> /// <param name="fileSystemEntries">The file system entries.</param>
/// <param name="directoryService">The directory service.</param> /// <param name="directoryService">The directory service.</param>
/// <param name="supportsMultipleSources">if set to <c>true</c> [supports multiple sources].</param>
/// <param name="collectionType">Type of the collection.</param> /// <param name="collectionType">Type of the collection.</param>
/// <returns>Movie.</returns> /// <returns>Movie.</returns>
private T FindMovie<T>(string path, Folder parent, IEnumerable<FileSystemInfo> fileSystemEntries, IDirectoryService directoryService, bool supportsMultipleSources, string collectionType) private T FindMovie<T>(string path, Folder parent, List<FileSystemInfo> fileSystemEntries, IDirectoryService directoryService, string collectionType)
where T : Video, new() where T : Video, new()
{ {
var movies = new List<T>();
var multiDiscFolders = new List<FileSystemInfo>(); var multiDiscFolders = new List<FileSystemInfo>();
// Loop through each child file/folder and see if we find a video // Search for a folder rip
foreach (var child in fileSystemEntries) foreach (var child in fileSystemEntries)
{ {
var filename = child.Name; var filename = child.Name;
@ -189,76 +290,59 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
{ {
if (IsDvdDirectory(filename)) if (IsDvdDirectory(filename))
{ {
return new T var movie = new T
{ {
Path = path, Path = path,
VideoType = VideoType.Dvd VideoType = VideoType.Dvd
}; };
Set3DFormat(movie);
return movie;
} }
if (IsBluRayDirectory(filename)) if (IsBluRayDirectory(filename))
{ {
return new T var movie = new T
{ {
Path = path, Path = path,
VideoType = VideoType.BluRay VideoType = VideoType.BluRay
}; };
Set3DFormat(movie);
return movie;
} }
multiDiscFolders.Add(child); multiDiscFolders.Add(child);
continue;
} }
// Don't misidentify extras or trailers as a movie
if (BaseItem.ExtraSuffixes.Any(i => filename.IndexOf(i.Key, StringComparison.OrdinalIgnoreCase) != -1))
{
continue;
} }
var childArgs = new ItemResolveArgs(_applicationPaths, LibraryManager, directoryService) var result = ResolveVideos<T>(parent, fileSystemEntries, directoryService, collectionType);
{
FileInfo = child,
Path = child.FullName,
Parent = parent,
CollectionType = collectionType
};
var item = ResolveVideo<T>(childArgs, true);
if (item != null) // Test for multi-editions
if (result.Items.Count > 1)
{ {
item.IsInMixedFolder = false; var filenamePrefix = Path.GetFileName(path);
movies.Add(item);
}
}
if (movies.Count > 1) if (!string.IsNullOrWhiteSpace(filenamePrefix))
{ {
var multiFileResult = GetMultiFileMovie(movies); if (result.Items.All(i => _fileSystem.GetFileNameWithoutExtension(i.Path).StartsWith(filenamePrefix + " - ", StringComparison.OrdinalIgnoreCase)))
if (multiFileResult != null)
{ {
return multiFileResult; var movie = (T)result.Items[0];
} movie.Name = filenamePrefix;
movie.LocalAlternateVersions = result.Items.Skip(1).Select(i => i.Path).ToList();
if (supportsMultipleSources) _logger.Debug("Multi-version video found: " + movie.Path);
{
var result = GetMovieWithMultipleSources(movies);
if (result != null) return movie;
{
return result;
} }
} }
return null;
} }
if (movies.Count == 1) if (result.Items.Count == 1)
{ {
return movies[0]; var movie = (T)result.Items[0];
movie.IsInMixedFolder = false;
return movie;
} }
if (multiDiscFolders.Count > 0) if (result.Items.Count == 0 && multiDiscFolders.Count > 0)
{ {
return GetMultiDiscMovie<T>(multiDiscFolders, directoryService); return GetMultiDiscMovie<T>(multiDiscFolders, directoryService);
} }
@ -331,65 +415,42 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
}; };
} }
/// <summary> private bool IsInvalid(Folder parent, string collectionType, IEnumerable<FileSystemInfo> files)
/// Gets the multi file movie.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="movies">The movies.</param>
/// <returns>``0.</returns>
private T GetMultiFileMovie<T>(IEnumerable<T> movies)
where T : Video, new()
{ {
var sortedMovies = movies.OrderBy(i => i.Path).ToList(); if (parent != null)
var firstMovie = sortedMovies[0];
var paths = sortedMovies.Select(i => i.Path).ToList();
var resolver = new StackResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger());
var result = resolver.ResolveFiles(paths);
if (result.Stacks.Count != 1)
{ {
return null; if (parent.IsRoot)
{
return true;
} }
firstMovie.AdditionalParts = result.Stacks[0].Files.Skip(1).ToList();
firstMovie.Name = result.Stacks[0].Name;
// They must all be part of the sequence if we're going to consider it a multi-part movie
return firstMovie;
} }
private T GetMovieWithMultipleSources<T>(IEnumerable<T> movies) // Don't do any resolving within a series structure
where T : Video, new() if (string.IsNullOrEmpty(collectionType))
{ {
var sortedMovies = movies.OrderBy(i => i.Path).ToList(); if (parent is Season || parent is Series)
// Cap this at five to help avoid incorrect matching
if (sortedMovies.Count > 5)
{ {
return null; return true;
} }
var firstMovie = sortedMovies[0]; // Since the looping is expensive, this is an optimization to help us avoid it
if (files.Select(i => i.Name).Contains("series.xml", StringComparer.OrdinalIgnoreCase))
var filenamePrefix = Path.GetFileName(Path.GetDirectoryName(firstMovie.Path));
if (!string.IsNullOrWhiteSpace(filenamePrefix))
{
if (sortedMovies.All(i => _fileSystem.GetFileNameWithoutExtension(i.Path).StartsWith(filenamePrefix + " - ", StringComparison.OrdinalIgnoreCase)))
{ {
firstMovie.LocalAlternateVersions = sortedMovies.Skip(1).Select(i => i.Path).ToList(); return true;
_logger.Debug("Multi-version video found: " + firstMovie.Path);
return firstMovie;
} }
} }
return null; var validCollectionTypes = new[]
{
string.Empty,
CollectionType.Movies,
CollectionType.HomeVideos,
CollectionType.MusicVideos,
CollectionType.BoxSets,
CollectionType.Movies
};
return !validCollectionTypes.Contains(collectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
} }
} }
} }

@ -17,7 +17,9 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
protected override Photo Resolve(ItemResolveArgs args) protected override Photo Resolve(ItemResolveArgs args)
{ {
// Must be an image file within a photo collection // Must be an image file within a photo collection
if (!args.IsDirectory && IsImageFile(args.Path) && string.Equals(args.GetCollectionType(), CollectionType.Photos, StringComparison.OrdinalIgnoreCase)) if (!args.IsDirectory &&
string.Equals(args.GetCollectionType(), CollectionType.Photos, StringComparison.OrdinalIgnoreCase) &&
IsImageFile(args.Path))
{ {
return new Photo return new Photo
{ {

@ -1,8 +1,5 @@
using System; using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities;
using System.Linq; using System.Linq;
namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
@ -42,10 +39,6 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
// If the parent is a Season or Series, then this is an Episode if the VideoResolver returns something // If the parent is a Season or Series, then this is an Episode if the VideoResolver returns something
if (season != null || parent is Series || parent.Parents.OfType<Series>().Any()) if (season != null || parent is Series || parent.Parents.OfType<Series>().Any())
{ {
if (args.IsDirectory && args.Path.IndexOf("dead like me", StringComparison.OrdinalIgnoreCase) != -1)
{
var b = true;
}
var episode = ResolveVideo<Episode>(args, false); var episode = ResolveVideo<Episode>(args, false);
if (episode != null) if (episode != null)

@ -1,5 +1,4 @@
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Entities.TV;
@ -84,7 +83,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
return new Series return new Series
{ {
Path = args.Path, Path = args.Path,
Name = ResolverHelper.StripBrackets(Path.GetFileName(args.Path)) Name = Path.GetFileName(args.Path)
}; };
} }
} }

@ -1,9 +1,6 @@
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Resolvers; using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities;
using System;
using System.Linq;
namespace MediaBrowser.Server.Implementations.Library.Resolvers namespace MediaBrowser.Server.Implementations.Library.Resolvers
{ {
@ -22,23 +19,8 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
if (args.Parent != null) if (args.Parent != null)
{ {
// The movie resolver will handle this // The movie resolver will handle this
if (args.IsDirectory)
{
return null;
}
var collectionType = args.GetCollectionType() ?? string.Empty;
var accepted = new[]
{
string.Empty,
CollectionType.HomeVideos
};
if (!accepted.Contains(collectionType, StringComparer.OrdinalIgnoreCase))
{
return null; return null;
} }
}
return base.Resolve(args); return base.Resolve(args);
} }
@ -52,6 +34,4 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
get { return ResolverPriority.Last; } get { return ResolverPriority.Last; }
} }
} }
} }

@ -51,7 +51,7 @@
</Reference> </Reference>
<Reference Include="MediaBrowser.Naming, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="MediaBrowser.Naming, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\MediaBrowser.Naming.1.0.0.13\lib\portable-net45+sl4+wp71+win8+wpa81\MediaBrowser.Naming.dll</HintPath> <HintPath>..\packages\MediaBrowser.Naming.1.0.0.15\lib\portable-net45+sl4+wp71+win8+wpa81\MediaBrowser.Naming.dll</HintPath>
</Reference> </Reference>
<Reference Include="Mono.Nat, Version=1.2.21.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Mono.Nat, Version=1.2.21.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="MediaBrowser.Naming" version="1.0.0.13" targetFramework="net45" /> <package id="MediaBrowser.Naming" version="1.0.0.15" targetFramework="net45" />
<package id="Mono.Nat" version="1.2.21.0" targetFramework="net45" /> <package id="Mono.Nat" version="1.2.21.0" targetFramework="net45" />
<package id="morelinq" version="1.1.0" targetFramework="net45" /> <package id="morelinq" version="1.1.0" targetFramework="net45" />
</packages> </packages>
Loading…
Cancel
Save