From daa532ba3fb8f9d1083cc0567b59beec94b69964 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 19 Jan 2014 01:47:01 -0500 Subject: [PATCH] sorter cleanup --- .../FileSorting/TvFileSorter.cs | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/MediaBrowser.Server.Implementations/FileSorting/TvFileSorter.cs b/MediaBrowser.Server.Implementations/FileSorting/TvFileSorter.cs index e2a967ef3a..ba3ba9212b 100644 --- a/MediaBrowser.Server.Implementations/FileSorting/TvFileSorter.cs +++ b/MediaBrowser.Server.Implementations/FileSorting/TvFileSorter.cs @@ -27,16 +27,22 @@ namespace MediaBrowser.Server.Implementations.FileSorting { var minFileBytes = options.MinFileSizeMb * 1024 * 1024; - var allSeries = _libraryManager.RootFolder - .RecursiveChildren.OfType() - .Where(i => i.LocationType == LocationType.FileSystem) - .ToList(); - var eligibleFiles = new DirectoryInfo(path) .EnumerateFiles("*", SearchOption.AllDirectories) .Where(i => EntityResolutionHelper.IsVideoFile(i.FullName) && i.Length >= minFileBytes) .ToList(); + if (eligibleFiles.Count == 0) + { + // Nothing to do + return; + } + + var allSeries = _libraryManager.RootFolder + .RecursiveChildren.OfType() + .Where(i => i.LocationType == LocationType.FileSystem) + .ToList(); + foreach (var file in eligibleFiles) { SortFile(file.FullName, options, allSeries); @@ -122,23 +128,28 @@ namespace MediaBrowser.Server.Implementations.FileSorting { var score = 0; - if (year.HasValue) - { - if (series.ProductionYear.HasValue && year.Value == series.ProductionYear.Value) - { - score++; - } - } - // TODO: Improve this if (string.Equals(sortedName, series.Name, StringComparison.OrdinalIgnoreCase)) { score++; + + if (year.HasValue) + { + if (series.ProductionYear.HasValue && year.Value == series.ProductionYear.Value) + { + score++; + } + } } return new Tuple(series, score); } + /// + /// Deletes the left over files. + /// + /// The path. + /// The extensions. private void DeleteLeftOverFiles(string path, IEnumerable extensions) { var eligibleFiles = new DirectoryInfo(path) @@ -159,6 +170,10 @@ namespace MediaBrowser.Server.Implementations.FileSorting } } + /// + /// Deletes the empty folders. + /// + /// The path. private void DeleteEmptyFolders(string path) { try