public IEnumerable <AudioBookInfo> Resolve(IEnumerable <FileSystemMetadata> files) { var audioBookResolver = new AudioBookResolver(_options); var audiobookFileInfos = files .Select(i => audioBookResolver.Resolve(i.FullName, i.IsDirectory)) .Where(i => i != null) .ToList(); // Filter out all extras, otherwise they could cause stacks to not be resolved // See the unit test TestStackedWithTrailer var metadata = audiobookFileInfos .Select(i => new FileSystemMetadata { FullName = i.Path, IsDirectory = i.IsDirectory }); var stackResult = new StackResolver(_options) .ResolveAudioBooks(metadata); foreach (var stack in stackResult) { var stackFiles = stack.Files.Select(i => audioBookResolver.Resolve(i, stack.IsDirectoryStack)).ToList(); stackFiles.Sort(); var info = new AudioBookInfo { Files = stackFiles, Name = stack.Name }; yield return(info); } }
public IEnumerable <AudioBookInfo> Resolve(IEnumerable <FileSystemMetadata> files) { var audioBookResolver = new AudioBookResolver(_options); var audiobookFileInfos = files .Select(i => audioBookResolver.Resolve(i.FullName, i.IsDirectory)) .Where(i => i != null) .ToList(); // Filter out all extras, otherwise they could cause stacks to not be resolved // See the unit test TestStackedWithTrailer var metadata = audiobookFileInfos .Select(i => new FileSystemMetadata { FullName = i.Path, IsDirectory = i.IsDirectory }); var stackResult = new StackResolver(_options) .ResolveAudioBooks(metadata); var list = new List <AudioBookInfo>(); foreach (var stack in stackResult.Stacks) { var stackFiles = stack.Files.Select(i => audioBookResolver.Resolve(i, stack.IsDirectoryStack)).ToList(); stackFiles.Sort(); var info = new AudioBookInfo { Files = stackFiles, Name = stack.Name }; list.Add(info); } // Whatever files are left, just add them /*list.AddRange(remainingFiles.Select(i => new AudioBookInfo * { * Files = new List<AudioBookFileInfo> { i }, * Name = i., * Year = i.Year * }));*/ var orderedList = list.OrderBy(i => i.Name); return(orderedList); }
/// <summary> /// Resolves Name, Year and differentiate alternative files and extras from regular audiobook files. /// </summary> /// <param name="files">List of files related to audiobook.</param> /// <returns>Returns IEnumerable of <see cref="AudioBookInfo"/>.</returns> public IEnumerable <AudioBookInfo> Resolve(IEnumerable <FileSystemMetadata> files) { var audioBookResolver = new AudioBookResolver(_options); // File with empty fullname will be sorted out here. var audiobookFileInfos = files .Select(i => audioBookResolver.Resolve(i.FullName)) .OfType <AudioBookFileInfo>() .ToList(); var stackResult = new StackResolver(_options) .ResolveAudioBooks(audiobookFileInfos); foreach (var stack in stackResult) { var stackFiles = stack.Files .Select(i => audioBookResolver.Resolve(i)) .OfType <AudioBookFileInfo>() .ToList(); stackFiles.Sort(); var nameParserResult = new AudioBookNameParser(_options).Parse(stack.Name); FindExtraAndAlternativeFiles(ref stackFiles, out var extras, out var alternativeVersions, nameParserResult); var info = new AudioBookInfo( nameParserResult.Name, nameParserResult.Year, stackFiles, extras, alternativeVersions); yield return(info); } }
/// <summary> /// Initializes a new instance of the <see cref="AudioBookListResolver"/> class. /// </summary> /// <param name="options">Naming options passed along to <see cref="AudioBookResolver"/> and <see cref="AudioBookNameParser"/>.</param> public AudioBookListResolver(NamingOptions options) { _options = options; _audioBookResolver = new AudioBookResolver(_options); }