aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Library/Resolvers
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2014-12-14 00:38:07 -0500
committerLuke <luke.pulverenti@gmail.com>2014-12-14 00:38:07 -0500
commit524293ea79ab61228f8326561be70bcca4d0ea8f (patch)
treeccfe163c8edafc8dd14b0b63d48712a6d504de9d /MediaBrowser.Server.Implementations/Library/Resolvers
parent00da34b90a2f2fcee4d6aa584e25fccebb375b6d (diff)
parent9df9723fa8554df0fd51d777d3f781b0136de926 (diff)
Merge pull request #954 from MediaBrowser/dev
3.0.5462.0
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers')
-rw-r--r--MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs11
-rw-r--r--MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs6
-rw-r--r--MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs261
-rw-r--r--MediaBrowser.Server.Implementations/Library/Resolvers/LocalTrailerResolver.cs61
-rw-r--r--MediaBrowser.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs12
-rw-r--r--MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs391
-rw-r--r--MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs4
-rw-r--r--MediaBrowser.Server.Implementations/Library/Resolvers/PlaylistResolver.cs6
-rw-r--r--MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs33
-rw-r--r--MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs45
-rw-r--r--MediaBrowser.Server.Implementations/Library/Resolvers/VideoResolver.cs18
11 files changed, 461 insertions, 387 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs
index 62eb1f47d..b4cda39cd 100644
--- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs
+++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs
@@ -41,10 +41,19 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
{
var collectionType = args.GetCollectionType();
+ var isMixed = string.IsNullOrWhiteSpace(collectionType);
+
+ // For conflicting extensions, give priority to videos
+ if (isMixed && _libraryManager.IsVideoFile(args.Path))
+ {
+ return null;
+ }
+
var isStandalone = args.Parent == null;
if (isStandalone ||
- string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase))
+ string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase) ||
+ isMixed)
{
return new Controller.Entities.Audio.Audio();
}
diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs
index 5ba07cdae..7f844ca0e 100644
--- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs
+++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs
@@ -141,12 +141,6 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
if (libraryManager.IsAudioFile(fullName))
{
- // Don't resolve these into audio files
- if (string.Equals(fileSystem.GetFileNameWithoutExtension(fullName), BaseItem.ThemeSongFilename))
- {
- continue;
- }
-
return true;
}
}
diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs
index 1b4903641..8e2218b0a 100644
--- a/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs
+++ b/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs
@@ -1,10 +1,12 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Naming.Audio;
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);
+ return ResolveVideo<T>(args, false);
}
/// <summary>
@@ -37,14 +39,93 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
/// </summary>
/// <typeparam name="TVideoType">The type of the T video type.</typeparam>
/// <param name="args">The args.</param>
+ /// <param name="parseName">if set to <c>true</c> [parse name].</param>
/// <returns>``0.</returns>
- protected TVideoType ResolveVideo<TVideoType>(ItemResolveArgs args)
+ protected TVideoType ResolveVideo<TVideoType>(ItemResolveArgs args, bool parseName)
where TVideoType : Video, new()
{
// If the path is a file check for a matching extensions
- if (!args.IsDirectory)
+ var parser = new Naming.Video.VideoResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger());
+
+ if (args.IsDirectory)
+ {
+ TVideoType video = null;
+ VideoFileInfo videoInfo = null;
+
+ // Loop through each child file/folder and see if we find a video
+ foreach (var child in args.FileSystemChildren)
+ {
+ var filename = child.Name;
+
+ if ((child.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
+ {
+ if (IsDvdDirectory(filename))
+ {
+ videoInfo = parser.ResolveDirectory(args.Path);
+
+ if (videoInfo == null)
+ {
+ return null;
+ }
+
+ video = new TVideoType
+ {
+ Path = args.Path,
+ VideoType = VideoType.Dvd,
+ ProductionYear = videoInfo.Year
+ };
+ break;
+ }
+ if (IsBluRayDirectory(filename))
+ {
+ videoInfo = parser.ResolveDirectory(args.Path);
+
+ if (videoInfo == null)
+ {
+ return null;
+ }
+
+ video = new TVideoType
+ {
+ Path = args.Path,
+ VideoType = VideoType.BluRay,
+ ProductionYear = videoInfo.Year
+ };
+ break;
+ }
+ }
+ else if (IsDvdFile(filename))
+ {
+ videoInfo = parser.ResolveDirectory(args.Path);
+
+ if (videoInfo == null)
+ {
+ return null;
+ }
+
+ video = new TVideoType
+ {
+ Path = args.Path,
+ VideoType = VideoType.Dvd,
+ ProductionYear = videoInfo.Year
+ };
+ break;
+ }
+ }
+
+ if (video != null)
+ {
+ video.Name = parseName ?
+ videoInfo.Name :
+ Path.GetFileName(args.Path);
+
+ Set3DFormat(video, videoInfo);
+ }
+
+ return video;
+ }
+ else
{
- var parser = new Naming.Video.VideoResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger());
var videoInfo = parser.ResolveFile(args.Path);
if (videoInfo == null)
@@ -52,74 +133,24 @@ 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,
- Name = videoInfo.Name,
ProductionYear = videoInfo.Year
};
- 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);
- if (videoInfo.Is3D)
- {
- if (string.Equals(videoInfo.Format3D, "fsbs", StringComparison.OrdinalIgnoreCase))
- {
- video.Video3DFormat = Video3DFormat.FullSideBySide;
- }
- else if (string.Equals(videoInfo.Format3D, "ftab", StringComparison.OrdinalIgnoreCase))
- {
- video.Video3DFormat = Video3DFormat.FullTopAndBottom;
- }
- else if (string.Equals(videoInfo.Format3D, "hsbs", StringComparison.OrdinalIgnoreCase))
- {
- video.Video3DFormat = Video3DFormat.HalfSideBySide;
- }
- else if (string.Equals(videoInfo.Format3D, "htab", StringComparison.OrdinalIgnoreCase))
- {
- video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
- }
- else if (string.Equals(videoInfo.Format3D, "sbs", StringComparison.OrdinalIgnoreCase))
- {
- video.Video3DFormat = Video3DFormat.HalfSideBySide;
- }
- else if (string.Equals(videoInfo.Format3D, "sbs3d", StringComparison.OrdinalIgnoreCase))
- {
- video.Video3DFormat = Video3DFormat.HalfSideBySide;
- }
- else if (string.Equals(videoInfo.Format3D, "tab", StringComparison.OrdinalIgnoreCase))
- {
- video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
- }
- }
+ Set3DFormat(video, videoInfo);
return video;
}
@@ -127,5 +158,111 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
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 (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(format3D, "ftab", StringComparison.OrdinalIgnoreCase))
+ {
+ video.Video3DFormat = Video3DFormat.FullTopAndBottom;
+ }
+ else if (string.Equals(format3D, "hsbs", StringComparison.OrdinalIgnoreCase))
+ {
+ video.Video3DFormat = Video3DFormat.HalfSideBySide;
+ }
+ else if (string.Equals(format3D, "htab", StringComparison.OrdinalIgnoreCase))
+ {
+ video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
+ }
+ else if (string.Equals(format3D, "sbs", StringComparison.OrdinalIgnoreCase))
+ {
+ video.Video3DFormat = Video3DFormat.HalfSideBySide;
+ }
+ else if (string.Equals(format3D, "sbs3d", StringComparison.OrdinalIgnoreCase))
+ {
+ video.Video3DFormat = Video3DFormat.HalfSideBySide;
+ }
+ 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>
+ /// <param name="directoryName">Name of the directory.</param>
+ /// <returns><c>true</c> if [is DVD directory] [the specified directory name]; otherwise, <c>false</c>.</returns>
+ protected bool IsDvdDirectory(string directoryName)
+ {
+ return string.Equals(directoryName, "video_ts", StringComparison.OrdinalIgnoreCase);
+ }
+
+ /// <summary>
+ /// Determines whether [is DVD file] [the specified name].
+ /// </summary>
+ /// <param name="name">The name.</param>
+ /// <returns><c>true</c> if [is DVD file] [the specified name]; otherwise, <c>false</c>.</returns>
+ protected bool IsDvdFile(string name)
+ {
+ return string.Equals(name, "video_ts.ifo", StringComparison.OrdinalIgnoreCase);
+ }
+
+ /// <summary>
+ /// Determines whether [is blu ray directory] [the specified directory name].
+ /// </summary>
+ /// <param name="directoryName">Name of the directory.</param>
+ /// <returns><c>true</c> if [is blu ray directory] [the specified directory name]; otherwise, <c>false</c>.</returns>
+ protected bool IsBluRayDirectory(string directoryName)
+ {
+ return string.Equals(directoryName, "bdmv", StringComparison.OrdinalIgnoreCase);
+ }
}
}
diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/LocalTrailerResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/LocalTrailerResolver.cs
deleted file mode 100644
index dfeefb74f..000000000
--- a/MediaBrowser.Server.Implementations/Library/Resolvers/LocalTrailerResolver.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-using MediaBrowser.Common.IO;
-using MediaBrowser.Controller.Entities;
-using MediaBrowser.Controller.Library;
-using MediaBrowser.Controller.Resolvers;
-using MediaBrowser.Model.Entities;
-using System;
-using System.IO;
-using System.Linq;
-
-namespace MediaBrowser.Server.Implementations.Library.Resolvers
-{
- /// <summary>
- /// Class LocalTrailerResolver
- /// </summary>
- public class LocalTrailerResolver : BaseVideoResolver<Trailer>
- {
- private readonly IFileSystem _fileSystem;
-
- public LocalTrailerResolver(ILibraryManager libraryManager, IFileSystem fileSystem) : base(libraryManager)
- {
- _fileSystem = fileSystem;
- }
-
- /// <summary>
- /// Resolves the specified args.
- /// </summary>
- /// <param name="args">The args.</param>
- /// <returns>Trailer.</returns>
- protected override Trailer Resolve(ItemResolveArgs args)
- {
- // Trailers are not Children, therefore this can never happen
- if (args.Parent != null)
- {
- return null;
- }
-
- // If the file is within a trailers folder, see if the VideoResolver returns something
- if (!args.IsDirectory)
- {
- if (string.Equals(Path.GetFileName(Path.GetDirectoryName(args.Path)), BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase))
- {
- return base.Resolve(args);
- }
-
- // Support xbmc local trailer convention, but only when looking for local trailers (hence the parent == null check)
- if (args.Parent == null)
- {
- var nameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(args.Path);
- var suffix = BaseItem.ExtraSuffixes.First(i => i.Value == ExtraType.Trailer);
-
- if (nameWithoutExtension.EndsWith(suffix.Key, StringComparison.OrdinalIgnoreCase))
- {
- return base.Resolve(args);
- }
- }
- }
-
- return null;
- }
- }
-}
diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs
index 1416bd04e..cc261c3e7 100644
--- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs
+++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs
@@ -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,9 +37,14 @@ 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 { Path = args.Path };
+ return new BoxSet
+ {
+ Path = args.Path,
+ Name = ResolverHelper.StripBrackets(Path.GetFileName(args.Path))
+ };
}
}
diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs
index a2da9ff77..9f714cfc5 100644
--- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs
+++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs
@@ -1,33 +1,34 @@
-using MediaBrowser.Common.Extensions;
-using MediaBrowser.Common.IO;
+using MediaBrowser.Common.IO;
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;
using System.IO;
using System.Linq;
-using MediaBrowser.Naming.Audio;
-using MediaBrowser.Naming.Common;
-using MediaBrowser.Naming.Video;
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;
@@ -45,93 +46,189 @@ 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;
}
}
- /// <summary>
- /// Resolves the specified args.
- /// </summary>
- /// <param name="args">The args.</param>
- /// <returns>Video.</returns>
- protected override Video Resolve(ItemResolveArgs args)
+ public MultiItemResolverResult ResolveMultiple(Folder parent,
+ List<FileSystemInfo> files,
+ string collectionType,
+ IDirectoryService directoryService)
{
- // Avoid expensive tests against VF's and all their children by not allowing this
- if (args.Parent != null)
+ 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))
{
- if (args.Parent.IsRoot)
+ // Owned items should just use the plain video type
+ if (parent == null)
{
- return 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);
}
- var isDirectory = args.IsDirectory;
+ 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>();
- if (isDirectory)
+ // Loop through each child file/folder and see if we find a video
+ foreach (var child in fileSystemEntries)
{
- // Since the looping is expensive, this is an optimization to help us avoid it
- if (args.ContainsMetaFileByName("series.xml"))
+ if ((child.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
+ {
+ leftOver.Add(child);
+ }
+ else
{
- return null;
+ 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()).ToList();
+
+ var result = new MultiItemResolverResult
+ {
+ ExtraFiles = leftOver,
+ Items = videos
+ };
+
+ var isInMixedFolder = resolverResult.Count > 0;
+
+ foreach (var video in resolverResult)
+ {
+ var firstVideo = video.Files.First();
+
+ var videoItem = new T
+ {
+ Path = video.Files[0].Path,
+ IsInMixedFolder = isInMixedFolder,
+ 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>
+ /// <param name="args">The args.</param>
+ /// <returns>Video.</returns>
+ protected override Video Resolve(ItemResolveArgs args)
+ {
var collectionType = args.GetCollectionType();
+ if (IsInvalid(args.Parent, collectionType, args.FileSystemChildren))
+ {
+ return null;
+ }
+
// Find movies with their own folders
- if (isDirectory)
+ if (args.IsDirectory)
{
- if (string.Equals(collectionType, CollectionType.Trailers, StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
{
- return FindMovie<Trailer>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, false, false, collectionType);
+ return FindMovie<MusicVideo>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType, false);
}
- if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
{
- return FindMovie<MusicVideo>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, false, false, collectionType);
+ return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType, false);
}
- if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
+ if (string.IsNullOrEmpty(collectionType))
{
- return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, true, false, collectionType);
+ // 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, collectionType);
+ }
+
+ // Since the looping is expensive, this is an optimization to help us avoid it
+ if (args.ContainsMetaFileByName("series.xml"))
+ {
+ return null;
+ }
+
+ return FindMovie<Movie>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType);
}
- if (string.IsNullOrEmpty(collectionType) ||
- string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) ||
- string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
+ 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, 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;
}
- // Find movies that are mixed in the same folder
- if (string.Equals(collectionType, CollectionType.Trailers, StringComparison.OrdinalIgnoreCase))
- {
- return ResolveVideo<Trailer>(args);
- }
-
Video item = null;
if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
{
- item = ResolveVideo<MusicVideo>(args);
+ item = ResolveVideo<MusicVideo>(args, false);
}
// To find a movie file, the collection type must be movies or boxsets
- // Otherwise we'll consider it a plain video and let the video resolver handle it
- if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) ||
+ else if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) ||
string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
{
- item = ResolveVideo<Movie>(args);
+ 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)
@@ -179,16 +276,15 @@ 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="supportMultiFileItems">if set to <c>true</c> [support multi file items].</param>
+ /// <param name="collectionType">Type of the collection.</param>
+ /// <param name="supportMultiVersion">if set to <c>true</c> [support multi version].</param>
/// <returns>Movie.</returns>
- private T FindMovie<T>(string path, Folder parent, List<FileSystemInfo> fileSystemEntries, IDirectoryService directoryService, bool supportMultiFileItems, bool supportsMultipleSources, string collectionType)
+ private T FindMovie<T>(string path, Folder parent, List<FileSystemInfo> fileSystemEntries, IDirectoryService directoryService, string collectionType, bool supportMultiVersion = true)
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;
@@ -197,78 +293,70 @@ 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)
+ else if (IsDvdFile(filename))
{
- FileInfo = child,
- Path = child.FullName,
- Parent = parent,
- CollectionType = collectionType
- };
-
- var item = ResolveVideo<T>(childArgs);
-
- if (item != null)
- {
- item.IsInMixedFolder = false;
- movies.Add(item);
+ var movie = new T
+ {
+ Path = path,
+ VideoType = VideoType.Dvd
+ };
+ Set3DFormat(movie);
+ return movie;
}
}
+
+ var result = ResolveVideos<T>(parent, fileSystemEntries, directoryService, collectionType);
- if (movies.Count > 1)
+ // Test for multi-editions
+ if (result.Items.Count > 1 && supportMultiVersion)
{
- if (supportMultiFileItems)
- {
- var result = GetMultiFileMovie(movies);
+ var filenamePrefix = Path.GetFileName(path);
- if (result != null)
- {
- return result;
- }
- }
- if (supportsMultipleSources)
+ if (!string.IsNullOrWhiteSpace(filenamePrefix))
{
- 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();
+ movie.IsInMixedFolder = false;
+
+ _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);
}
@@ -290,7 +378,11 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
var folderPaths = multiDiscFolders.Select(i => i.FullName).Where(i =>
{
- var subfolders = directoryService.GetDirectories(i)
+ var subFileEntries = directoryService.GetFileSystemEntries(i)
+ .ToList();
+
+ var subfolders = subFileEntries
+ .Where(e => (e.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
.Select(d => d.Name)
.ToList();
@@ -305,6 +397,16 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
return true;
}
+ var subFiles = subFileEntries
+ .Where(e => (e.Attributes & FileAttributes.Directory) != FileAttributes.Directory)
+ .Select(d => d.Name);
+
+ if (subFiles.Any(IsDvdFile))
+ {
+ videoTypes.Add(VideoType.Dvd);
+ return true;
+ }
+
return false;
}).OrderBy(i => i).ToList();
@@ -328,12 +430,12 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
{
return null;
}
-
+
return new T
{
Path = folderPaths[0],
- IsMultiPart = true,
+ AdditionalParts = folderPaths.Skip(1).ToList(),
VideoType = videoTypes[0],
@@ -341,85 +443,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)
- {
- return null;
- }
-
- firstMovie.IsMultiPart = true;
- 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)
+ if (parent != null)
{
- return null;
+ if (parent.IsRoot)
+ {
+ return true;
+ }
}
- var firstMovie = sortedMovies[0];
-
- var filenamePrefix = Path.GetFileName(Path.GetDirectoryName(firstMovie.Path));
-
- if (!string.IsNullOrWhiteSpace(filenamePrefix))
+ // Don't do any resolving within a series structure
+ if (string.IsNullOrEmpty(collectionType))
{
- if (sortedMovies.All(i => _fileSystem.GetFileNameWithoutExtension(i.Path).StartsWith(filenamePrefix + " - ", StringComparison.OrdinalIgnoreCase)))
+ if (parent is Season || parent is Series)
{
- firstMovie.HasLocalAlternateVersions = true;
-
- _logger.Debug("Multi-version video found: " + firstMovie.Path);
+ return true;
+ }
- return firstMovie;
+ // 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;
}
}
- return null;
- }
-
- /// <summary>
- /// Determines whether [is DVD directory] [the specified directory name].
- /// </summary>
- /// <param name="directoryName">Name of the directory.</param>
- /// <returns><c>true</c> if [is DVD directory] [the specified directory name]; otherwise, <c>false</c>.</returns>
- private bool IsDvdDirectory(string directoryName)
- {
- return string.Equals(directoryName, "video_ts", StringComparison.OrdinalIgnoreCase);
- }
+ var validCollectionTypes = new[]
+ {
+ string.Empty,
+ CollectionType.Movies,
+ CollectionType.HomeVideos,
+ CollectionType.MusicVideos,
+ CollectionType.BoxSets,
+ CollectionType.Movies
+ };
- /// <summary>
- /// Determines whether [is blu ray directory] [the specified directory name].
- /// </summary>
- /// <param name="directoryName">Name of the directory.</param>
- /// <returns><c>true</c> if [is blu ray directory] [the specified directory name]; otherwise, <c>false</c>.</returns>
- private bool IsBluRayDirectory(string directoryName)
- {
- return string.Equals(directoryName, "bdmv", StringComparison.OrdinalIgnoreCase);
+ return !validCollectionTypes.Contains(collectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
}
}
}
diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs
index e3fe37be8..5580b442c 100644
--- a/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs
+++ b/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs
@@ -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
{
diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/PlaylistResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/PlaylistResolver.cs
index 7eff53ce1..a95739f22 100644
--- a/MediaBrowser.Server.Implementations/Library/Resolvers/PlaylistResolver.cs
+++ b/MediaBrowser.Server.Implementations/Library/Resolvers/PlaylistResolver.cs
@@ -28,7 +28,11 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
if (filename.IndexOf("[playlist]", StringComparison.OrdinalIgnoreCase) != -1)
{
- return new Playlist { Path = args.Path };
+ return new Playlist
+ {
+ Path = args.Path,
+ Name = ResolverHelper.StripBrackets(Path.GetFileName(args.Path))
+ };
}
}
diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs
index 839b14a9e..057425ca9 100644
--- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs
+++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs
@@ -1,7 +1,5 @@
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
@@ -41,39 +39,10 @@ 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())
{
- Episode episode = null;
-
- if (args.IsDirectory)
- {
- if (args.ContainsFileSystemEntryByName("video_ts"))
- {
- episode = new Episode
- {
- Path = args.Path,
- VideoType = VideoType.Dvd
- };
- }
- if (args.ContainsFileSystemEntryByName("bdmv"))
- {
- episode = new Episode
- {
- Path = args.Path,
- VideoType = VideoType.BluRay
- };
- }
- }
-
- if (episode == null)
- {
- episode = base.Resolve(args);
- }
+ var episode = ResolveVideo<Episode>(args, false);
if (episode != null)
{
- // The base video resolver is going to fill these in, so null them out
- episode.ProductionYear = null;
- episode.Name = null;
-
if (season != null)
{
episode.ParentIndexNumber = season.IndexNumber;
diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs
index 30eaf3198..ce7491524 100644
--- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs
+++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs
@@ -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;
@@ -81,7 +80,11 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
if (IsSeriesFolder(args.Path, isTvShowsFolder, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger, _libraryManager))
{
- return new Series();
+ return new Series
+ {
+ Path = args.Path,
+ Name = Path.GetFileName(args.Path)
+ };
}
}
@@ -96,12 +99,11 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
/// <param name="fileSystemChildren">The file system children.</param>
/// <param name="directoryService">The directory service.</param>
/// <param name="fileSystem">The file system.</param>
+ /// <param name="logger">The logger.</param>
+ /// <param name="libraryManager">The library manager.</param>
/// <returns><c>true</c> if [is series folder] [the specified path]; otherwise, <c>false</c>.</returns>
public static bool IsSeriesFolder(string path, bool considerSeasonlessEntries, IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService, IFileSystem fileSystem, ILogger logger, ILibraryManager libraryManager)
{
- // A folder with more than 3 non-season folders in will not becounted as a series
- var nonSeriesFolders = 0;
-
foreach (var child in fileSystemChildren)
{
var attributes = child.Attributes;
@@ -126,19 +128,6 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
//logger.Debug("{0} is a series because of season folder {1}.", path, child.FullName);
return true;
}
-
- if (IsBadFolder(child.Name))
- {
- logger.Debug("Invalid folder under series: {0}", child.FullName);
-
- nonSeriesFolders++;
- }
-
- if (nonSeriesFolders >= 3)
- {
- logger.Debug("{0} not a series due to 3 or more invalid folders.", path);
- return false;
- }
}
else
{
@@ -176,24 +165,6 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
return string.Equals(extension, ".disc", StringComparison.OrdinalIgnoreCase);
}
- private static bool IsBadFolder(string name)
- {
- if (string.Equals(name, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
- {
- return false;
- }
- if (string.Equals(name, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
- {
- return false;
- }
- if (string.Equals(name, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase))
- {
- return false;
- }
-
- return !EntityResolutionHelper.IgnoreFolders.Contains(name, StringComparer.OrdinalIgnoreCase);
- }
-
/// <summary>
/// Determines whether [is season folder] [the specified path].
/// </summary>
diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/VideoResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/VideoResolver.cs
index cde75aea2..97682db66 100644
--- a/MediaBrowser.Server.Implementations/Library/Resolvers/VideoResolver.cs
+++ b/MediaBrowser.Server.Implementations/Library/Resolvers/VideoResolver.cs
@@ -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
{
@@ -21,17 +18,8 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
{
if (args.Parent != null)
{
- var collectionType = args.GetCollectionType() ?? string.Empty;
- var accepted = new[]
- {
- string.Empty,
- CollectionType.HomeVideos
- };
-
- if (!accepted.Contains(collectionType, StringComparer.OrdinalIgnoreCase))
- {
- return null;
- }
+ // The movie resolver will handle this
+ return null;
}
return base.Resolve(args);
@@ -46,6 +34,4 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
get { return ResolverPriority.Last; }
}
}
-
-
}