private void ProcessFile(string filename) { _log.WriteEntry("Processing " + filename); if (IsArchive(filename)) { bool filesExtracted = ExtractVideoFiles(filename); if (filesExtracted) { TryDelete(filename); } } else { MoveableFile file = _factory.Create(filename); if (file.IsSeries) { MoveSeries(file); } else { MoveMovie(file); } } }
public IEnumerable <DirectoryMatch> FindDirectoryMatches(MoveableFile file) { foreach (string directory in _directories) { DirectoryInfo info = new DirectoryInfo(directory); int partMatches = info.Name .Split(' ', '.') .Count(part => file.Names.Contains(part, StringComparer.InvariantCultureIgnoreCase)); _matches.Add(new DirectoryMatch(info, partMatches)); } return(_matches.Where(m => m.Matches > 0)); }
private void MoveSeries(MoveableFile file) { var seriesFolders = Directory .EnumerateDirectories(_settings.SeriesFolder) .ToArray(); DirectorySearch search = new DirectorySearch(seriesFolders); IEnumerable <DirectoryMatch> matches = search.FindDirectoryMatches(file); if (matches.Any()) { var match = matches .OrderByDescending(m => m.Matches) .First(); _filemover.Move(file.Fullname, match.Directory.FullName); } else { _filemover.Move(file.Fullname, _settings.DefaultSeriesFolder); } }
private void MoveMovie(MoveableFile file) { _filemover.Move(file.Fullname, _settings.MovieFolder); }