public override IEnumerable <ExtraFile> MoveFilesAfterRename(Series series, List <EpisodeFile> episodeFiles) { var subtitleFiles = _subtitleFileService.GetFilesBySeries(series.Id); var movedFiles = new List <SubtitleFile>(); foreach (var episodeFile in episodeFiles) { var groupedExtraFilesForEpisodeFile = subtitleFiles.Where(m => m.EpisodeFileId == episodeFile.Id) .GroupBy(s => s.Language + s.Extension).ToList(); foreach (var group in groupedExtraFilesForEpisodeFile) { var groupCount = group.Count(); var copy = 1; if (groupCount > 1) { _logger.Warn("Multiple subtitle files found with the same language and extension for {0}", Path.Combine(series.Path, episodeFile.RelativePath)); } foreach (var subtitleFile in group) { var suffix = GetSuffix(subtitleFile.Language, copy, groupCount > 1); movedFiles.AddIfNotNull(MoveFile(series, episodeFile, subtitleFile, suffix)); copy++; } } } _subtitleFileService.Upsert(movedFiles); return(movedFiles); }
public override IEnumerable <ExtraFile> MoveFilesAfterRename(Series series, List <EpisodeFile> episodeFiles) { var subtitleFiles = _subtitleFileService.GetFilesBySeries(series.Id); var movedFiles = new List <SubtitleFile>(); foreach (var episodeFile in episodeFiles) { var groupedExtraFilesForEpisodeFile = subtitleFiles.Where(m => m.EpisodeFileId == episodeFile.Id) .GroupBy(s => s.Language + s.Extension).ToList(); foreach (var group in groupedExtraFilesForEpisodeFile) { var groupCount = group.Count(); var copy = 1; foreach (var subtitleFile in group) { var suffix = GetSuffix(subtitleFile.Language, copy, groupCount > 1); movedFiles.AddIfNotNull(MoveFile(series, episodeFile, subtitleFile, suffix)); copy++; } } } _subtitleFileService.Upsert(movedFiles); return(movedFiles); }
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 subtitleFiles = _subtitleFileService.GetFilesBySeries(series.Id); var movedFiles = new List <SubtitleFile>(); foreach (var episodeFile in episodeFiles) { var groupedExtraFilesForEpisodeFile = subtitleFiles.Where(m => m.EpisodeFileId == episodeFile.Id) .GroupBy(s => s.Language + s.Extension).ToList(); foreach (var group in groupedExtraFilesForEpisodeFile) { var groupCount = group.Count(); var copy = 1; if (groupCount > 1) { _logger.Warn("Multiple subtitle files found with the same language and extension for {0}", Path.Combine(series.Path, episodeFile.RelativePath)); } foreach (var extraFile in group) { var existingFileName = Path.Combine(series.Path, extraFile.RelativePath); var extension = GetExtension(extraFile, existingFileName, copy, groupCount > 1); 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 subtitle file: {0}", existingFileName); } } copy++; } } } _subtitleFileService.Upsert(movedFiles); return(movedFiles); }