2015-04-29 11:48:34 -07:00
|
|
|
|
using Interfaces.IO;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
2015-01-09 22:53:35 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-02-12 22:11:54 -07:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-03-03 09:53:58 -07:00
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2015-01-17 13:12:02 -07:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
2014-11-29 12:51:30 -07:00
|
|
|
|
using MediaBrowser.Naming.Video;
|
2015-01-17 13:12:02 -07:00
|
|
|
|
using MediaBrowser.Server.Implementations.Logging;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2013-06-12 14:46:50 -07:00
|
|
|
|
using System.Linq;
|
2015-10-03 21:23:11 -07:00
|
|
|
|
using CommonIO;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-03-02 23:58:04 -07:00
|
|
|
|
namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class MovieResolver
|
|
|
|
|
/// </summary>
|
2014-12-03 22:24:41 -07:00
|
|
|
|
public class MovieResolver : BaseVideoResolver<Video>, IMultiItemResolver
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2015-01-04 07:34:15 -07:00
|
|
|
|
public MovieResolver(ILibraryManager libraryManager)
|
|
|
|
|
: base(libraryManager)
|
2013-03-03 22:43:06 -07:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07: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-03 22:24:41 -07:00
|
|
|
|
// Also run after series resolver
|
|
|
|
|
return ResolverPriority.Third;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-04 07:34:15 -07:00
|
|
|
|
public MultiItemResolverResult ResolveMultiple(Folder parent,
|
2015-10-03 20:38:46 -07:00
|
|
|
|
List<FileSystemMetadata> files,
|
2014-12-03 22:24:41 -07:00
|
|
|
|
string collectionType,
|
|
|
|
|
IDirectoryService directoryService)
|
2015-07-22 22:26:21 -07:00
|
|
|
|
{
|
2016-08-19 11:44:58 -07:00
|
|
|
|
if (parent != null && parent.Path != null && parent.Path.IndexOf("disney", StringComparison.OrdinalIgnoreCase) != -1)
|
|
|
|
|
{
|
|
|
|
|
var b = true;
|
|
|
|
|
var a = b;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 22:26:21 -07:00
|
|
|
|
var result = ResolveMultipleInternal(parent, files, collectionType, directoryService);
|
|
|
|
|
|
|
|
|
|
if (result != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in result.Items)
|
|
|
|
|
{
|
|
|
|
|
SetInitialItemValues((Video)item, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MultiItemResolverResult ResolveMultipleInternal(Folder parent,
|
2015-10-03 20:38:46 -07:00
|
|
|
|
List<FileSystemMetadata> files,
|
2015-07-22 22:26:21 -07:00
|
|
|
|
string collectionType,
|
|
|
|
|
IDirectoryService directoryService)
|
2014-12-03 22:24:41 -07:00
|
|
|
|
{
|
2015-11-04 16:49:06 -07:00
|
|
|
|
if (IsInvalid(parent, collectionType))
|
2014-12-03 22:24:41 -07:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-10-18 10:35:36 -07:00
|
|
|
|
return ResolveVideos<MusicVideo>(parent, files, directoryService, false);
|
2014-12-03 22:24:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-26 11:36:56 -07:00
|
|
|
|
if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) ||
|
2016-02-25 08:12:22 -07:00
|
|
|
|
string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase))
|
2014-12-03 22:24:41 -07:00
|
|
|
|
{
|
2015-10-18 10:35:36 -07:00
|
|
|
|
return ResolveVideos<Video>(parent, files, directoryService, false);
|
2014-12-03 22:24:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(collectionType))
|
|
|
|
|
{
|
|
|
|
|
// Owned items should just use the plain video type
|
|
|
|
|
if (parent == null)
|
|
|
|
|
{
|
2015-10-18 10:35:36 -07:00
|
|
|
|
return ResolveVideos<Video>(parent, files, directoryService, false);
|
2014-12-03 22:24:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-11 07:56:31 -07:00
|
|
|
|
if (parent is Series || parent.GetParents().OfType<Series>().Any())
|
2015-01-09 22:53:35 -07:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-18 10:35:36 -07:00
|
|
|
|
return ResolveVideos<Movie>(parent, files, directoryService, false);
|
2014-12-03 22:24:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-18 21:20:07 -07:00
|
|
|
|
if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
|
2014-12-03 22:24:41 -07:00
|
|
|
|
{
|
2015-10-18 10:35:36 -07:00
|
|
|
|
return ResolveVideos<Movie>(parent, files, directoryService, true);
|
2014-12-03 22:24:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-18 10:35:36 -07:00
|
|
|
|
private MultiItemResolverResult ResolveVideos<T>(Folder parent, IEnumerable<FileSystemMetadata> fileSystemEntries, IDirectoryService directoryService, bool suppportMultiEditions)
|
2014-12-03 22:24:41 -07:00
|
|
|
|
where T : Video, new()
|
|
|
|
|
{
|
2015-10-03 20:38:46 -07:00
|
|
|
|
var files = new List<FileSystemMetadata>();
|
2014-12-03 22:24:41 -07:00
|
|
|
|
var videos = new List<BaseItem>();
|
2015-10-03 20:38:46 -07:00
|
|
|
|
var leftOver = new List<FileSystemMetadata>();
|
2014-12-03 22:24:41 -07:00
|
|
|
|
|
|
|
|
|
// 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);
|
2015-01-09 22:53:35 -07:00
|
|
|
|
}
|
|
|
|
|
else if (IsIgnored(child.Name))
|
|
|
|
|
{
|
2015-09-20 10:28:32 -07:00
|
|
|
|
|
2014-12-03 22:24:41 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
files.Add(child);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-09 22:53:35 -07:00
|
|
|
|
var namingOptions = ((LibraryManager)LibraryManager).GetNamingOptions();
|
|
|
|
|
|
2015-01-16 21:38:24 -07:00
|
|
|
|
var resolver = new VideoListResolver(namingOptions, new PatternsLogger());
|
2015-04-29 11:48:34 -07:00
|
|
|
|
var resolverResult = resolver.Resolve(files.Select(i => new FileMetadata
|
2014-12-03 22:24:41 -07:00
|
|
|
|
{
|
2015-04-29 11:48:34 -07:00
|
|
|
|
Id = i.FullName,
|
2016-02-25 08:12:22 -07:00
|
|
|
|
IsFolder = i.IsDirectory
|
2014-12-03 22:24:41 -07:00
|
|
|
|
|
2014-12-29 13:18:48 -07:00
|
|
|
|
}).ToList(), suppportMultiEditions).ToList();
|
2014-12-03 22:24:41 -07:00
|
|
|
|
|
|
|
|
|
var result = new MultiItemResolverResult
|
|
|
|
|
{
|
|
|
|
|
ExtraFiles = leftOver,
|
|
|
|
|
Items = videos
|
|
|
|
|
};
|
|
|
|
|
|
2015-01-13 21:20:30 -07:00
|
|
|
|
var isInMixedFolder = resolverResult.Count > 1;
|
2014-12-08 21:57:18 -07:00
|
|
|
|
|
2014-12-03 22:24:41 -07:00
|
|
|
|
foreach (var video in resolverResult)
|
|
|
|
|
{
|
|
|
|
|
var firstVideo = video.Files.First();
|
|
|
|
|
|
|
|
|
|
var videoItem = new T
|
|
|
|
|
{
|
|
|
|
|
Path = video.Files[0].Path,
|
2014-12-08 21:57:18 -07:00
|
|
|
|
IsInMixedFolder = isInMixedFolder,
|
2014-12-03 22:24:41 -07:00
|
|
|
|
ProductionYear = video.Year,
|
|
|
|
|
Name = video.Name,
|
2014-12-29 13:18:48 -07:00
|
|
|
|
AdditionalParts = video.Files.Skip(1).Select(i => i.Path).ToList(),
|
|
|
|
|
LocalAlternateVersions = video.AlternateVersions.Select(i => i.Path).ToList()
|
2014-12-03 22:24:41 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SetVideoType(videoItem, firstVideo);
|
|
|
|
|
Set3DFormat(videoItem, firstVideo);
|
|
|
|
|
|
|
|
|
|
result.Items.Add(videoItem);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-25 08:12:22 -07:00
|
|
|
|
result.ExtraFiles.AddRange(files.Where(i => !ContainsFile(resolverResult, i)));
|
|
|
|
|
|
2014-12-03 22:24:41 -07:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-25 08:12:22 -07:00
|
|
|
|
private bool ContainsFile(List<VideoInfo> result, FileSystemMetadata file)
|
|
|
|
|
{
|
|
|
|
|
return result.Any(i => ContainsFile(i, file));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ContainsFile(VideoInfo result, FileSystemMetadata file)
|
|
|
|
|
{
|
|
|
|
|
return result.Files.Any(i => ContainsFile(i, file)) ||
|
|
|
|
|
result.AlternateVersions.Any(i => ContainsFile(i, file)) ||
|
|
|
|
|
result.Extras.Any(i => ContainsFile(i, file));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ContainsFile(VideoFileInfo result, FileSystemMetadata file)
|
|
|
|
|
{
|
|
|
|
|
return string.Equals(result.Path, file.FullName, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Resolves the specified args.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="args">The args.</param>
|
2013-05-27 18:59:26 -07:00
|
|
|
|
/// <returns>Video.</returns>
|
|
|
|
|
protected override Video Resolve(ItemResolveArgs args)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2014-12-03 22:24:41 -07:00
|
|
|
|
var collectionType = args.GetCollectionType();
|
|
|
|
|
|
2015-11-04 16:49:06 -07:00
|
|
|
|
if (IsInvalid(args.Parent, collectionType))
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2014-12-03 22:24:41 -07:00
|
|
|
|
return null;
|
2013-08-15 08:25:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-15 09:00:39 -07:00
|
|
|
|
// Find movies with their own folders
|
2014-12-02 20:13:03 -07:00
|
|
|
|
if (args.IsDirectory)
|
2013-08-15 08:25:51 -07:00
|
|
|
|
{
|
2015-11-04 16:49:06 -07:00
|
|
|
|
var files = args.FileSystemChildren
|
|
|
|
|
.Where(i => !LibraryManager.IgnoreFile(i, args.Parent))
|
|
|
|
|
.ToList();
|
|
|
|
|
|
2014-03-11 19:11:01 -07:00
|
|
|
|
if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
|
2013-05-27 18:59:26 -07:00
|
|
|
|
{
|
2015-11-04 16:49:06 -07:00
|
|
|
|
return FindMovie<MusicVideo>(args.Path, args.Parent, files, args.DirectoryService, collectionType);
|
2013-07-12 12:56:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-28 22:32:03 -07:00
|
|
|
|
if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-11-04 16:49:06 -07:00
|
|
|
|
return FindMovie<Video>(args.Path, args.Parent, files, args.DirectoryService, collectionType);
|
2013-12-28 22:32:03 -07:00
|
|
|
|
}
|
2014-03-15 15:52:43 -07:00
|
|
|
|
|
2014-12-02 20:13:03 -07:00
|
|
|
|
if (string.IsNullOrEmpty(collectionType))
|
2013-07-12 12:56:40 -07:00
|
|
|
|
{
|
2014-12-02 20:13:03 -07:00
|
|
|
|
// Owned items should just use the plain video type
|
|
|
|
|
if (args.Parent == null)
|
|
|
|
|
{
|
2015-11-04 16:49:06 -07:00
|
|
|
|
return FindMovie<Video>(args.Path, args.Parent, files, args.DirectoryService, collectionType);
|
2014-12-02 20:13:03 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-09 22:53:35 -07:00
|
|
|
|
if (args.HasParent<Series>())
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-04 16:49:06 -07:00
|
|
|
|
return FindMovie<Movie>(args.Path, args.Parent, files, args.DirectoryService, collectionType);
|
2013-05-27 18:59:26 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-18 21:20:07 -07:00
|
|
|
|
if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
|
2014-12-02 20:13:03 -07:00
|
|
|
|
{
|
2015-11-04 16:49:06 -07:00
|
|
|
|
return FindMovie<Movie>(args.Path, args.Parent, files, args.DirectoryService, collectionType);
|
2014-12-02 20:13:03 -07:00
|
|
|
|
}
|
2014-12-03 22:24:41 -07:00
|
|
|
|
|
2013-08-29 14:00:27 -07:00
|
|
|
|
return null;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 22:24:41 -07:00
|
|
|
|
// Owned items will be caught by the plain video resolver
|
|
|
|
|
if (args.Parent == null)
|
2013-12-08 11:07:58 -07:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-15 09:00:39 -07:00
|
|
|
|
Video item = null;
|
|
|
|
|
|
2014-03-31 14:04:22 -07:00
|
|
|
|
if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
|
2013-08-15 09:00:39 -07:00
|
|
|
|
{
|
2014-12-03 22:24:41 -07:00
|
|
|
|
item = ResolveVideo<MusicVideo>(args, false);
|
2013-08-15 09:00:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// To find a movie file, the collection type must be movies or boxsets
|
2014-12-18 21:20:07 -07:00
|
|
|
|
else if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
|
2013-08-15 09:00:39 -07:00
|
|
|
|
{
|
2014-11-29 12:51:30 -07:00
|
|
|
|
item = ResolveVideo<Movie>(args, true);
|
2013-08-15 09:00:39 -07:00
|
|
|
|
}
|
2014-12-03 22:24:41 -07:00
|
|
|
|
|
2016-01-26 11:36:56 -07:00
|
|
|
|
else if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) ||
|
|
|
|
|
string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase))
|
2015-03-18 20:47:21 -07:00
|
|
|
|
{
|
|
|
|
|
item = ResolveVideo<Video>(args, false);
|
|
|
|
|
}
|
2014-12-03 22:24:41 -07:00
|
|
|
|
else if (string.IsNullOrEmpty(collectionType))
|
|
|
|
|
{
|
2015-01-09 22:53:35 -07:00
|
|
|
|
if (args.HasParent<Series>())
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item = ResolveVideo<Video>(args, false);
|
2014-12-03 22:24:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-15 09:00:39 -07:00
|
|
|
|
if (item != null)
|
|
|
|
|
{
|
|
|
|
|
item.IsInMixedFolder = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return item;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-09 22:53:35 -07:00
|
|
|
|
private bool IsIgnored(string filename)
|
|
|
|
|
{
|
|
|
|
|
// Ignore samples
|
|
|
|
|
var sampleFilename = " " + filename.Replace(".", " ", StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
.Replace("-", " ", StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
.Replace("_", " ", StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
.Replace("!", " ", StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
if (sampleFilename.IndexOf(" sample ", StringComparison.OrdinalIgnoreCase) != -1)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the initial item values.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="args">The args.</param>
|
2013-05-27 18:59:26 -07:00
|
|
|
|
protected override void SetInitialItemValues(Video item, ItemResolveArgs args)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
base.SetInitialItemValues(item, args);
|
|
|
|
|
|
2015-01-02 07:29:20 -07:00
|
|
|
|
SetProviderIdsFromPath(item);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the provider id from path.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
2015-01-02 07:29:20 -07:00
|
|
|
|
private void SetProviderIdsFromPath(Video item)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2015-01-04 07:34:15 -07:00
|
|
|
|
if (item is Movie || item is MusicVideo)
|
|
|
|
|
{
|
|
|
|
|
//we need to only look at the name of this actual item (not parents)
|
|
|
|
|
var justName = item.IsInMixedFolder ? Path.GetFileName(item.Path) : Path.GetFileName(item.ContainingFolderPath);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2015-09-09 20:22:52 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(justName))
|
2015-01-04 07:34:15 -07:00
|
|
|
|
{
|
2015-09-09 20:22:52 -07:00
|
|
|
|
// check for tmdb id
|
|
|
|
|
var tmdbid = justName.GetAttributeValue("tmdbid");
|
2015-01-02 07:29:20 -07:00
|
|
|
|
|
2015-09-09 20:22:52 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(tmdbid))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.Tmdb, tmdbid);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-02 07:29:20 -07:00
|
|
|
|
|
2015-09-09 20:22:52 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.Path))
|
2015-01-04 07:34:15 -07:00
|
|
|
|
{
|
2015-09-09 20:22:52 -07:00
|
|
|
|
// check for imdb id - we use full media path, as we can assume, that this will match in any use case (wither id in parent dir or in file name)
|
|
|
|
|
var imdbid = item.Path.GetAttributeValue("imdbid");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(imdbid))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.Imdb, imdbid);
|
|
|
|
|
}
|
2015-01-04 07:34:15 -07:00
|
|
|
|
}
|
2015-01-02 07:29:20 -07:00
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Finds a movie based on a child file system entries
|
|
|
|
|
/// </summary>
|
2013-06-16 12:02:57 -07:00
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
/// <param name="path">The path.</param>
|
2013-12-29 19:41:22 -07:00
|
|
|
|
/// <param name="parent">The parent.</param>
|
2013-06-16 12:02:57 -07:00
|
|
|
|
/// <param name="fileSystemEntries">The file system entries.</param>
|
2014-03-11 19:11:01 -07:00
|
|
|
|
/// <param name="directoryService">The directory service.</param>
|
2014-11-29 12:51:30 -07:00
|
|
|
|
/// <param name="collectionType">Type of the collection.</param>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <returns>Movie.</returns>
|
2015-10-03 20:38:46 -07:00
|
|
|
|
private T FindMovie<T>(string path, Folder parent, List<FileSystemMetadata> fileSystemEntries, IDirectoryService directoryService, string collectionType)
|
2013-06-16 12:02:57 -07:00
|
|
|
|
where T : Video, new()
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2015-10-03 20:38:46 -07:00
|
|
|
|
var multiDiscFolders = new List<FileSystemMetadata>();
|
2015-01-04 07:34:15 -07:00
|
|
|
|
|
2014-12-03 22:24:41 -07:00
|
|
|
|
// Search for a folder rip
|
2013-06-16 12:02:57 -07:00
|
|
|
|
foreach (var child in fileSystemEntries)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-06-19 19:23:07 -07:00
|
|
|
|
var filename = child.Name;
|
|
|
|
|
|
2013-06-11 13:35:54 -07:00
|
|
|
|
if ((child.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-06-19 19:23:07 -07:00
|
|
|
|
if (IsDvdDirectory(filename))
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2014-12-03 22:24:41 -07:00
|
|
|
|
var movie = new T
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-06-16 12:02:57 -07:00
|
|
|
|
Path = path,
|
2013-02-20 18:33:05 -07:00
|
|
|
|
VideoType = VideoType.Dvd
|
|
|
|
|
};
|
2014-12-03 22:24:41 -07:00
|
|
|
|
Set3DFormat(movie);
|
|
|
|
|
return movie;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
2013-06-19 19:23:07 -07:00
|
|
|
|
if (IsBluRayDirectory(filename))
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2014-12-03 22:24:41 -07:00
|
|
|
|
var movie = new T
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-06-16 12:02:57 -07:00
|
|
|
|
Path = path,
|
2013-02-20 18:33:05 -07:00
|
|
|
|
VideoType = VideoType.BluRay
|
|
|
|
|
};
|
2014-12-03 22:24:41 -07:00
|
|
|
|
Set3DFormat(movie);
|
|
|
|
|
return movie;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
2013-06-16 12:02:57 -07:00
|
|
|
|
|
2014-11-17 19:48:22 -07:00
|
|
|
|
multiDiscFolders.Add(child);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
2014-12-08 21:57:18 -07:00
|
|
|
|
else if (IsDvdFile(filename))
|
|
|
|
|
{
|
|
|
|
|
var movie = new T
|
|
|
|
|
{
|
|
|
|
|
Path = path,
|
|
|
|
|
VideoType = VideoType.Dvd
|
|
|
|
|
};
|
|
|
|
|
Set3DFormat(movie);
|
|
|
|
|
return movie;
|
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-18 21:20:07 -07:00
|
|
|
|
var supportsMultiVersion = !string.Equals(collectionType, CollectionType.HomeVideos) &&
|
2015-03-18 20:47:21 -07:00
|
|
|
|
!string.Equals(collectionType, CollectionType.Photos) &&
|
2014-12-29 13:18:48 -07:00
|
|
|
|
!string.Equals(collectionType, CollectionType.MusicVideos);
|
2014-03-15 15:52:43 -07:00
|
|
|
|
|
2015-10-18 10:35:36 -07:00
|
|
|
|
var result = ResolveVideos<T>(parent, fileSystemEntries, directoryService, supportsMultiVersion);
|
2013-06-12 14:46:50 -07:00
|
|
|
|
|
2014-12-03 22:24:41 -07:00
|
|
|
|
if (result.Items.Count == 1)
|
2013-06-16 12:02:57 -07:00
|
|
|
|
{
|
2014-12-03 22:24:41 -07:00
|
|
|
|
var movie = (T)result.Items[0];
|
|
|
|
|
movie.IsInMixedFolder = false;
|
2014-12-27 23:21:39 -07:00
|
|
|
|
movie.Name = Path.GetFileName(movie.ContainingFolderPath);
|
2014-12-03 22:24:41 -07:00
|
|
|
|
return movie;
|
2013-06-16 12:02:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 22:24:41 -07:00
|
|
|
|
if (result.Items.Count == 0 && multiDiscFolders.Count > 0)
|
2013-06-16 12:02:57 -07:00
|
|
|
|
{
|
2014-11-17 19:48:22 -07:00
|
|
|
|
return GetMultiDiscMovie<T>(multiDiscFolders, directoryService);
|
2013-06-16 12:02:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 12:02:57 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the multi disc movie.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
2013-12-19 20:21:37 -07:00
|
|
|
|
/// <param name="multiDiscFolders">The folders.</param>
|
2014-11-17 19:48:22 -07:00
|
|
|
|
/// <param name="directoryService">The directory service.</param>
|
2013-06-16 12:02:57 -07:00
|
|
|
|
/// <returns>``0.</returns>
|
2015-10-03 20:38:46 -07:00
|
|
|
|
private T GetMultiDiscMovie<T>(List<FileSystemMetadata> multiDiscFolders, IDirectoryService directoryService)
|
2013-06-16 12:02:57 -07:00
|
|
|
|
where T : Video, new()
|
|
|
|
|
{
|
2013-12-19 20:21:37 -07:00
|
|
|
|
var videoTypes = new List<VideoType>();
|
2013-06-16 12:02:57 -07:00
|
|
|
|
|
2013-12-19 20:21:37 -07:00
|
|
|
|
var folderPaths = multiDiscFolders.Select(i => i.FullName).Where(i =>
|
2013-06-16 12:02:57 -07:00
|
|
|
|
{
|
2014-12-08 21:57:18 -07:00
|
|
|
|
var subFileEntries = directoryService.GetFileSystemEntries(i)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var subfolders = subFileEntries
|
|
|
|
|
.Where(e => (e.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
|
2014-11-17 19:48:22 -07:00
|
|
|
|
.Select(d => d.Name)
|
|
|
|
|
.ToList();
|
2013-06-16 12:02:57 -07:00
|
|
|
|
|
|
|
|
|
if (subfolders.Any(IsDvdDirectory))
|
|
|
|
|
{
|
2013-12-19 20:21:37 -07:00
|
|
|
|
videoTypes.Add(VideoType.Dvd);
|
2013-06-16 12:02:57 -07:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (subfolders.Any(IsBluRayDirectory))
|
|
|
|
|
{
|
2013-12-19 20:21:37 -07:00
|
|
|
|
videoTypes.Add(VideoType.BluRay);
|
2013-06-16 12:02:57 -07:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-08 21:57:18 -07: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 12:02:57 -07:00
|
|
|
|
return false;
|
|
|
|
|
|
2013-06-19 19:23:07 -07:00
|
|
|
|
}).OrderBy(i => i).ToList();
|
2013-06-16 12:02:57 -07:00
|
|
|
|
|
2013-12-19 20:21:37 -07:00
|
|
|
|
// If different video types were found, don't allow this
|
2014-11-17 19:48:22 -07:00
|
|
|
|
if (videoTypes.Distinct().Count() > 1)
|
2013-12-19 20:21:37 -07:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-19 19:23:07 -07:00
|
|
|
|
if (folderPaths.Count == 0)
|
2013-06-16 12:02:57 -07:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-09 22:53:35 -07:00
|
|
|
|
var namingOptions = ((LibraryManager)LibraryManager).GetNamingOptions();
|
2015-01-16 21:38:24 -07:00
|
|
|
|
var resolver = new StackResolver(namingOptions, new PatternsLogger());
|
2013-12-19 20:21:37 -07:00
|
|
|
|
|
2014-11-17 19:48:22 -07:00
|
|
|
|
var result = resolver.ResolveDirectories(folderPaths);
|
2013-12-19 20:21:37 -07:00
|
|
|
|
|
2014-11-17 19:48:22 -07:00
|
|
|
|
if (result.Stacks.Count != 1)
|
2013-12-19 20:21:37 -07:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2014-12-03 22:24:41 -07:00
|
|
|
|
|
2016-02-08 21:09:29 -07:00
|
|
|
|
var returnVideo = new T
|
2013-06-16 12:02:57 -07:00
|
|
|
|
{
|
2013-06-19 19:23:07 -07:00
|
|
|
|
Path = folderPaths[0],
|
2013-06-16 12:02:57 -07:00
|
|
|
|
|
2014-12-02 20:13:03 -07:00
|
|
|
|
AdditionalParts = folderPaths.Skip(1).ToList(),
|
2013-06-16 12:02:57 -07:00
|
|
|
|
|
2014-11-17 19:48:22 -07:00
|
|
|
|
VideoType = videoTypes[0],
|
|
|
|
|
|
|
|
|
|
Name = result.Stacks[0].Name
|
2013-06-16 12:02:57 -07:00
|
|
|
|
};
|
2016-02-08 21:09:29 -07:00
|
|
|
|
|
|
|
|
|
SetIsoType(returnVideo);
|
|
|
|
|
|
|
|
|
|
return returnVideo;
|
2013-06-16 12:02:57 -07:00
|
|
|
|
}
|
2013-06-12 14:46:50 -07:00
|
|
|
|
|
2015-11-04 16:49:06 -07:00
|
|
|
|
private bool IsInvalid(Folder parent, string collectionType)
|
2014-03-15 15:52:43 -07:00
|
|
|
|
{
|
2014-12-03 22:24:41 -07:00
|
|
|
|
if (parent != null)
|
2014-03-15 15:52:43 -07:00
|
|
|
|
{
|
2014-12-03 22:24:41 -07:00
|
|
|
|
if (parent.IsRoot)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-03-15 15:52:43 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 22:24:41 -07:00
|
|
|
|
var validCollectionTypes = new[]
|
|
|
|
|
{
|
|
|
|
|
CollectionType.Movies,
|
|
|
|
|
CollectionType.HomeVideos,
|
|
|
|
|
CollectionType.MusicVideos,
|
2015-03-18 20:47:21 -07:00
|
|
|
|
CollectionType.Movies,
|
|
|
|
|
CollectionType.Photos
|
2014-12-03 22:24:41 -07:00
|
|
|
|
};
|
|
|
|
|
|
2015-10-18 10:35:36 -07:00
|
|
|
|
if (string.IsNullOrWhiteSpace(collectionType))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return !validCollectionTypes.Contains(collectionType, StringComparer.OrdinalIgnoreCase);
|
2013-06-12 14:46:50 -07:00
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
2015-09-20 10:36:09 -07:00
|
|
|
|
}
|