Auto-Organize Copy/Move Option, Fix for Overwrite Existing File
Addition of the option in Auto-Organize to copy or move files from watch folder. Fix to use the Overwrite Existing File option from the config rather than hardcoded value.
This commit is contained in:
parent
3bbb30f5cc
commit
1bf4447dce
|
@ -19,6 +19,8 @@ namespace MediaBrowser.Model.Configuration
|
||||||
|
|
||||||
public bool DeleteEmptyFolders { get; set; }
|
public bool DeleteEmptyFolders { get; set; }
|
||||||
|
|
||||||
|
public bool CopyOriginalFile { get; set; }
|
||||||
|
|
||||||
public TvFileOrganizationOptions()
|
public TvFileOrganizationOptions()
|
||||||
{
|
{
|
||||||
MinFileSizeMb = 50;
|
MinFileSizeMb = 50;
|
||||||
|
@ -31,6 +33,8 @@ namespace MediaBrowser.Model.Configuration
|
||||||
MultiEpisodeNamePattern = "%sn - %sx%0e-x%0ed - %en.%ext";
|
MultiEpisodeNamePattern = "%sn - %sx%0e-x%0ed - %en.%ext";
|
||||||
SeasonFolderPattern = "Season %s";
|
SeasonFolderPattern = "Season %s";
|
||||||
SeasonZeroFolderName = "Season 0";
|
SeasonZeroFolderName = "Season 0";
|
||||||
|
|
||||||
|
CopyOriginalFile = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,9 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
var fileExists = File.Exists(result.TargetPath);
|
var fileExists = File.Exists(result.TargetPath);
|
||||||
var otherDuplicatePaths = GetOtherDuplicatePaths(result.TargetPath, series, seasonNumber, episodeNumber, endingEpiosdeNumber);
|
var otherDuplicatePaths = GetOtherDuplicatePaths(result.TargetPath, series, seasonNumber, episodeNumber, endingEpiosdeNumber);
|
||||||
|
|
||||||
if (!overwriteExisting && (fileExists || otherDuplicatePaths.Count > 0))
|
if (!overwriteExisting)
|
||||||
|
{
|
||||||
|
if (fileExists || otherDuplicatePaths.Count > 0)
|
||||||
{
|
{
|
||||||
result.Status = FileSortingStatus.SkippedExisting;
|
result.Status = FileSortingStatus.SkippedExisting;
|
||||||
result.StatusMessage = string.Empty;
|
result.StatusMessage = string.Empty;
|
||||||
|
@ -179,6 +181,17 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.CopyOriginalFile && fileExists && IsSameEpisode(sourcePath, newPath))
|
||||||
|
{
|
||||||
|
_logger.Info("File {0} already copied to new path {1}, stopping organization", sourcePath, newPath);
|
||||||
|
result.Status = FileSortingStatus.SkippedExisting;
|
||||||
|
result.StatusMessage = string.Empty;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PerformFileSorting(options, result);
|
PerformFileSorting(options, result);
|
||||||
|
|
||||||
if (overwriteExisting)
|
if (overwriteExisting)
|
||||||
|
@ -266,7 +279,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (copy)
|
if (copy || options.CopyOriginalFile)
|
||||||
{
|
{
|
||||||
File.Copy(result.OriginalPath, result.TargetPath, true);
|
File.Copy(result.OriginalPath, result.TargetPath, true);
|
||||||
}
|
}
|
||||||
|
@ -293,7 +306,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
_libraryMonitor.ReportFileSystemChangeComplete(result.TargetPath, true);
|
_libraryMonitor.ReportFileSystemChangeComplete(result.TargetPath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy)
|
if (copy && !options.CopyOriginalFile)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -439,5 +452,27 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
.Replace("%0e", episodeNumber.ToString("00", _usCulture))
|
.Replace("%0e", episodeNumber.ToString("00", _usCulture))
|
||||||
.Replace("%00e", episodeNumber.ToString("000", _usCulture));
|
.Replace("%00e", episodeNumber.ToString("000", _usCulture));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsSameEpisode(string sourcePath, string newPath)
|
||||||
|
{
|
||||||
|
|
||||||
|
FileInfo sourceFileInfo = new FileInfo(sourcePath);
|
||||||
|
FileInfo destinationFileInfo = new FileInfo(newPath);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (sourceFileInfo.Length == destinationFileInfo.Length)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
var organizer = new EpisodeFileOrganizer(_organizationService, _config, _fileSystem, _logger, _libraryManager,
|
var organizer = new EpisodeFileOrganizer(_organizationService, _config, _fileSystem, _logger, _libraryManager,
|
||||||
_libraryMonitor, _providerManager);
|
_libraryMonitor, _providerManager);
|
||||||
|
|
||||||
var result = await organizer.OrganizeEpisodeFile(file.FullName, options, false, cancellationToken).ConfigureAwait(false);
|
var result = await organizer.OrganizeEpisodeFile(file.FullName, options, options.OverwriteExistingEpisodes, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
if (result.Status == FileSortingStatus.Success)
|
if (result.Status == FileSortingStatus.Success)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user