From f9923f4592b3f5f8f6664908955408f140d8e296 Mon Sep 17 00:00:00 2001 From: Tim Turner Date: Sat, 21 Jan 2017 17:20:30 -0500 Subject: [PATCH 1/8] Move folder on rename; event doesn't fire yet --- .../MediaFiles/MovieFileMovingService.cs | 28 +++++++++++++++---- .../MediaFiles/RenameMovieFileService.cs | 10 +++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/NzbDrone.Core/MediaFiles/MovieFileMovingService.cs b/src/NzbDrone.Core/MediaFiles/MovieFileMovingService.cs index cf8acd6f9..6d3250575 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieFileMovingService.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieFileMovingService.cs @@ -60,7 +60,7 @@ namespace NzbDrone.Core.MediaFiles var newFileName = _buildFileNames.BuildFileName(movie, movieFile); var filePath = _buildFileNames.BuildFilePath(movie, newFileName, Path.GetExtension(movieFile.RelativePath)); - EnsureMovieFolder(movieFile, movie, filePath); + filePath = EnsureMovieFolder(movieFile, movie, filePath); _logger.Debug("Renaming movie file: {0} to {1}", movieFile, filePath); @@ -72,7 +72,7 @@ namespace NzbDrone.Core.MediaFiles var newFileName = _buildFileNames.BuildFileName(localMovie.Movie, movieFile); var filePath = _buildFileNames.BuildFilePath(localMovie.Movie, newFileName, Path.GetExtension(localMovie.Path)); - EnsureMovieFolder(movieFile, localMovie, filePath); + filePath = EnsureMovieFolder(movieFile, localMovie, filePath); _logger.Debug("Moving movie file: {0} to {1}", movieFile.Path, filePath); @@ -84,7 +84,7 @@ namespace NzbDrone.Core.MediaFiles var newFileName = _buildFileNames.BuildFileName(localMovie.Movie, movieFile); var filePath = _buildFileNames.BuildFilePath(localMovie.Movie, newFileName, Path.GetExtension(localMovie.Path)); - EnsureMovieFolder(movieFile, localMovie, filePath); + filePath = EnsureMovieFolder(movieFile, localMovie, filePath); if (_configService.CopyUsingHardlinks) { @@ -135,15 +135,17 @@ namespace NzbDrone.Core.MediaFiles return movieFile; } - private void EnsureMovieFolder(MovieFile movieFile, LocalMovie localMovie, string filePath) + private string EnsureMovieFolder(MovieFile movieFile, LocalMovie localMovie, string filePath) { - EnsureMovieFolder(movieFile, localMovie.Movie, filePath); + return EnsureMovieFolder(movieFile, localMovie.Movie, filePath); } - private void EnsureMovieFolder(MovieFile movieFile, Movie movie, string filePath) + private string EnsureMovieFolder(MovieFile movieFile, Movie movie, string filePath) { var movieFolder = Path.GetDirectoryName(filePath); var rootFolder = new OsPath(movieFolder).Directory.FullPath; + var fileName = Path.GetFileName(filePath); + var newPath = ""; if (!_diskProvider.FolderExists(rootFolder)) { @@ -157,6 +159,18 @@ namespace NzbDrone.Core.MediaFiles { CreateFolder(movieFolder); newEvent.SeriesFolder = movieFolder; + newPath = Path.Combine(rootFolder, movieFolder, fileName); + changed = true; + } + + var newFolder = _buildFileNames.GetMovieFolder(movie); + + if(_diskProvider.FolderExists(movieFolder) && movieFolder != newFolder) + { + newFolder = Path.Combine(rootFolder, newFolder); + CreateFolder(newFolder); + newEvent.SeriesFolder = newFolder; + newPath = Path.Combine(newFolder, fileName); changed = true; } @@ -164,6 +178,8 @@ namespace NzbDrone.Core.MediaFiles { _eventAggregator.PublishEvent(newEvent); } + + return newPath; } private void CreateFolder(string directoryName) diff --git a/src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs b/src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs index 9a4019f56..86df62faa 100644 --- a/src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs +++ b/src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs @@ -80,6 +80,16 @@ namespace NzbDrone.Core.MediaFiles } + private void RenameMovieFiles(List movieFiles, Movie movie) + { + + } + + private void RenameFolder(Movie movie) + { + + } + private void RenameFiles(List movieFiles, Movie movie) { var renamed = new List(); From 68f58fb37d6e3ba592be99c0e1079c8b36aeacf1 Mon Sep 17 00:00:00 2001 From: Tim Turner Date: Sat, 21 Jan 2017 17:22:21 -0500 Subject: [PATCH 2/8] Undo unecessary changes --- src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs b/src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs index 86df62faa..9a4019f56 100644 --- a/src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs +++ b/src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs @@ -80,16 +80,6 @@ namespace NzbDrone.Core.MediaFiles } - private void RenameMovieFiles(List movieFiles, Movie movie) - { - - } - - private void RenameFolder(Movie movie) - { - - } - private void RenameFiles(List movieFiles, Movie movie) { var renamed = new List(); From 72aac6e551a8f2d6526fde07e235369a9377a2fc Mon Sep 17 00:00:00 2001 From: Tim Turner Date: Wed, 25 Jan 2017 19:03:40 -0500 Subject: [PATCH 3/8] Update Rename Preview to support folder renaming --- .../MediaFiles/RenameMovieFileService.cs | 5 +-- .../Organizer/FileNameBuilder.cs | 31 +++++++++++++++++-- src/UI/Rename/RenamePreviewFormatView.js | 1 + .../RenamePreviewFormatViewTemplate.hbs | 1 + src/UI/Rename/RenamePreviewLayoutTemplate.hbs | 2 +- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs b/src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs index 9a4019f56..38036cf5a 100644 --- a/src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs +++ b/src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs @@ -71,8 +71,9 @@ namespace NzbDrone.Core.MediaFiles { MovieId = movie.Id, MovieFileId = file.Id, - ExistingPath = file.RelativePath, - NewPath = movie.Path.GetRelativePath(newPath) + ExistingPath = movieFilePath, + //NewPath = movie.Path.GetRelativePath(newPath) + NewPath = newPath }; } diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 535a89071..7cd3e0c0e 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -155,12 +155,11 @@ namespace NzbDrone.Core.Organizer return GetOriginalTitle(movieFile); } - //TODO: Update namingConfig for Movies! var pattern = namingConfig.StandardMovieFormat; var tokenHandlers = new Dictionary>(FileNameBuilderTokenEqualityComparer.Instance); AddMovieTokens(tokenHandlers, movie); - AddReleaseDateTokens(tokenHandlers, movie.Year); //In case we want to separate the year + AddReleaseDateTokens(tokenHandlers, movie.Year); AddImdbIdTokens(tokenHandlers, movie.ImdbId); AddQualityTokens(tokenHandlers, movie, movieFile); AddMediaInfoTokens(tokenHandlers, movieFile); @@ -186,11 +185,37 @@ namespace NzbDrone.Core.Organizer { Ensure.That(extension, () => extension).IsNotNullOrWhiteSpace(); - var path = movie.Path; + var path = BuildMoviePath(movie); return Path.Combine(path, fileName + extension); } + public string BuildMoviePath(Movie movie) + { + var path = movie.Path; + var directory = new DirectoryInfo(path).Name; + var parentDirectoryPath = new DirectoryInfo(path).Parent.FullName; + var namingConfig = _namingConfigService.GetConfig(); + + var movieFile = movie.MovieFile; + + var pattern = namingConfig.MovieFolderFormat; + var tokenHandlers = new Dictionary>(FileNameBuilderTokenEqualityComparer.Instance); + + AddMovieTokens(tokenHandlers, movie); + AddReleaseDateTokens(tokenHandlers, movie.Year); + AddImdbIdTokens(tokenHandlers, movie.ImdbId); + AddQualityTokens(tokenHandlers, movie, movieFile); + AddMediaInfoTokens(tokenHandlers, movieFile); + AddMovieFileTokens(tokenHandlers, movieFile); + + var directoryName = ReplaceTokens(pattern, tokenHandlers, namingConfig).Trim(); + directoryName = FileNameCleanupRegex.Replace(directoryName, match => match.Captures[0].Value[0].ToString()); + directoryName = TrimSeparatorsRegex.Replace(directoryName, string.Empty); + + return Path.Combine(parentDirectoryPath, directoryName); + } + public string BuildSeasonPath(Series series, int seasonNumber) { var path = series.Path; diff --git a/src/UI/Rename/RenamePreviewFormatView.js b/src/UI/Rename/RenamePreviewFormatView.js index 5796e6748..141b42f8b 100644 --- a/src/UI/Rename/RenamePreviewFormatView.js +++ b/src/UI/Rename/RenamePreviewFormatView.js @@ -9,6 +9,7 @@ module.exports = Marionette.ItemView.extend({ //var type = this.model.get('seriesType'); return { rename : this.naming.get('renameEpisodes'), + folderFormat: this.naming.get('movieFolderFormat'), format : this.naming.get('standardMovieFormat') }; }, diff --git a/src/UI/Rename/RenamePreviewFormatViewTemplate.hbs b/src/UI/Rename/RenamePreviewFormatViewTemplate.hbs index 77297f56b..99a1f6462 100644 --- a/src/UI/Rename/RenamePreviewFormatViewTemplate.hbs +++ b/src/UI/Rename/RenamePreviewFormatViewTemplate.hbs @@ -1,3 +1,4 @@ {{#if rename}} +Folder Naming pattern: {{folderFormat}}
Naming pattern: {{format}} {{/if}} diff --git a/src/UI/Rename/RenamePreviewLayoutTemplate.hbs b/src/UI/Rename/RenamePreviewLayoutTemplate.hbs index a3aa41d51..ee1f2571c 100644 --- a/src/UI/Rename/RenamePreviewLayoutTemplate.hbs +++ b/src/UI/Rename/RenamePreviewLayoutTemplate.hbs @@ -9,7 +9,7 @@