1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-26 22:46:53 -04:00

Relative episode file paths

This commit is contained in:
Mark McDowall
2014-07-23 16:43:54 -07:00
parent 10fc875715
commit 6671934c0f
63 changed files with 571 additions and 464 deletions
@@ -50,7 +50,7 @@ namespace NzbDrone.Core.MediaFiles
{
var episodes = _episodeService.GetEpisodesByFileId(episodeFile.Id);
var newFileName = _buildFileNames.BuildFileName(episodes, series, episodeFile);
var filePath = _buildFileNames.BuildFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path));
var filePath = _buildFileNames.BuildFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.RelativePath));
_logger.Debug("Renaming episode file: {0} to {1}", episodeFile, filePath);
@@ -60,7 +60,7 @@ namespace NzbDrone.Core.MediaFiles
public EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode)
{
var newFileName = _buildFileNames.BuildFileName(localEpisode.Episodes, localEpisode.Series, episodeFile);
var filePath = _buildFileNames.BuildFilePath(localEpisode.Series, localEpisode.SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path));
var filePath = _buildFileNames.BuildFilePath(localEpisode.Series, localEpisode.SeasonNumber, newFileName, Path.GetExtension(localEpisode.Path));
_logger.Debug("Moving episode file: {0} to {1}", episodeFile, filePath);
@@ -70,27 +70,29 @@ namespace NzbDrone.Core.MediaFiles
public EpisodeFile CopyEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode)
{
var newFileName = _buildFileNames.BuildFileName(localEpisode.Episodes, localEpisode.Series, episodeFile);
var filePath = _buildFileNames.BuildFilePath(localEpisode.Series, localEpisode.SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path));
var filePath = _buildFileNames.BuildFilePath(localEpisode.Series, localEpisode.SeasonNumber, newFileName, Path.GetExtension(localEpisode.Path));
_logger.Debug("Copying episode file: {0} to {1}", episodeFile, filePath);
return TransferFile(episodeFile, localEpisode.Series, localEpisode.Episodes, filePath, true);
}
private EpisodeFile TransferFile(EpisodeFile episodeFile, Series series, List<Episode> episodes, string destinationFilename, bool copyOnly)
private EpisodeFile TransferFile(EpisodeFile episodeFile, Series series, List<Episode> episodes, String destinationFilename, Boolean copyOnly)
{
Ensure.That(episodeFile, () => episodeFile).IsNotNull();
Ensure.That(series,() => series).IsNotNull();
Ensure.That(destinationFilename, () => destinationFilename).IsValidPath();
if (!_diskProvider.FileExists(episodeFile.Path))
var episodeFilePath = episodeFile.Path ?? Path.Combine(series.Path, episodeFile.RelativePath);
if (!_diskProvider.FileExists(episodeFilePath))
{
throw new FileNotFoundException("Episode file path does not exist", episodeFile.Path);
throw new FileNotFoundException("Episode file path does not exist", episodeFilePath);
}
if (episodeFile.Path.PathEquals(destinationFilename))
if (episodeFilePath.PathEquals(destinationFilename))
{
throw new SameFilenameException("File not moved, source and destination are the same", episodeFile.Path);
throw new SameFilenameException("File not moved, source and destination are the same", episodeFilePath);
}
var directoryName = new FileInfo(destinationFilename).DirectoryName;
@@ -116,15 +118,16 @@ namespace NzbDrone.Core.MediaFiles
if (copyOnly)
{
_logger.Debug("Copying [{0}] > [{1}]", episodeFile.Path, destinationFilename);
_diskProvider.CopyFile(episodeFile.Path, destinationFilename);
_logger.Debug("Copying [{0}] > [{1}]", episodeFilePath, destinationFilename);
_diskProvider.CopyFile(episodeFilePath, destinationFilename);
}
else
{
_logger.Debug("Moving [{0}] > [{1}]", episodeFile.Path, destinationFilename);
_diskProvider.MoveFile(episodeFile.Path, destinationFilename);
_logger.Debug("Moving [{0}] > [{1}]", episodeFilePath, destinationFilename);
_diskProvider.MoveFile(episodeFilePath, destinationFilename);
}
episodeFile.Path = destinationFilename;
episodeFile.RelativePath = series.Path.GetRelativePath(destinationFilename);
_updateEpisodeFileService.ChangeFileDateForFile(episodeFile, series, episodes);