2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Common.Extensions;
|
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;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2013-06-12 21:46:50 +00:00
|
|
|
|
using System.Linq;
|
2014-03-15 22:52:43 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
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>
|
2013-05-28 01:59:26 +00:00
|
|
|
|
public class MovieResolver : BaseVideoResolver<Video>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-09-04 17:07:35 +00:00
|
|
|
|
private readonly IServerApplicationPaths _applicationPaths;
|
2013-07-12 19:56:40 +00:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2014-03-15 22:52:43 +00:00
|
|
|
|
private readonly ILogger _logger;
|
2013-06-12 21:46:50 +00:00
|
|
|
|
|
2014-03-15 22:52:43 +00:00
|
|
|
|
public MovieResolver(IServerApplicationPaths appPaths, ILibraryManager libraryManager, ILogger logger)
|
2013-03-04 05:43:06 +00:00
|
|
|
|
{
|
2013-09-04 17:07:35 +00:00
|
|
|
|
_applicationPaths = appPaths;
|
2013-07-12 19:56:40 +00:00
|
|
|
|
_libraryManager = libraryManager;
|
2014-03-15 22:52:43 +00:00
|
|
|
|
_logger = logger;
|
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
|
|
|
|
|
return ResolverPriority.Second;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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
|
|
|
|
{
|
2013-08-15 15:25:51 +00:00
|
|
|
|
// Avoid expensive tests against VF's and all their children by not allowing this
|
|
|
|
|
if (args.Parent != null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-08-15 15:25:51 +00:00
|
|
|
|
if (args.Parent.IsRoot)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-08-15 15:25:51 +00:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var isDirectory = args.IsDirectory;
|
|
|
|
|
|
|
|
|
|
if (isDirectory)
|
|
|
|
|
{
|
2013-05-28 01:59:26 +00:00
|
|
|
|
// Since the looping is expensive, this is an optimization to help us avoid it
|
2013-08-15 15:25:51 +00:00
|
|
|
|
if (args.ContainsMetaFileByName("series.xml"))
|
2013-05-28 01:59:26 +00:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2013-08-15 15:25:51 +00:00
|
|
|
|
}
|
2013-05-28 01:59:26 +00:00
|
|
|
|
|
2013-09-04 17:07:35 +00:00
|
|
|
|
var collectionType = args.GetCollectionType();
|
2013-06-16 19:02:57 +00:00
|
|
|
|
|
2013-08-15 16:00:39 +00:00
|
|
|
|
// Find movies with their own folders
|
2013-08-15 15:25:51 +00:00
|
|
|
|
if (isDirectory)
|
|
|
|
|
{
|
2014-03-12 02:11:01 +00:00
|
|
|
|
if (string.Equals(collectionType, CollectionType.Trailers, StringComparison.OrdinalIgnoreCase))
|
2013-05-28 01:59:26 +00:00
|
|
|
|
{
|
2014-03-15 22:52:43 +00:00
|
|
|
|
return FindMovie<Trailer>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, false, false);
|
2013-05-28 01:59:26 +00:00
|
|
|
|
}
|
2013-07-12 19:56:40 +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-03-15 22:52:43 +00:00
|
|
|
|
return FindMovie<MusicVideo>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, false, false);
|
2013-07-12 19:56:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-12 02:11:01 +00:00
|
|
|
|
if (string.Equals(collectionType, CollectionType.AdultVideos, StringComparison.OrdinalIgnoreCase))
|
2013-07-16 18:47:05 +00:00
|
|
|
|
{
|
2014-03-15 22:52:43 +00:00
|
|
|
|
return FindMovie<AdultVideo>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, true, false);
|
2013-07-16 18:47:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-29 05:32:03 +00:00
|
|
|
|
if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2014-03-15 22:52:43 +00:00
|
|
|
|
return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, true, false);
|
2013-12-29 05:32:03 +00:00
|
|
|
|
}
|
2014-03-15 22:52:43 +00:00
|
|
|
|
|
2013-08-29 21:00:27 +00:00
|
|
|
|
if (string.IsNullOrEmpty(collectionType) ||
|
|
|
|
|
string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) ||
|
|
|
|
|
string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
|
2013-07-12 19:56:40 +00:00
|
|
|
|
{
|
2014-03-15 22:52:43 +00:00
|
|
|
|
return FindMovie<Movie>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, true, true);
|
2013-05-28 01:59:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-29 21:00:27 +00:00
|
|
|
|
return null;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-08 18:07:58 +00:00
|
|
|
|
var filename = Path.GetFileName(args.Path);
|
|
|
|
|
// Don't misidentify xbmc trailers as a movie
|
|
|
|
|
if (filename.IndexOf(BaseItem.XbmcTrailerFileSuffix, StringComparison.OrdinalIgnoreCase) != -1)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-15 16:00:39 +00:00
|
|
|
|
// Find movies that are mixed in the same folder
|
|
|
|
|
if (args.Path.IndexOf("[trailers]", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
|
|
|
string.Equals(collectionType, CollectionType.Trailers, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return ResolveVideo<Trailer>(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Video item = null;
|
|
|
|
|
|
|
|
|
|
if (args.Path.IndexOf("[musicvideos]", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
|
|
|
string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
item = ResolveVideo<MusicVideo>(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (args.Path.IndexOf("[adultvideos]", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
|
|
|
string.Equals(collectionType, CollectionType.AdultVideos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
item = ResolveVideo<AdultVideo>(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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) ||
|
|
|
|
|
string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
item = ResolveVideo<Movie>(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
/// <param name="supportMultiFileItems">if set to <c>true</c> [support multi file items].</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <returns>Movie.</returns>
|
2014-03-15 22:52:43 +00:00
|
|
|
|
private T FindMovie<T>(string path, Folder parent, IEnumerable<FileSystemInfo> fileSystemEntries, IDirectoryService directoryService, bool supportMultiFileItems, bool supportsAlternateVersions)
|
2013-06-16 19:02:57 +00:00
|
|
|
|
where T : Video, new()
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-28 01:59:26 +00:00
|
|
|
|
var movies = new List<T>();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-06-16 19:02:57 +00:00
|
|
|
|
var multiDiscFolders = new List<FileSystemInfo>();
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
// Loop through each child file/folder and see if we find a video
|
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
|
|
|
|
{
|
2013-05-28 01:59:26 +00:00
|
|
|
|
return 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
|
|
|
|
|
};
|
|
|
|
|
}
|
2013-06-20 02:23:07 +00:00
|
|
|
|
if (IsBluRayDirectory(filename))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-28 01:59:26 +00:00
|
|
|
|
return 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
|
|
|
|
|
};
|
|
|
|
|
}
|
2013-06-16 19:02:57 +00:00
|
|
|
|
|
2014-03-15 22:52:43 +00:00
|
|
|
|
if (EntityResolutionHelper.IsMultiPartFolder(filename))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-06-16 19:02:57 +00:00
|
|
|
|
multiDiscFolders.Add(child);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-20 16:43:22 +00:00
|
|
|
|
// Don't misidentify xbmc trailers as a movie
|
2013-06-20 02:23:07 +00:00
|
|
|
|
if (filename.IndexOf(BaseItem.XbmcTrailerFileSuffix, StringComparison.OrdinalIgnoreCase) != -1)
|
2013-05-20 16:43:22 +00:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-13 05:11:54 +00:00
|
|
|
|
var childArgs = new ItemResolveArgs(_applicationPaths, _libraryManager, directoryService)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
FileInfo = child,
|
2013-12-30 02:41:22 +00:00
|
|
|
|
Path = child.FullName,
|
|
|
|
|
Parent = parent
|
2013-02-21 01:33:05 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-05-28 01:59:26 +00:00
|
|
|
|
var item = ResolveVideo<T>(childArgs);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
if (item != null)
|
|
|
|
|
{
|
2013-08-16 20:13:45 +00:00
|
|
|
|
item.IsInMixedFolder = false;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
movies.Add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-15 22:52:43 +00:00
|
|
|
|
if (movies.Count > 1)
|
2013-06-12 21:46:50 +00:00
|
|
|
|
{
|
2014-03-15 22:52:43 +00:00
|
|
|
|
if (supportMultiFileItems)
|
|
|
|
|
{
|
|
|
|
|
var result = GetMultiFileMovie(movies);
|
|
|
|
|
|
|
|
|
|
if (result != null)
|
|
|
|
|
{
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (supportsAlternateVersions)
|
|
|
|
|
{
|
|
|
|
|
var result = GetMovieWithAlternateVersions(movies);
|
|
|
|
|
|
|
|
|
|
if (result != null)
|
|
|
|
|
{
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2013-06-12 21:46:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 19:02:57 +00:00
|
|
|
|
if (movies.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
return movies[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (multiDiscFolders.Count > 0)
|
|
|
|
|
{
|
2013-12-20 03:21:37 +00:00
|
|
|
|
var folders = fileSystemEntries.Where(child => (child.Attributes & FileAttributes.Directory) == FileAttributes.Directory);
|
|
|
|
|
|
|
|
|
|
return GetMultiDiscMovie<T>(multiDiscFolders, folders);
|
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>
|
|
|
|
|
/// <param name="allFolders">All folders.</param>
|
2013-06-16 19:02:57 +00:00
|
|
|
|
/// <returns>``0.</returns>
|
2013-12-20 03:21:37 +00:00
|
|
|
|
private T GetMultiDiscMovie<T>(List<FileSystemInfo> multiDiscFolders, IEnumerable<FileSystemInfo> allFolders)
|
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
|
|
|
|
{
|
2013-06-20 02:23:07 +00:00
|
|
|
|
var subfolders = Directory.GetDirectories(i).Select(Path.GetFileName).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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
if (videoTypes.Count > 0 && videoTypes.Any(i => i != videoTypes[0]))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-20 02:23:07 +00:00
|
|
|
|
if (folderPaths.Count == 0)
|
2013-06-16 19:02:57 +00:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-20 03:21:37 +00:00
|
|
|
|
// If there are other folders side by side that are folder rips, don't allow it
|
|
|
|
|
// TODO: Improve this to return null if any folder is present aside from our regularly ignored folders
|
|
|
|
|
if (allFolders.Except(multiDiscFolders).Any(i =>
|
|
|
|
|
{
|
|
|
|
|
var subfolders = Directory.GetDirectories(i.FullName).Select(Path.GetFileName).ToList();
|
|
|
|
|
|
|
|
|
|
if (subfolders.Any(IsDvdDirectory))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (subfolders.Any(IsBluRayDirectory))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
IsMultiPart = true,
|
|
|
|
|
|
2013-12-20 03:21:37 +00:00
|
|
|
|
VideoType = videoTypes[0]
|
2013-06-16 19:02:57 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
2013-06-12 21:46:50 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the multi file movie.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
/// <param name="movies">The movies.</param>
|
|
|
|
|
/// <returns>``0.</returns>
|
2014-02-20 17:49:07 +00:00
|
|
|
|
private T GetMultiFileMovie<T>(IEnumerable<T> movies)
|
2013-06-12 21:46:50 +00:00
|
|
|
|
where T : Video, new()
|
|
|
|
|
{
|
2014-02-20 17:49:07 +00:00
|
|
|
|
var sortedMovies = movies.OrderBy(i => i.Path).ToList();
|
2013-06-12 21:46:50 +00:00
|
|
|
|
|
2014-02-20 17:49:07 +00:00
|
|
|
|
var firstMovie = sortedMovies[0];
|
2013-06-12 21:46:50 +00:00
|
|
|
|
|
2014-02-20 17:49:07 +00:00
|
|
|
|
// They must all be part of the sequence if we're going to consider it a multi-part movie
|
2014-03-15 22:52:43 +00:00
|
|
|
|
if (sortedMovies.All(i => EntityResolutionHelper.IsMultiPartFile(i.Path)))
|
2014-02-20 17:49:07 +00:00
|
|
|
|
{
|
2014-03-15 22:52:43 +00:00
|
|
|
|
// Only support up to 8 (matches Plex), to help avoid incorrect detection
|
|
|
|
|
if (sortedMovies.Count <= 8)
|
|
|
|
|
{
|
|
|
|
|
firstMovie.IsMultiPart = true;
|
|
|
|
|
|
|
|
|
|
_logger.Info("Multi-part video found: " + firstMovie.Path);
|
2013-06-12 21:46:50 +00:00
|
|
|
|
|
2014-03-15 22:52:43 +00:00
|
|
|
|
return firstMovie;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private T GetMovieWithAlternateVersions<T>(IEnumerable<T> movies)
|
|
|
|
|
where T : Video, new()
|
|
|
|
|
{
|
|
|
|
|
var sortedMovies = movies.OrderBy(i => i.Path.Length).ToList();
|
|
|
|
|
|
|
|
|
|
// Cap this at five to help avoid incorrect matching
|
|
|
|
|
if (sortedMovies.Count > 5)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var firstMovie = sortedMovies[0];
|
|
|
|
|
|
|
|
|
|
var filenamePrefix = Path.GetFileNameWithoutExtension(firstMovie.Path);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(filenamePrefix))
|
|
|
|
|
{
|
|
|
|
|
if (sortedMovies.All(i => Path.GetFileNameWithoutExtension(i.Path).StartsWith(filenamePrefix, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
firstMovie.HasLocalAlternateVersions = true;
|
|
|
|
|
|
|
|
|
|
_logger.Info("Multi-version video found: " + firstMovie.Path);
|
|
|
|
|
|
|
|
|
|
return firstMovie;
|
|
|
|
|
}
|
2014-02-20 17:49:07 +00:00
|
|
|
|
}
|
2013-06-12 21:46:50 +00:00
|
|
|
|
|
2014-02-20 17:49:07 +00:00
|
|
|
|
return null;
|
2013-06-12 21:46:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <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)
|
|
|
|
|
{
|
2013-11-21 16:02:49 +00:00
|
|
|
|
return string.Equals(directoryName, "video_ts", StringComparison.OrdinalIgnoreCase);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2013-06-12 21:46:50 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <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)
|
|
|
|
|
{
|
2013-11-21 16:02:49 +00:00
|
|
|
|
return string.Equals(directoryName, "bdmv", StringComparison.OrdinalIgnoreCase);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|