Ejemplo n.º 1
0
        private void RenameFiles(List <MovieFile> movieFiles, Movie movie, string oldMoviePath = null)
        {
            var renamed = new List <MovieFile>();

            if (oldMoviePath == null)
            {
                oldMoviePath = movie.Path;
            }

            foreach (var movieFile in movieFiles)
            {
                var oldMovieFilePath = Path.Combine(oldMoviePath, movieFile.RelativePath);
                movieFile.Path = oldMovieFilePath;

                try
                {
                    _logger.Debug("Renaming movie file: {0}", movieFile);
                    _movieFileMover.MoveMovieFile(movieFile, movie);

                    _mediaFileService.Update(movieFile);
                    _movieService.UpdateMovie(movie);
                    renamed.Add(movieFile);

                    _logger.Debug("Renamed movie file: {0}", movieFile);
                }
                catch (SameFilenameException ex)
                {
                    _logger.Debug("File not renamed, source and destination are the same: {0}", ex.Filename);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, "Failed to rename file: " + oldMovieFilePath);
                }
            }
        }
Ejemplo n.º 2
0
        private List <RenamedMovieFile> RenameFiles(List <MovieFile> movieFiles, Movie movie)
        {
            var renamed = new List <RenamedMovieFile>();

            foreach (var movieFile in movieFiles)
            {
                var previousRelativePath = movieFile.RelativePath;
                var previousPath         = Path.Combine(movie.Path, movieFile.RelativePath);

                try
                {
                    _logger.Debug("Renaming movie file: {0}", movieFile);
                    _movieFileMover.MoveMovieFile(movieFile, movie);

                    _mediaFileService.Update(movieFile);
                    _movieService.UpdateMovie(movie);
                    renamed.Add(new RenamedMovieFile
                    {
                        MovieFile            = movieFile,
                        PreviousRelativePath = previousRelativePath,
                        PreviousPath         = previousPath
                    });

                    _logger.Debug("Renamed movie file: {0}", movieFile);

                    _eventAggregator.PublishEvent(new MovieFileRenamedEvent(movie, movieFile, previousPath));
                }
                catch (SameFilenameException ex)
                {
                    _logger.Debug("File not renamed, source and destination are the same: {0}", ex.Filename);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, "Failed to rename file: {0}", previousPath);
                }
            }

            if (renamed.Any())
            {
                _diskProvider.RemoveEmptySubfolders(movie.Path);

                _eventAggregator.PublishEvent(new MovieRenamedEvent(movie, renamed));
            }

            return(renamed);
        }
Ejemplo n.º 3
0
        public MovieFileMoveResult UpgradeMovieFile(MovieFile movieFile, LocalMovie localMovie, bool copyOnly = false)
        {
            _logger.Trace("Upgrading existing movie file.");
            var moveFileResult = new MovieFileMoveResult();

            var existingFile = localMovie.Movie.MovieFileId > 0 ? localMovie.Movie.MovieFile : null;

            var rootFolder = _diskProvider.GetParentFolder(localMovie.Movie.Path);

            // If there are existing movie files and the root folder is missing, throw, so the old file isn't left behind during the import process.
            if (existingFile != null && !_diskProvider.FolderExists(rootFolder))
            {
                throw new RootFolderNotFoundException($"Root folder '{rootFolder}' was not found.");
            }

            if (existingFile != null)
            {
                var movieFilePath = Path.Combine(localMovie.Movie.Path, existingFile.RelativePath);
                var subfolder     = rootFolder.GetRelativePath(_diskProvider.GetParentFolder(movieFilePath));

                if (_diskProvider.FileExists(movieFilePath))
                {
                    _logger.Debug("Removing existing movie file: {0}", existingFile);
                    _recycleBinProvider.DeleteFile(movieFilePath, subfolder);
                }

                moveFileResult.OldFiles.Add(existingFile);
                _mediaFileService.Delete(existingFile, DeleteMediaFileReason.Upgrade);
            }

            if (copyOnly)
            {
                moveFileResult.MovieFile = _movieFileMover.CopyMovieFile(movieFile, localMovie);
            }
            else
            {
                moveFileResult.MovieFile = _movieFileMover.MoveMovieFile(movieFile, localMovie);
            }

            return(moveFileResult);
        }
Ejemplo n.º 4
0
        public MovieFileMoveResult UpgradeMovieFile(MovieFile movieFile, LocalMovie localMovie, bool copyOnly = false)
        {
            _logger.Trace("Upgrading existing movie file.");
            var moveFileResult = new MovieFileMoveResult();

            var existingFile = localMovie.Movie.MovieFile;

            if (existingFile != null)
            {
                var movieFilePath = Path.Combine(localMovie.Movie.Path, existingFile.RelativePath);

                if (_diskProvider.FileExists(movieFilePath))
                {
                    _logger.Debug("Removing existing movie file: {0}", existingFile);
                    _recycleBinProvider.DeleteFile(movieFilePath);
                }

                moveFileResult.OldFiles.Add(existingFile);
                _mediaFileService.Delete(existingFile, DeleteMediaFileReason.Upgrade);
            }

            //Temporary for correctly getting path
            localMovie.Movie.MovieFileId = 1;
            localMovie.Movie.MovieFile   = movieFile;

            if (copyOnly)
            {
                moveFileResult.MovieFile = _movieFileMover.CopyMovieFile(movieFile, localMovie);
            }
            else
            {
                moveFileResult.MovieFile = _movieFileMover.MoveMovieFile(movieFile, localMovie);
            }

            localMovie.Movie.MovieFileId = existingFile?.Id ?? 0;
            localMovie.Movie.MovieFile   = existingFile;

            //_movieFileRenamer.RenameMoviePath(localMovie.Movie, false);

            return(moveFileResult);
        }