From 0604d180ab49e236d3aff80c7a715392ac980004 Mon Sep 17 00:00:00 2001 From: tikuf Date: Thu, 6 Mar 2014 08:46:32 +1100 Subject: [PATCH 1/3] Added Jump In - NameStartsWith --- .../UserLibrary/BaseItemsByNameService.cs | 6 ++++++ MediaBrowser.Api/UserLibrary/ItemsService.cs | 14 ++++++++++++++ MediaBrowser.Model/Querying/ItemQuery.cs | 11 +++++++++++ MediaBrowser.Model/Querying/ItemsByNameQuery.cs | 4 ++++ 4 files changed, 35 insertions(+) diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs index 5c2c9967e3..6f8e8a9092 100644 --- a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs +++ b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs @@ -174,6 +174,10 @@ namespace MediaBrowser.Api.UserLibrary { items = items.Where(i => string.Compare(request.NameStartsWithOrGreater, i.SortName, StringComparison.CurrentCultureIgnoreCase) < 1); } + if (!string.IsNullOrEmpty(request.NameStartsWith)) + { + items = items.Where(i => string.Compare(request.NameStartsWith, i.SortName.Substring(0, 1), StringComparison.CurrentCultureIgnoreCase) == 0); + } if (!string.IsNullOrEmpty(request.NameLessThan)) { @@ -312,6 +316,8 @@ namespace MediaBrowser.Api.UserLibrary [ApiMember(Name = "NameStartsWithOrGreater", Description = "Optional filter by items whose name is sorted equally or greater than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string NameStartsWithOrGreater { get; set; } + [ApiMember(Name = "NameStartsWith", Description = "Optional filter by items whose name is sorted equally than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string NameStartsWith { get; set; } [ApiMember(Name = "NameLessThan", Description = "Optional filter by items whose name is sorted less than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string NameLessThan { get; set; } diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 871c9aecb4..3221813055 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -110,6 +110,11 @@ namespace MediaBrowser.Api.UserLibrary [ApiMember(Name = "NameStartsWithOrGreater", Description = "Optional filter by items whose name is sorted equally or greater than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string NameStartsWithOrGreater { get; set; } + [ApiMember(Name = "NameStartsWith", Description = "Optional filter by items whose name is sorted equally than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string NameStartsWith { get; set; } + + [ApiMember(Name = "NameLessThan", Description = "Optional filter by items whose name is equally or lesser than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string NameLessThan { get; set; } [ApiMember(Name = "AlbumArtistStartsWithOrGreater", Description = "Optional filter by items whose album artist is sorted equally or greater than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string AlbumArtistStartsWithOrGreater { get; set; } @@ -768,6 +773,15 @@ namespace MediaBrowser.Api.UserLibrary { items = items.Where(i => string.Compare(request.NameStartsWithOrGreater, i.SortName, StringComparison.CurrentCultureIgnoreCase) < 1); } + if (!string.IsNullOrEmpty(request.NameStartsWith)) + { + items = items.Where(i => string.Compare(request.NameStartsWith, i.SortName.Substring(0, 1), StringComparison.CurrentCultureIgnoreCase) == 0); + } + + if (!string.IsNullOrEmpty(request.NameLessThan)) + { + items = items.Where(i => string.Compare(request.NameLessThan, i.SortName, StringComparison.CurrentCultureIgnoreCase) == 1); + } if (!string.IsNullOrEmpty(request.AlbumArtistStartsWithOrGreater)) { diff --git a/MediaBrowser.Model/Querying/ItemQuery.cs b/MediaBrowser.Model/Querying/ItemQuery.cs index bc769b786a..354e12579c 100644 --- a/MediaBrowser.Model/Querying/ItemQuery.cs +++ b/MediaBrowser.Model/Querying/ItemQuery.cs @@ -217,6 +217,17 @@ namespace MediaBrowser.Model.Querying /// /// The name starts with or greater. public string NameStartsWithOrGreater { get; set; } + /// + /// Gets or sets the name starts with. + /// + /// The name starts with or greater. + public string NameStartsWith { get; set; } + + /// + /// Gets or sets the name starts with. + /// + /// The name lessthan. + public string NameLessThan { get; set; } /// /// Gets or sets the album artist starts with or greater. diff --git a/MediaBrowser.Model/Querying/ItemsByNameQuery.cs b/MediaBrowser.Model/Querying/ItemsByNameQuery.cs index eafc322abd..4227dc0c59 100644 --- a/MediaBrowser.Model/Querying/ItemsByNameQuery.cs +++ b/MediaBrowser.Model/Querying/ItemsByNameQuery.cs @@ -86,6 +86,10 @@ namespace MediaBrowser.Model.Querying public string NameStartsWithOrGreater { get; set; } /// + /// Gets or sets the name starts with + /// + /// The name starts with or greater. + public string NameStartsWith { get; set; } /// Gets or sets the name less than. /// /// The name less than. From 52eca07c675b52205234076d395f1a1361e43658 Mon Sep 17 00:00:00 2001 From: tikuf Date: Thu, 6 Mar 2014 13:59:48 +1100 Subject: [PATCH 2/3] Formatting fixes --- MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs | 7 ++++--- MediaBrowser.Api/UserLibrary/ItemsService.cs | 1 + MediaBrowser.Model/Querying/ItemQuery.cs | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs index 6f8e8a9092..12b3fd0154 100644 --- a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs +++ b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs @@ -175,9 +175,9 @@ namespace MediaBrowser.Api.UserLibrary items = items.Where(i => string.Compare(request.NameStartsWithOrGreater, i.SortName, StringComparison.CurrentCultureIgnoreCase) < 1); } if (!string.IsNullOrEmpty(request.NameStartsWith)) - { - items = items.Where(i => string.Compare(request.NameStartsWith, i.SortName.Substring(0, 1), StringComparison.CurrentCultureIgnoreCase) == 0); - } + { + items = items.Where(i => string.Compare(request.NameStartsWith, i.SortName.Substring(0, 1), StringComparison.CurrentCultureIgnoreCase) == 0); + } if (!string.IsNullOrEmpty(request.NameLessThan)) { @@ -316,6 +316,7 @@ namespace MediaBrowser.Api.UserLibrary [ApiMember(Name = "NameStartsWithOrGreater", Description = "Optional filter by items whose name is sorted equally or greater than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string NameStartsWithOrGreater { get; set; } + [ApiMember(Name = "NameStartsWith", Description = "Optional filter by items whose name is sorted equally than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string NameStartsWith { get; set; } diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 3221813055..b040d3dd81 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -110,6 +110,7 @@ namespace MediaBrowser.Api.UserLibrary [ApiMember(Name = "NameStartsWithOrGreater", Description = "Optional filter by items whose name is sorted equally or greater than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string NameStartsWithOrGreater { get; set; } + [ApiMember(Name = "NameStartsWith", Description = "Optional filter by items whose name is sorted equally than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string NameStartsWith { get; set; } diff --git a/MediaBrowser.Model/Querying/ItemQuery.cs b/MediaBrowser.Model/Querying/ItemQuery.cs index 354e12579c..aee1ca947b 100644 --- a/MediaBrowser.Model/Querying/ItemQuery.cs +++ b/MediaBrowser.Model/Querying/ItemQuery.cs @@ -217,13 +217,14 @@ namespace MediaBrowser.Model.Querying /// /// The name starts with or greater. public string NameStartsWithOrGreater { get; set; } - /// + + /// /// Gets or sets the name starts with. /// /// The name starts with or greater. public string NameStartsWith { get; set; } - /// + /// /// Gets or sets the name starts with. /// /// The name lessthan. From 1bf4447dcef2fb5bdfd1791b01f5c06cb5361d47 Mon Sep 17 00:00:00 2001 From: Tensre Date: Wed, 5 Mar 2014 20:44:29 -0800 Subject: [PATCH 3/3] Auto-Organize Copy/Move Option, Fix for Overwrite Existing File Addition of the option in Auto-Organize to copy or move files from watch folder. Fix to use the Overwrite Existing File option from the config rather than hardcoded value. --- .../Configuration/AutoOrganize.cs | 4 ++ .../FileOrganization/EpisodeFileOrganizer.cs | 49 ++++++++++++++++--- .../FileOrganization/TvFolderOrganizer.cs | 2 +- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/MediaBrowser.Model/Configuration/AutoOrganize.cs b/MediaBrowser.Model/Configuration/AutoOrganize.cs index a30aa36d8b..fe32d4a80a 100644 --- a/MediaBrowser.Model/Configuration/AutoOrganize.cs +++ b/MediaBrowser.Model/Configuration/AutoOrganize.cs @@ -19,6 +19,8 @@ namespace MediaBrowser.Model.Configuration public bool DeleteEmptyFolders { get; set; } + public bool CopyOriginalFile { get; set; } + public TvFileOrganizationOptions() { MinFileSizeMb = 50; @@ -31,6 +33,8 @@ namespace MediaBrowser.Model.Configuration MultiEpisodeNamePattern = "%sn - %sx%0e-x%0ed - %en.%ext"; SeasonFolderPattern = "Season %s"; SeasonZeroFolderName = "Season 0"; + + CopyOriginalFile = false; } } } diff --git a/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs b/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs index b91067dd76..e5ffd639bd 100644 --- a/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs +++ b/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs @@ -171,14 +171,27 @@ namespace MediaBrowser.Server.Implementations.FileOrganization var fileExists = File.Exists(result.TargetPath); var otherDuplicatePaths = GetOtherDuplicatePaths(result.TargetPath, series, seasonNumber, episodeNumber, endingEpiosdeNumber); - if (!overwriteExisting && (fileExists || otherDuplicatePaths.Count > 0)) + if (!overwriteExisting) { - result.Status = FileSortingStatus.SkippedExisting; - result.StatusMessage = string.Empty; - result.DuplicatePaths = otherDuplicatePaths; - return; + if (fileExists || otherDuplicatePaths.Count > 0) + { + result.Status = FileSortingStatus.SkippedExisting; + result.StatusMessage = string.Empty; + result.DuplicatePaths = otherDuplicatePaths; + return; + } + + if (options.CopyOriginalFile && fileExists && IsSameEpisode(sourcePath, newPath)) + { + _logger.Info("File {0} already copied to new path {1}, stopping organization", sourcePath, newPath); + result.Status = FileSortingStatus.SkippedExisting; + result.StatusMessage = string.Empty; + return; + } } + + PerformFileSorting(options, result); if (overwriteExisting) @@ -266,7 +279,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization try { - if (copy) + if (copy || options.CopyOriginalFile) { File.Copy(result.OriginalPath, result.TargetPath, true); } @@ -293,7 +306,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization _libraryMonitor.ReportFileSystemChangeComplete(result.TargetPath, true); } - if (copy) + if (copy && !options.CopyOriginalFile) { try { @@ -439,5 +452,27 @@ namespace MediaBrowser.Server.Implementations.FileOrganization .Replace("%0e", episodeNumber.ToString("00", _usCulture)) .Replace("%00e", episodeNumber.ToString("000", _usCulture)); } + + private bool IsSameEpisode(string sourcePath, string newPath) + { + + FileInfo sourceFileInfo = new FileInfo(sourcePath); + FileInfo destinationFileInfo = new FileInfo(newPath); + + try + { + if (sourceFileInfo.Length == destinationFileInfo.Length) + { + return true; + } + } + catch (FileNotFoundException) + { + return false; + } + + return false; + + } } } diff --git a/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs b/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs index 7edcf9739c..82bb9862c9 100644 --- a/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs +++ b/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs @@ -61,7 +61,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization var organizer = new EpisodeFileOrganizer(_organizationService, _config, _fileSystem, _logger, _libraryManager, _libraryMonitor, _providerManager); - var result = await organizer.OrganizeEpisodeFile(file.FullName, options, false, cancellationToken).ConfigureAwait(false); + var result = await organizer.OrganizeEpisodeFile(file.FullName, options, options.OverwriteExistingEpisodes, cancellationToken).ConfigureAwait(false); if (result.Status == FileSortingStatus.Success) {