public void TestMultiPartFolders() { Assert.IsFalse(EntityResolutionHelper.IsMultiPartFolder(@"blah blah")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - cd1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - disc1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - disk1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - pt1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - part1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - dvd1")); // Add a space Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - cd 1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - disc 1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - disk 1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - pt 1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - part 1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - dvd 1")); // Not case sensitive Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - Disc1")); }
public void TestMultiPartFolders() { Assert.IsFalse(EntityResolutionHelper.IsMultiPartFolder(@"blah blah")); Assert.IsFalse(EntityResolutionHelper.IsMultiPartFolder(@"d:\\music\weezer\\03 Pinkerton")); Assert.IsFalse(EntityResolutionHelper.IsMultiPartFolder(@"d:\\music\\michael jackson\\Bad (2012 Remaster)")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - cd1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - disc1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - disk1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - pt1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - part1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - dvd1")); // Add a space Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - cd 1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - disc 1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - disk 1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - pt 1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - part 1")); Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - dvd 1")); // Not case sensitive Assert.IsTrue(EntityResolutionHelper.IsMultiPartFolder(@"blah blah - Disc1")); }
/// <summary> /// Finds a movie based on a child file system entries /// </summary> /// <typeparam name="T"></typeparam> /// <param name="path">The path.</param> /// <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> /// <returns>Movie.</returns> private T FindMovie <T>(string path, Folder parent, List <FileSystemInfo> fileSystemEntries, IDirectoryService directoryService, bool supportMultiFileItems, bool supportsMultipleSources) 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 foreach (var child in fileSystemEntries) { var filename = child.Name; if ((child.Attributes & FileAttributes.Directory) == FileAttributes.Directory) { if (IsDvdDirectory(filename)) { return(new T { Path = path, VideoType = VideoType.Dvd }); } if (IsBluRayDirectory(filename)) { return(new T { Path = path, VideoType = VideoType.BluRay }); } if (EntityResolutionHelper.IsMultiPartFolder(filename)) { multiDiscFolders.Add(child); } continue; } // Don't misidentify extras or trailers as a movie if (BaseItem.ExtraSuffixes.Any(i => filename.IndexOf(i.Key, StringComparison.OrdinalIgnoreCase) != -1)) { continue; } var childArgs = new ItemResolveArgs(_applicationPaths, _libraryManager, directoryService) { FileInfo = child, Path = child.FullName, Parent = parent }; var item = ResolveVideo <T>(childArgs); if (item != null) { item.IsInMixedFolder = false; movies.Add(item); } } if (movies.Count > 1) { if (supportMultiFileItems) { var result = GetMultiFileMovie(movies); if (result != null) { return(result); } } if (supportsMultipleSources) { var result = GetMovieWithMultipleSources(movies); if (result != null) { return(result); } } return(null); } if (movies.Count == 1) { return(movies[0]); } if (multiDiscFolders.Count > 0) { var folders = fileSystemEntries.Where(child => (child.Attributes & FileAttributes.Directory) == FileAttributes.Directory); return(GetMultiDiscMovie <T>(multiDiscFolders, folders)); } return(null); }
/// <summary> /// Loads the additional parts. /// </summary> /// <returns>IEnumerable{Video}.</returns> private IEnumerable <Video> LoadAdditionalParts(IEnumerable <FileSystemInfo> fileSystemChildren, IDirectoryService directoryService) { IEnumerable <FileSystemInfo> files; var path = Path; if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd) { files = fileSystemChildren.Where(i => { if ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory) { return(!string.Equals(i.FullName, path, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsMultiPartFolder(i.FullName)); } return(false); }); } else { files = fileSystemChildren.Where(i => { if ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory) { return(false); } return(!string.Equals(i.FullName, path, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsVideoFile(i.FullName) && EntityResolutionHelper.IsMultiPartFile(i.Name)); }); } return(LibraryManager.ResolvePaths <Video>(files, directoryService, null).Select(video => { // Try to retrieve it from the db. If we don't find it, use the resolved version var dbItem = LibraryManager.GetItemById(video.Id) as Video; if (dbItem != null) { video = dbItem; } return video; // Sort them so that the list can be easily compared for changes }).OrderBy(i => i.Path).ToList()); }