2014-12-03 03:13:03 +00:00
|
|
|
|
using MediaBrowser.Common.IO;
|
2013-03-04 05:43:06 +00:00
|
|
|
|
using MediaBrowser.Controller;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-02-13 05:11:54 +00:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-03-03 16:53:58 +00:00
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2014-07-13 04:55:56 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2014-11-29 19:51:30 +00:00
|
|
|
|
using MediaBrowser.Naming.Common;
|
2014-12-04 05:24:41 +00:00
|
|
|
|
using MediaBrowser.Naming.IO;
|
2014-11-29 19:51:30 +00:00
|
|
|
|
using MediaBrowser.Naming.Video;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2013-06-12 21:46:50 +00:00
|
|
|
|
using System.Linq;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-03-03 06:58:04 +00:00
|
|
|
|
namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class MovieResolver
|
|
|
|
|
/// </summary>
|
2014-12-04 05:24:41 +00:00
|
|
|
|
public class MovieResolver : BaseVideoResolver<Video>, IMultiItemResolver
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-09-04 17:07:35 +00:00
|
|
|
|
private readonly IServerApplicationPaths _applicationPaths;
|
2014-03-15 22:52:43 +00:00
|
|
|
|
private readonly ILogger _logger;
|
2014-07-26 17:30:15 +00:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
2013-06-12 21:46:50 +00:00
|
|
|
|
|
2014-12-04 05:24:41 +00:00
|
|
|
|
public MovieResolver(ILibraryManager libraryManager, IServerApplicationPaths applicationPaths, ILogger logger, IFileSystem fileSystem)
|
|
|
|
|
: base(libraryManager)
|
2013-03-04 05:43:06 +00:00
|
|
|
|
{
|
2014-11-16 20:44:08 +00:00
|
|
|
|
_applicationPaths = applicationPaths;
|
2014-03-15 22:52:43 +00:00
|
|
|
|
_logger = logger;
|
2014-07-26 17:30:15 +00:00
|
|
|
|
_fileSystem = fileSystem;
|
2013-03-04 05:43:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the priority.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The priority.</value>
|
|
|
|
|
public override ResolverPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// 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
|
2014-12-04 05:24:41 +00:00
|
|
|
|
// Also run after series resolver
|
|
|
|
|
return ResolverPriority.Third;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-04 05:24:41 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-22 06:50:29 +00:00
|
|
|
|
return ResolveVideos<Video>(parent, files, directoryService, collectionType);
|
2014-12-04 05:24:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-19 04:20:07 +00:00
|
|
|
|
if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
|
2014-12-04 05:24:41 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
|
2014-12-19 04:20:07 +00:00
|
|
|
|
}).ToList(), false).ToList();
|
2014-12-04 05:24:41 +00:00
|
|
|
|
|
|
|
|
|
var result = new MultiItemResolverResult
|
|
|
|
|
{
|
|
|
|
|
ExtraFiles = leftOver,
|
|
|
|
|
Items = videos
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-09 04:57:18 +00:00
|
|
|
|
var isInMixedFolder = resolverResult.Count > 0;
|
|
|
|
|
|
2014-12-04 05:24:41 +00:00
|
|
|
|
foreach (var video in resolverResult)
|
|
|
|
|
{
|
|
|
|
|
var firstVideo = video.Files.First();
|
|
|
|
|
|
|
|
|
|
var videoItem = new T
|
|
|
|
|
{
|
|
|
|
|
Path = video.Files[0].Path,
|
2014-12-09 04:57:18 +00:00
|
|
|
|
IsInMixedFolder = isInMixedFolder,
|
2014-12-04 05:24:41 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Resolves the specified args.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="args">The args.</param>
|
2013-05-28 01:59:26 +00:00
|
|
|
|
/// <returns>Video.</returns>
|
|
|
|
|
protected override Video Resolve(ItemResolveArgs args)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2014-12-04 05:24:41 +00:00
|
|
|
|
var collectionType = args.GetCollectionType();
|
|
|
|
|
|
|
|
|
|
if (IsInvalid(args.Parent, collectionType, args.FileSystemChildren))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2014-12-04 05:24:41 +00:00
|
|
|
|
return null;
|
2013-08-15 15:25:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-15 16:00:39 +00:00
|
|
|
|
// Find movies with their own folders
|
2014-12-03 03:13:03 +00:00
|
|
|
|
if (args.IsDirectory)
|
2013-08-15 15:25:51 +00:00
|
|
|
|
{
|
2014-03-12 02:11:01 +00:00
|
|
|
|
if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
|
2013-05-28 01:59:26 +00:00
|
|
|
|
{
|
2014-12-19 04:20:07 +00:00
|
|
|
|
return FindMovie<MusicVideo>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType);
|
2013-07-12 19:56:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-29 05:32:03 +00:00
|
|
|
|
if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2014-12-19 04:20:07 +00:00
|
|
|
|
return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType);
|
2013-12-29 05:32:03 +00:00
|
|
|
|
}
|
2014-03-15 22:52:43 +00:00
|
|
|
|
|
2014-12-03 03:13:03 +00:00
|
|
|
|
if (string.IsNullOrEmpty(collectionType))
|
2013-07-12 19:56:40 +00:00
|
|
|
|
{
|
2014-12-03 03:13:03 +00:00
|
|
|
|
// Owned items should just use the plain video type
|
|
|
|
|
if (args.Parent == null)
|
|
|
|
|
{
|
2014-12-04 05:24:41 +00:00
|
|
|
|
return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType);
|
2014-12-03 03:13:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-28 06:21:39 +00:00
|
|
|
|
return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType);
|
2013-05-28 01:59:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-19 04:20:07 +00:00
|
|
|
|
if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
|
2014-12-03 03:13:03 +00:00
|
|
|
|
{
|
2014-12-04 05:24:41 +00:00
|
|
|
|
return FindMovie<Movie>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType);
|
2014-12-03 03:13:03 +00:00
|
|
|
|
}
|
2014-12-04 05:24:41 +00:00
|
|
|
|
|
2013-08-29 21:00:27 +00:00
|
|
|
|
return null;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-04 05:24:41 +00:00
|
|
|
|
// Owned items will be caught by the plain video resolver
|
|
|
|
|
if (args.Parent == null)
|
2013-12-08 18:07:58 +00:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-15 16:00:39 +00:00
|
|
|
|
Video item = null;
|
|
|
|
|
|
2014-03-31 21:04:22 +00:00
|
|
|
|
if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
|
2013-08-15 16:00:39 +00:00
|
|
|
|
{
|
2014-12-04 05:24:41 +00:00
|
|
|
|
item = ResolveVideo<MusicVideo>(args, false);
|
2013-08-15 16:00:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// To find a movie file, the collection type must be movies or boxsets
|
2014-12-19 04:20:07 +00:00
|
|
|
|
else if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
|
2013-08-15 16:00:39 +00:00
|
|
|
|
{
|
2014-11-29 19:51:30 +00:00
|
|
|
|
item = ResolveVideo<Movie>(args, true);
|
2013-08-15 16:00:39 +00:00
|
|
|
|
}
|
2014-12-04 05:24:41 +00:00
|
|
|
|
|
|
|
|
|
else if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
item = ResolveVideo<Video>(args, false);
|
|
|
|
|
}
|
|
|
|
|
else if (string.IsNullOrEmpty(collectionType))
|
|
|
|
|
{
|
2014-12-22 06:50:29 +00:00
|
|
|
|
item = ResolveVideo<Video>(args, false);
|
2014-12-04 05:24:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-15 16:00:39 +00:00
|
|
|
|
if (item != null)
|
|
|
|
|
{
|
|
|
|
|
item.IsInMixedFolder = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return item;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the initial item values.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="args">The args.</param>
|
2013-05-28 01:59:26 +00:00
|
|
|
|
protected override void SetInitialItemValues(Video item, ItemResolveArgs args)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
base.SetInitialItemValues(item, args);
|
|
|
|
|
|
|
|
|
|
SetProviderIdFromPath(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the provider id from path.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
2013-05-28 01:59:26 +00:00
|
|
|
|
private void SetProviderIdFromPath(Video item)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
//we need to only look at the name of this actual item (not parents)
|
2014-02-06 04:39:16 +00:00
|
|
|
|
var justName = item.IsInMixedFolder ? Path.GetFileName(item.Path) : Path.GetFileName(item.ContainingFolderPath);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
var id = justName.GetAttributeValue("tmdbid");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(id))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.Tmdb, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Finds a movie based on a child file system entries
|
|
|
|
|
/// </summary>
|
2013-06-16 19:02:57 +00:00
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
/// <param name="path">The path.</param>
|
2013-12-30 02:41:22 +00:00
|
|
|
|
/// <param name="parent">The parent.</param>
|
2013-06-16 19:02:57 +00:00
|
|
|
|
/// <param name="fileSystemEntries">The file system entries.</param>
|
2014-03-12 02:11:01 +00:00
|
|
|
|
/// <param name="directoryService">The directory service.</param>
|
2014-11-29 19:51:30 +00:00
|
|
|
|
/// <param name="collectionType">Type of the collection.</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <returns>Movie.</returns>
|
2014-12-19 04:20:07 +00:00
|
|
|
|
private T FindMovie<T>(string path, Folder parent, List<FileSystemInfo> fileSystemEntries, IDirectoryService directoryService, string collectionType)
|
2013-06-16 19:02:57 +00:00
|
|
|
|
where T : Video, new()
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-06-16 19:02:57 +00:00
|
|
|
|
var multiDiscFolders = new List<FileSystemInfo>();
|
2014-12-04 05:24:41 +00:00
|
|
|
|
|
|
|
|
|
// Search for a folder rip
|
2013-06-16 19:02:57 +00:00
|
|
|
|
foreach (var child in fileSystemEntries)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-06-20 02:23:07 +00:00
|
|
|
|
var filename = child.Name;
|
|
|
|
|
|
2013-06-11 20:35:54 +00:00
|
|
|
|
if ((child.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-06-20 02:23:07 +00:00
|
|
|
|
if (IsDvdDirectory(filename))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2014-12-04 05:24:41 +00:00
|
|
|
|
var movie = new T
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-06-16 19:02:57 +00:00
|
|
|
|
Path = path,
|
2013-02-21 01:33:05 +00:00
|
|
|
|
VideoType = VideoType.Dvd
|
|
|
|
|
};
|
2014-12-04 05:24:41 +00:00
|
|
|
|
Set3DFormat(movie);
|
|
|
|
|
return movie;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2013-06-20 02:23:07 +00:00
|
|
|
|
if (IsBluRayDirectory(filename))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2014-12-04 05:24:41 +00:00
|
|
|
|
var movie = new T
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-06-16 19:02:57 +00:00
|
|
|
|
Path = path,
|
2013-02-21 01:33:05 +00:00
|
|
|
|
VideoType = VideoType.BluRay
|
|
|
|
|
};
|
2014-12-04 05:24:41 +00:00
|
|
|
|
Set3DFormat(movie);
|
|
|
|
|
return movie;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2013-06-16 19:02:57 +00:00
|
|
|
|
|
2014-11-18 02:48:22 +00:00
|
|
|
|
multiDiscFolders.Add(child);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2014-12-09 04:57:18 +00:00
|
|
|
|
else if (IsDvdFile(filename))
|
|
|
|
|
{
|
|
|
|
|
var movie = new T
|
|
|
|
|
{
|
|
|
|
|
Path = path,
|
|
|
|
|
VideoType = VideoType.Dvd
|
|
|
|
|
};
|
|
|
|
|
Set3DFormat(movie);
|
|
|
|
|
return movie;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2014-12-04 05:24:41 +00:00
|
|
|
|
|
|
|
|
|
var result = ResolveVideos<T>(parent, fileSystemEntries, directoryService, collectionType);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2014-12-19 04:20:07 +00:00
|
|
|
|
var supportsMultiVersion = !string.Equals(collectionType, CollectionType.HomeVideos) &&
|
|
|
|
|
!string.Equals(collectionType, CollectionType.MusicVideos);
|
|
|
|
|
|
2014-12-04 05:24:41 +00:00
|
|
|
|
// Test for multi-editions
|
2014-12-19 04:20:07 +00:00
|
|
|
|
if (result.Items.Count > 1 && supportsMultiVersion)
|
2013-06-12 21:46:50 +00:00
|
|
|
|
{
|
2014-12-04 05:24:41 +00:00
|
|
|
|
var filenamePrefix = Path.GetFileName(path);
|
2014-03-15 22:52:43 +00:00
|
|
|
|
|
2014-12-04 05:24:41 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(filenamePrefix))
|
2014-12-03 03:13:03 +00:00
|
|
|
|
{
|
2014-12-04 05:24:41 +00:00
|
|
|
|
if (result.Items.All(i => _fileSystem.GetFileNameWithoutExtension(i.Path).StartsWith(filenamePrefix + " - ", StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
var movie = (T)result.Items[0];
|
|
|
|
|
movie.Name = filenamePrefix;
|
|
|
|
|
movie.LocalAlternateVersions = result.Items.Skip(1).Select(i => i.Path).ToList();
|
2014-12-09 04:57:18 +00:00
|
|
|
|
movie.IsInMixedFolder = false;
|
2014-12-03 03:13:03 +00:00
|
|
|
|
|
2014-12-04 05:24:41 +00:00
|
|
|
|
_logger.Debug("Multi-version video found: " + movie.Path);
|
2014-03-15 22:52:43 +00:00
|
|
|
|
|
2014-12-04 05:24:41 +00:00
|
|
|
|
return movie;
|
2014-03-15 22:52:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-12 21:46:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-04 05:24:41 +00:00
|
|
|
|
if (result.Items.Count == 1)
|
2013-06-16 19:02:57 +00:00
|
|
|
|
{
|
2014-12-04 05:24:41 +00:00
|
|
|
|
var movie = (T)result.Items[0];
|
|
|
|
|
movie.IsInMixedFolder = false;
|
2014-12-28 06:21:39 +00:00
|
|
|
|
movie.Name = Path.GetFileName(movie.ContainingFolderPath);
|
2014-12-04 05:24:41 +00:00
|
|
|
|
return movie;
|
2013-06-16 19:02:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-04 05:24:41 +00:00
|
|
|
|
if (result.Items.Count == 0 && multiDiscFolders.Count > 0)
|
2013-06-16 19:02:57 +00:00
|
|
|
|
{
|
2014-11-18 02:48:22 +00:00
|
|
|
|
return GetMultiDiscMovie<T>(multiDiscFolders, directoryService);
|
2013-06-16 19:02:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 19:02:57 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the multi disc movie.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
2013-12-20 03:21:37 +00:00
|
|
|
|
/// <param name="multiDiscFolders">The folders.</param>
|
2014-11-18 02:48:22 +00:00
|
|
|
|
/// <param name="directoryService">The directory service.</param>
|
2013-06-16 19:02:57 +00:00
|
|
|
|
/// <returns>``0.</returns>
|
2014-11-18 02:48:22 +00:00
|
|
|
|
private T GetMultiDiscMovie<T>(List<FileSystemInfo> multiDiscFolders, IDirectoryService directoryService)
|
2013-06-16 19:02:57 +00:00
|
|
|
|
where T : Video, new()
|
|
|
|
|
{
|
2013-12-20 03:21:37 +00:00
|
|
|
|
var videoTypes = new List<VideoType>();
|
2013-06-16 19:02:57 +00:00
|
|
|
|
|
2013-12-20 03:21:37 +00:00
|
|
|
|
var folderPaths = multiDiscFolders.Select(i => i.FullName).Where(i =>
|
2013-06-16 19:02:57 +00:00
|
|
|
|
{
|
2014-12-09 04:57:18 +00:00
|
|
|
|
var subFileEntries = directoryService.GetFileSystemEntries(i)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var subfolders = subFileEntries
|
|
|
|
|
.Where(e => (e.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
|
2014-11-18 02:48:22 +00:00
|
|
|
|
.Select(d => d.Name)
|
|
|
|
|
.ToList();
|
2013-06-16 19:02:57 +00:00
|
|
|
|
|
|
|
|
|
if (subfolders.Any(IsDvdDirectory))
|
|
|
|
|
{
|
2013-12-20 03:21:37 +00:00
|
|
|
|
videoTypes.Add(VideoType.Dvd);
|
2013-06-16 19:02:57 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (subfolders.Any(IsBluRayDirectory))
|
|
|
|
|
{
|
2013-12-20 03:21:37 +00:00
|
|
|
|
videoTypes.Add(VideoType.BluRay);
|
2013-06-16 19:02:57 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-09 04:57:18 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 19:02:57 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2013-06-20 02:23:07 +00:00
|
|
|
|
}).OrderBy(i => i).ToList();
|
2013-06-16 19:02:57 +00:00
|
|
|
|
|
2013-12-20 03:21:37 +00:00
|
|
|
|
// If different video types were found, don't allow this
|
2014-11-18 02:48:22 +00:00
|
|
|
|
if (videoTypes.Distinct().Count() > 1)
|
2013-12-20 03:21:37 +00:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-20 02:23:07 +00:00
|
|
|
|
if (folderPaths.Count == 0)
|
2013-06-16 19:02:57 +00:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-28 17:41:47 +00:00
|
|
|
|
var resolver = new StackResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger());
|
2013-12-20 03:21:37 +00:00
|
|
|
|
|
2014-11-18 02:48:22 +00:00
|
|
|
|
var result = resolver.ResolveDirectories(folderPaths);
|
2013-12-20 03:21:37 +00:00
|
|
|
|
|
2014-11-18 02:48:22 +00:00
|
|
|
|
if (result.Stacks.Count != 1)
|
2013-12-20 03:21:37 +00:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2014-12-04 05:24:41 +00:00
|
|
|
|
|
2013-06-16 19:02:57 +00:00
|
|
|
|
return new T
|
|
|
|
|
{
|
2013-06-20 02:23:07 +00:00
|
|
|
|
Path = folderPaths[0],
|
2013-06-16 19:02:57 +00:00
|
|
|
|
|
2014-12-03 03:13:03 +00:00
|
|
|
|
AdditionalParts = folderPaths.Skip(1).ToList(),
|
2013-06-16 19:02:57 +00:00
|
|
|
|
|
2014-11-18 02:48:22 +00:00
|
|
|
|
VideoType = videoTypes[0],
|
|
|
|
|
|
|
|
|
|
Name = result.Stacks[0].Name
|
2013-06-16 19:02:57 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
2013-06-12 21:46:50 +00:00
|
|
|
|
|
2014-12-04 05:24:41 +00:00
|
|
|
|
private bool IsInvalid(Folder parent, string collectionType, IEnumerable<FileSystemInfo> files)
|
2014-03-15 22:52:43 +00:00
|
|
|
|
{
|
2014-12-04 05:24:41 +00:00
|
|
|
|
if (parent != null)
|
2014-03-15 22:52:43 +00:00
|
|
|
|
{
|
2014-12-04 05:24:41 +00:00
|
|
|
|
if (parent.IsRoot)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-03-15 22:52:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-04 05:24:41 +00:00
|
|
|
|
var validCollectionTypes = new[]
|
|
|
|
|
{
|
|
|
|
|
string.Empty,
|
|
|
|
|
CollectionType.Movies,
|
|
|
|
|
CollectionType.HomeVideos,
|
|
|
|
|
CollectionType.MusicVideos,
|
|
|
|
|
CollectionType.Movies
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return !validCollectionTypes.Contains(collectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
|
2013-06-12 21:46:50 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|