resolve mixed folder detection
This commit is contained in:
parent
56f6b0335c
commit
5eb44c42c5
|
@ -53,16 +53,6 @@ namespace MediaBrowser.Controller.Entities
|
|||
public static string ThemeSongFilename = "theme";
|
||||
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; }
|
||||
|
||||
[IgnoreDataMember]
|
||||
|
@ -618,7 +608,9 @@ namespace MediaBrowser.Controller.Entities
|
|||
.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
|
||||
var dbItem = LibraryManager.GetItemById(audio.Id) as Audio.Audio;
|
||||
|
@ -628,10 +620,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
audio = dbItem;
|
||||
}
|
||||
|
||||
if (audio != null)
|
||||
{
|
||||
audio.ExtraType = ExtraType.ThemeSong;
|
||||
}
|
||||
audio.ExtraType = ExtraType.ThemeSong;
|
||||
|
||||
return audio;
|
||||
|
||||
|
@ -649,7 +638,9 @@ namespace MediaBrowser.Controller.Entities
|
|||
.Where(i => string.Equals(i.Name, ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
|
||||
.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
|
||||
var dbItem = LibraryManager.GetItemById(item.Id) as Video;
|
||||
|
@ -659,10 +650,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
item = dbItem;
|
||||
}
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
item.ExtraType = ExtraType.ThemeVideo;
|
||||
}
|
||||
item.ExtraType = ExtraType.ThemeVideo;
|
||||
|
||||
return item;
|
||||
|
||||
|
|
|
@ -696,7 +696,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
{
|
||||
var collectionType = LibraryManager.FindCollectionType(this);
|
||||
|
||||
return LibraryManager.ResolvePaths<BaseItem>(GetFileSystemChildren(directoryService), directoryService, this, collectionType);
|
||||
return LibraryManager.ResolvePaths(GetFileSystemChildren(directoryService), directoryService, this, collectionType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -741,6 +741,12 @@ namespace MediaBrowser.Controller.Entities
|
|||
|
||||
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);
|
||||
|
||||
if (item != null)
|
||||
|
|
|
@ -24,7 +24,9 @@ namespace MediaBrowser.Controller.Library
|
|||
/// <param name="parent">The parent.</param>
|
||||
/// <param name="collectionType">Type of the collection.</param>
|
||||
/// <returns>BaseItem.</returns>
|
||||
BaseItem ResolvePath(FileSystemInfo fileInfo, Folder parent = null, string collectionType = null);
|
||||
BaseItem ResolvePath(FileSystemInfo fileInfo,
|
||||
Folder parent = null,
|
||||
string collectionType = null);
|
||||
|
||||
/// <summary>
|
||||
/// 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="collectionType">Type of the collection.</param>
|
||||
/// <returns>List{``0}.</returns>
|
||||
List<T> ResolvePaths<T>(IEnumerable<FileSystemInfo> files, IDirectoryService directoryService, Folder parent, string collectionType = null)
|
||||
where T : BaseItem;
|
||||
IEnumerable<BaseItem> ResolvePaths(IEnumerable<FileSystemInfo> files,
|
||||
IDirectoryService directoryService,
|
||||
Folder parent, string
|
||||
collectionType = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the root folder.
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace MediaBrowser.Controller.Resolvers
|
||||
{
|
||||
|
@ -20,4 +23,24 @@ namespace MediaBrowser.Controller.Resolvers
|
|||
/// <value>The priority.</value>
|
||||
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 item = serverItem.Item;
|
||||
|
||||
var totalCount = 0;
|
||||
int totalCount;
|
||||
|
||||
if (string.Equals(flag, "BrowseMetadata"))
|
||||
{
|
||||
totalCount = 1;
|
||||
|
||||
if (item.IsFolder || serverItem.StubType.HasValue)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -95,11 +95,6 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (BaseItem.ExtraSuffixes.Any(i => filename.IndexOf(i.Key, StringComparison.OrdinalIgnoreCase) != -1))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore samples
|
||||
|
|
|
@ -26,79 +26,5 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
".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,22 +466,10 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
/// </summary>
|
||||
/// <param name="args">The args.</param>
|
||||
/// <returns>BaseItem.</returns>
|
||||
public BaseItem ResolveItem(ItemResolveArgs args)
|
||||
private BaseItem ResolveItem(ItemResolveArgs args)
|
||||
{
|
||||
var item = EntityResolvers.Select(r =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return r.ResolvePath(args);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error in {0} resolving {1}", ex, r.GetType().Name, args.Path);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}).FirstOrDefault(i => i != null);
|
||||
var item = EntityResolvers.Select(r => Resolve(args, r))
|
||||
.FirstOrDefault(i => i != null);
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
|
@ -491,6 +479,19 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
return item;
|
||||
}
|
||||
|
||||
private BaseItem Resolve(ItemResolveArgs args, IItemResolver resolver)
|
||||
{
|
||||
try
|
||||
{
|
||||
return resolver.ResolvePath(args);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error in {0} resolving {1}", ex, resolver.GetType().Name, args.Path);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Guid GetNewItemId(string key, Type type)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
|
@ -565,7 +566,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
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)
|
||||
{
|
||||
|
@ -645,23 +646,50 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
return !args.ContainsFileSystemEntryByName(".ignore");
|
||||
}
|
||||
|
||||
public List<T> ResolvePaths<T>(IEnumerable<FileSystemInfo> files, IDirectoryService directoryService, Folder parent, string collectionType = null)
|
||||
where T : BaseItem
|
||||
public IEnumerable<BaseItem> ResolvePaths(IEnumerable<FileSystemInfo> files, IDirectoryService directoryService, Folder parent, string collectionType)
|
||||
{
|
||||
return files.Select(f =>
|
||||
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 fileList.Select(f =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return ResolvePath(f, directoryService, parent, collectionType) as T;
|
||||
return ResolvePath(f, directoryService, parent, collectionType);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error resolving path {0}", ex, f.FullName);
|
||||
return null;
|
||||
}
|
||||
|
||||
}).Where(i => i != null)
|
||||
.ToList();
|
||||
}).Where(i => i != null);
|
||||
}
|
||||
|
||||
/// <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)));
|
||||
}
|
||||
|
||||
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
|
||||
var dbItem = GetItemById(video.Id) as Video;
|
||||
|
@ -1775,27 +1805,29 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
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 =>
|
||||
{
|
||||
// Try to retrieve it from the db. If we don't find it, use the resolved version
|
||||
var dbItem = GetItemById(video.Id) as Video;
|
||||
|
||||
if (dbItem != null)
|
||||
return ResolvePaths(files, directoryService, null, null)
|
||||
.OfType<Video>()
|
||||
.Select(video =>
|
||||
{
|
||||
video = dbItem;
|
||||
}
|
||||
// Try to retrieve it from the db. If we don't find it, use the resolved version
|
||||
var dbItem = GetItemById(video.Id) as Video;
|
||||
|
||||
SetExtraTypeFromFilename(video);
|
||||
if (dbItem != null)
|
||||
{
|
||||
video = dbItem;
|
||||
}
|
||||
|
||||
return video;
|
||||
SetExtraTypeFromFilename(video);
|
||||
|
||||
// Sort them so that the list can be easily compared for changes
|
||||
}).OrderBy(i => i.Path).ToList();
|
||||
return video;
|
||||
|
||||
// Sort them so that the list can be easily compared for changes
|
||||
}).OrderBy(i => i.Path).ToList();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
@ -13,12 +14,55 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
/// </summary>
|
||||
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>
|
||||
/// Sets the initial item values.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="args">The args.</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)
|
||||
{
|
||||
// If the resolver didn't specify this
|
||||
|
@ -42,27 +86,26 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
}
|
||||
|
||||
// Make sure the item has a name
|
||||
EnsureName(item, args);
|
||||
EnsureName(item, args.FileInfo);
|
||||
|
||||
item.IsLocked = item.Path.IndexOf("[dontfetchmeta]", StringComparison.OrdinalIgnoreCase) != -1 ||
|
||||
item.Parents.Any(i => i.IsLocked);
|
||||
|
||||
// Make sure DateCreated and DateModified have values
|
||||
EntityResolutionHelper.EnsureDates(fileSystem, item, args, true);
|
||||
EnsureDates(fileSystem, item, args, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures the name.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="args">The arguments.</param>
|
||||
private static void EnsureName(BaseItem item, ItemResolveArgs args)
|
||||
/// <param name="fileInfo">The file information.</param>
|
||||
private static void EnsureName(BaseItem item, FileSystemInfo fileInfo)
|
||||
{
|
||||
// If the subclass didn't supply a name, add it here
|
||||
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(args.FileInfo.Name, (args.FileInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory);
|
||||
item.Name = GetDisplayName(fileInfo.Name, (fileInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,10 +117,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
/// <returns>System.String.</returns>
|
||||
private static string GetDisplayName(string path, bool isDirectory)
|
||||
{
|
||||
//first just get the file or directory name
|
||||
var fn = isDirectory ? Path.GetFileName(path) : Path.GetFileNameWithoutExtension(path);
|
||||
|
||||
return fn;
|
||||
return isDirectory ? Path.GetFileName(path) : Path.GetFileNameWithoutExtension(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -90,5 +130,79 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
var output = MbNameRegex.Replace(inputString, string.Empty).Trim();
|
||||
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.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Naming.Common;
|
||||
using MediaBrowser.Naming.Video;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
||||
{
|
||||
|
@ -29,7 +31,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
|||
/// <returns>`0.</returns>
|
||||
protected override T Resolve(ItemResolveArgs args)
|
||||
{
|
||||
return ResolveVideo<T>(args, true);
|
||||
return ResolveVideo<T>(args, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -96,14 +98,9 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
|||
|
||||
if (video != null)
|
||||
{
|
||||
if (parseName)
|
||||
{
|
||||
video.Name = videoInfo.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
video.Name = Path.GetFileName(args.Path);
|
||||
}
|
||||
video.Name = parseName ?
|
||||
videoInfo.Name :
|
||||
Path.GetFileName(args.Path);
|
||||
|
||||
Set3DFormat(video, videoInfo);
|
||||
}
|
||||
|
@ -119,50 +116,22 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
|||
return null;
|
||||
}
|
||||
|
||||
var isShortcut = string.Equals(videoInfo.Container, "strm", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
if (LibraryManager.IsVideoFile(args.Path) || videoInfo.IsStub || isShortcut)
|
||||
if (LibraryManager.IsVideoFile(args.Path) || videoInfo.IsStub)
|
||||
{
|
||||
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 video = new TVideoType
|
||||
{
|
||||
VideoType = type,
|
||||
Path = path,
|
||||
IsInMixedFolder = true,
|
||||
IsPlaceHolder = videoInfo.IsStub,
|
||||
IsShortcut = isShortcut,
|
||||
ProductionYear = videoInfo.Year
|
||||
};
|
||||
|
||||
if (parseName)
|
||||
{
|
||||
video.Name = videoInfo.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
video.Name = Path.GetFileNameWithoutExtension(path);
|
||||
}
|
||||
|
||||
if (videoInfo.IsStub)
|
||||
{
|
||||
if (string.Equals(videoInfo.StubType, "dvd", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
video.VideoType = VideoType.Dvd;
|
||||
}
|
||||
else if (string.Equals(videoInfo.StubType, "hddvd", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
video.VideoType = VideoType.HdDvd;
|
||||
}
|
||||
else if (string.Equals(videoInfo.StubType, "bluray", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
video.VideoType = VideoType.BluRay;
|
||||
}
|
||||
}
|
||||
SetVideoType(video, videoInfo);
|
||||
|
||||
video.Name = parseName ?
|
||||
videoInfo.Name :
|
||||
Path.GetFileNameWithoutExtension(args.Path);
|
||||
|
||||
Set3DFormat(video, videoInfo);
|
||||
|
||||
|
@ -173,41 +142,82 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
|||
return null;
|
||||
}
|
||||
|
||||
private void Set3DFormat(Video video, VideoFileInfo videoInfo)
|
||||
protected void SetVideoType(Video video, VideoFileInfo videoInfo)
|
||||
{
|
||||
if (videoInfo.Is3D)
|
||||
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 (string.Equals(videoInfo.Format3D, "fsbs", StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(videoInfo.StubType, "dvd", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
video.VideoType = VideoType.Dvd;
|
||||
}
|
||||
else if (string.Equals(videoInfo.StubType, "hddvd", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
video.VideoType = VideoType.HdDvd;
|
||||
}
|
||||
else if (string.Equals(videoInfo.StubType, "bluray", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
video.VideoType = VideoType.BluRay;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void Set3DFormat(Video video, bool is3D, string format3D)
|
||||
{
|
||||
if (is3D)
|
||||
{
|
||||
if (string.Equals(format3D, "fsbs", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
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;
|
||||
}
|
||||
else if (string.Equals(videoInfo.Format3D, "hsbs", StringComparison.OrdinalIgnoreCase))
|
||||
else if (string.Equals(format3D, "hsbs", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
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;
|
||||
}
|
||||
else if (string.Equals(videoInfo.Format3D, "sbs", StringComparison.OrdinalIgnoreCase))
|
||||
else if (string.Equals(format3D, "sbs", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
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;
|
||||
}
|
||||
else if (string.Equals(videoInfo.Format3D, "tab", StringComparison.OrdinalIgnoreCase))
|
||||
else if (string.Equals(format3D, "tab", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
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>
|
||||
/// Determines whether [is DVD directory] [the specified directory name].
|
||||
/// </summary>
|
||||
|
@ -227,5 +237,15 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
|||
{
|
||||
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.Library;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
@ -38,7 +37,8 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
|||
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
|
||||
{
|
||||
|
|
|
@ -2,12 +2,14 @@
|
|||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Controller.Resolvers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Naming.Common;
|
||||
using MediaBrowser.Naming.IO;
|
||||
using MediaBrowser.Naming.Video;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -19,13 +21,14 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
|||
/// <summary>
|
||||
/// Class MovieResolver
|
||||
/// </summary>
|
||||
public class MovieResolver : BaseVideoResolver<Video>
|
||||
public class MovieResolver : BaseVideoResolver<Video>, IMultiItemResolver
|
||||
{
|
||||
private readonly IServerApplicationPaths _applicationPaths;
|
||||
private readonly ILogger _logger;
|
||||
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;
|
||||
_logger = logger;
|
||||
|
@ -43,10 +46,107 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
|||
// Give plugins a chance to catch iso's first
|
||||
// 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
|
||||
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>
|
||||
/// Resolves the specified args.
|
||||
/// </summary>
|
||||
|
@ -54,28 +154,24 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
|||
/// <returns>Video.</returns>
|
||||
protected override Video Resolve(ItemResolveArgs args)
|
||||
{
|
||||
// Avoid expensive tests against VF's and all their children by not allowing this
|
||||
if (args.Parent != null)
|
||||
{
|
||||
if (args.Parent.IsRoot)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
var collectionType = args.GetCollectionType();
|
||||
|
||||
if (IsInvalid(args.Parent, collectionType, args.FileSystemChildren))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Find movies with their own folders
|
||||
if (args.IsDirectory)
|
||||
{
|
||||
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))
|
||||
{
|
||||
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))
|
||||
|
@ -83,7 +179,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
|||
// Owned items should just use the plain video type
|
||||
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
|
||||
|
@ -91,22 +187,21 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
|||
{
|
||||
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) ||
|
||||
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;
|
||||
}
|
||||
|
||||
var filename = Path.GetFileName(args.Path);
|
||||
// Don't misidentify extras or trailers
|
||||
if (BaseItem.ExtraSuffixes.Any(i => filename.IndexOf(i.Key, StringComparison.OrdinalIgnoreCase) != -1))
|
||||
// Owned items will be caught by the plain video resolver
|
||||
if (args.Parent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -115,7 +210,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
|||
|
||||
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
|
||||
|
@ -124,7 +219,16 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
|||
{
|
||||
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)
|
||||
{
|
||||
item.IsInMixedFolder = true;
|
||||
|
@ -170,17 +274,14 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
|||
/// <param name="parent">The parent.</param>
|
||||
/// <param name="fileSystemEntries">The file system entries.</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>
|
||||
/// <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()
|
||||
{
|
||||
var movies = new List<T>();
|
||||
|
||||
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)
|
||||
{
|
||||
var filename = child.Name;
|
||||
|
@ -189,76 +290,59 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
|||
{
|
||||
if (IsDvdDirectory(filename))
|
||||
{
|
||||
return new T
|
||||
var movie = new T
|
||||
{
|
||||
Path = path,
|
||||
VideoType = VideoType.Dvd
|
||||
};
|
||||
Set3DFormat(movie);
|
||||
return movie;
|
||||
}
|
||||
if (IsBluRayDirectory(filename))
|
||||
{
|
||||
return new T
|
||||
var movie = new T
|
||||
{
|
||||
Path = path,
|
||||
VideoType = VideoType.BluRay
|
||||
};
|
||||
Set3DFormat(movie);
|
||||
return movie;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
FileInfo = child,
|
||||
Path = child.FullName,
|
||||
Parent = parent,
|
||||
CollectionType = collectionType
|
||||
};
|
||||
|
||||
var item = ResolveVideo<T>(childArgs, true);
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
item.IsInMixedFolder = false;
|
||||
movies.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
var result = ResolveVideos<T>(parent, fileSystemEntries, directoryService, collectionType);
|
||||
|
||||
if (movies.Count > 1)
|
||||
// Test for multi-editions
|
||||
if (result.Items.Count > 1)
|
||||
{
|
||||
var multiFileResult = GetMultiFileMovie(movies);
|
||||
var filenamePrefix = Path.GetFileName(path);
|
||||
|
||||
if (multiFileResult != null)
|
||||
if (!string.IsNullOrWhiteSpace(filenamePrefix))
|
||||
{
|
||||
return multiFileResult;
|
||||
}
|
||||
|
||||
if (supportsMultipleSources)
|
||||
{
|
||||
var result = GetMovieWithMultipleSources(movies);
|
||||
|
||||
if (result != null)
|
||||
if (result.Items.All(i => _fileSystem.GetFileNameWithoutExtension(i.Path).StartsWith(filenamePrefix + " - ", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return result;
|
||||
var movie = (T)result.Items[0];
|
||||
movie.Name = filenamePrefix;
|
||||
movie.LocalAlternateVersions = result.Items.Skip(1).Select(i => i.Path).ToList();
|
||||
|
||||
_logger.Debug("Multi-version video found: " + movie.Path);
|
||||
|
||||
return movie;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
@ -318,7 +402,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return new T
|
||||
{
|
||||
Path = folderPaths[0],
|
||||
|
@ -331,65 +415,42 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
|||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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()
|
||||
private bool IsInvalid(Folder parent, string collectionType, IEnumerable<FileSystemInfo> files)
|
||||
{
|
||||
var sortedMovies = movies.OrderBy(i => i.Path).ToList();
|
||||
|
||||
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)
|
||||
if (parent != null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
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)
|
||||
where T : Video, new()
|
||||
{
|
||||
var sortedMovies = movies.OrderBy(i => i.Path).ToList();
|
||||
|
||||
// Cap this at five to help avoid incorrect matching
|
||||
if (sortedMovies.Count > 5)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var firstMovie = sortedMovies[0];
|
||||
|
||||
var filenamePrefix = Path.GetFileName(Path.GetDirectoryName(firstMovie.Path));
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(filenamePrefix))
|
||||
{
|
||||
if (sortedMovies.All(i => _fileSystem.GetFileNameWithoutExtension(i.Path).StartsWith(filenamePrefix + " - ", StringComparison.OrdinalIgnoreCase)))
|
||||
if (parent.IsRoot)
|
||||
{
|
||||
firstMovie.LocalAlternateVersions = sortedMovies.Skip(1).Select(i => i.Path).ToList();
|
||||
|
||||
_logger.Debug("Multi-version video found: " + firstMovie.Path);
|
||||
|
||||
return firstMovie;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
// Don't do any resolving within a series structure
|
||||
if (string.IsNullOrEmpty(collectionType))
|
||||
{
|
||||
if (parent is Season || parent is Series)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 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))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// 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
|
||||
{
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
using System;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Resolvers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System.Linq;
|
||||
|
||||
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 (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);
|
||||
|
||||
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.Audio;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
|
@ -84,7 +83,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
|
|||
return new Series
|
||||
{
|
||||
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.Library;
|
||||
using MediaBrowser.Controller.Resolvers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
||||
{
|
||||
|
@ -22,22 +19,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
|||
if (args.Parent != null)
|
||||
{
|
||||
// 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);
|
||||
|
@ -52,6 +34,4 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
|||
get { return ResolverPriority.Last; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
</Reference>
|
||||
<Reference Include="MediaBrowser.Naming, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<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 Include="Mono.Nat, Version=1.2.21.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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="morelinq" version="1.1.0" targetFramework="net45" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user