Ejemplo n.º 1
0
        public void RenameOtherExtraFile(Movie movie, string path)
        {
            if (!_diskProvider.FileExists(path))
            {
                return;
            }

            var relativePath = movie.Path.GetRelativePath(path);

            var otherExtraFile = _otherExtraFileService.FindByPath(relativePath);

            if (otherExtraFile != null)
            {
                var newPath = path + "-orig";

                // Recycle an existing -orig file.
                RemoveOtherExtraFile(movie, newPath);

                // Rename the file to .*-orig
                _diskProvider.MoveFile(path, newPath);
                otherExtraFile.RelativePath = relativePath + "-orig";
                otherExtraFile.Extension   += "-orig";
                _otherExtraFileService.Upsert(otherExtraFile);
            }
        }
Ejemplo n.º 2
0
        public override IEnumerable <ExtraFile> MoveFilesAfterRename(Series series, List <EpisodeFile> episodeFiles)
        {
            var extraFiles = _otherExtraFileService.GetFilesBySeries(series.Id);
            var movedFiles = new List <OtherExtraFile>();

            foreach (var episodeFile in episodeFiles)
            {
                var extraFilesForEpisodeFile = extraFiles.Where(m => m.EpisodeFileId == episodeFile.Id).ToList();

                foreach (var extraFile in extraFilesForEpisodeFile)
                {
                    movedFiles.AddIfNotNull(MoveFile(series, episodeFile, extraFile));
                }
            }

            _otherExtraFileService.Upsert(movedFiles);

            return(movedFiles);
        }
Ejemplo n.º 3
0
        public override IEnumerable <ExtraFile> MoveFilesAfterRename(Author author, List <BookFile> bookFiles)
        {
            var extraFiles = _otherExtraFileService.GetFilesByAuthor(author.Id);
            var movedFiles = new List <OtherExtraFile>();

            foreach (var bookFile in bookFiles)
            {
                var extraFilesForTrackFile = extraFiles.Where(m => m.BookFileId == bookFile.Id).ToList();

                foreach (var extraFile in extraFilesForTrackFile)
                {
                    movedFiles.AddIfNotNull(MoveFile(author, bookFile, extraFile));
                }
            }

            _otherExtraFileService.Upsert(movedFiles);

            return(movedFiles);
        }
Ejemplo n.º 4
0
        public override IEnumerable <ExtraFile> MoveFilesAfterRename(Artist artist, List <TrackFile> trackFiles)
        {
            var extraFiles = _otherExtraFileService.GetFilesByArtist(artist.Id);
            var movedFiles = new List <OtherExtraFile>();

            foreach (var trackFile in trackFiles)
            {
                var extraFilesForTrackFile = extraFiles.Where(m => m.TrackFileId == trackFile.Id).ToList();

                foreach (var extraFile in extraFilesForTrackFile)
                {
                    movedFiles.AddIfNotNull(MoveFile(artist, trackFile, extraFile));
                }
            }

            _otherExtraFileService.Upsert(movedFiles);

            return(movedFiles);
        }
Ejemplo n.º 5
0
        public override IEnumerable <ExtraFile> MoveFilesAfterRename(Movie movie, List <MovieFile> movieFiles)
        {
            var extraFiles = _otherExtraFileService.GetFilesByMovie(movie.Id);
            var movedFiles = new List <OtherExtraFile>();

            foreach (var movieFile in movieFiles)
            {
                var extraFilesForMovieFile = extraFiles.Where(m => m.MovieFileId == movieFile.Id).ToList();

                foreach (var extraFile in extraFilesForMovieFile)
                {
                    movedFiles.AddIfNotNull(MoveFile(movie, movieFile, extraFile));
                }
            }

            _otherExtraFileService.Upsert(movedFiles);

            return(movedFiles);
        }
Ejemplo n.º 6
0
        public override IEnumerable<ExtraFile> MoveFilesAfterRename(Series series, List<EpisodeFile> episodeFiles)
        {
            // TODO: Remove
            // We don't want to move files after rename yet.

            return Enumerable.Empty<ExtraFile>();

            var extraFiles = _otherExtraFileService.GetFilesBySeries(series.Id);
            var movedFiles = new List<OtherExtraFile>();

            foreach (var episodeFile in episodeFiles)
            {
                var extraFilesForEpisodeFile = extraFiles.Where(m => m.EpisodeFileId == episodeFile.Id).ToList();

                foreach (var extraFile in extraFilesForEpisodeFile)
                {
                    var existingFileName = Path.Combine(series.Path, extraFile.RelativePath);
                    var extension = Path.GetExtension(existingFileName).TrimStart('.');
                    var newFileName = Path.ChangeExtension(Path.Combine(series.Path, episodeFile.RelativePath), extension);

                    if (newFileName.PathNotEquals(existingFileName))
                    {
                        try
                        {
                            _diskProvider.MoveFile(existingFileName, newFileName);
                            extraFile.RelativePath = series.Path.GetRelativePath(newFileName);
                            movedFiles.Add(extraFile);
                        }
                        catch (Exception ex)
                        {
                            _logger.Warn(ex, "Unable to move extra file: {0}", existingFileName);
                        }
                    }
                }
            }

            _otherExtraFileService.Upsert(movedFiles);

            return movedFiles;
        }