|
@@ -46,12 +46,12 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
|
|
|
|
|
public Task<FileOrganizationResult> OrganizeEpisodeFile(string path, CancellationToken cancellationToken)
|
|
public Task<FileOrganizationResult> OrganizeEpisodeFile(string path, CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
- var options = _config.GetAutoOrganizeOptions().TvOptions;
|
|
|
|
|
|
+ var options = _config.GetAutoOrganizeOptions();
|
|
|
|
|
|
return OrganizeEpisodeFile(path, options, false, cancellationToken);
|
|
return OrganizeEpisodeFile(path, options, false, cancellationToken);
|
|
}
|
|
}
|
|
|
|
|
|
- public async Task<FileOrganizationResult> OrganizeEpisodeFile(string path, TvFileOrganizationOptions options, bool overwriteExisting, CancellationToken cancellationToken)
|
|
|
|
|
|
+ public async Task<FileOrganizationResult> OrganizeEpisodeFile(string path, AutoOrganizeOptions options, bool overwriteExisting, CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
_logger.Info("Sorting file {0}", path);
|
|
_logger.Info("Sorting file {0}", path);
|
|
|
|
|
|
@@ -110,6 +110,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
|
premiereDate,
|
|
premiereDate,
|
|
options,
|
|
options,
|
|
overwriteExisting,
|
|
overwriteExisting,
|
|
|
|
+ false,
|
|
result,
|
|
result,
|
|
cancellationToken).ConfigureAwait(false);
|
|
cancellationToken).ConfigureAwait(false);
|
|
}
|
|
}
|
|
@@ -145,7 +146,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- public async Task<FileOrganizationResult> OrganizeWithCorrection(EpisodeFileOrganizationRequest request, TvFileOrganizationOptions options, CancellationToken cancellationToken)
|
|
|
|
|
|
+ public async Task<FileOrganizationResult> OrganizeWithCorrection(EpisodeFileOrganizationRequest request, AutoOrganizeOptions options, CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
var result = _organizationService.GetResult(request.ResultId);
|
|
var result = _organizationService.GetResult(request.ResultId);
|
|
|
|
|
|
@@ -159,6 +160,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
|
null,
|
|
null,
|
|
options,
|
|
options,
|
|
true,
|
|
true,
|
|
|
|
+ request.RememberCorrection,
|
|
result,
|
|
result,
|
|
cancellationToken).ConfigureAwait(false);
|
|
cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
@@ -173,12 +175,13 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
|
int? episodeNumber,
|
|
int? episodeNumber,
|
|
int? endingEpiosdeNumber,
|
|
int? endingEpiosdeNumber,
|
|
DateTime? premiereDate,
|
|
DateTime? premiereDate,
|
|
- TvFileOrganizationOptions options,
|
|
|
|
|
|
+ AutoOrganizeOptions options,
|
|
bool overwriteExisting,
|
|
bool overwriteExisting,
|
|
|
|
+ bool rememberCorrection,
|
|
FileOrganizationResult result,
|
|
FileOrganizationResult result,
|
|
CancellationToken cancellationToken)
|
|
CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
- var series = GetMatchingSeries(seriesName, result);
|
|
|
|
|
|
+ var series = GetMatchingSeries(seriesName, result, options);
|
|
|
|
|
|
if (series == null)
|
|
if (series == null)
|
|
{
|
|
{
|
|
@@ -197,6 +200,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
|
premiereDate,
|
|
premiereDate,
|
|
options,
|
|
options,
|
|
overwriteExisting,
|
|
overwriteExisting,
|
|
|
|
+ rememberCorrection,
|
|
result,
|
|
result,
|
|
cancellationToken);
|
|
cancellationToken);
|
|
}
|
|
}
|
|
@@ -207,15 +211,18 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
|
int? episodeNumber,
|
|
int? episodeNumber,
|
|
int? endingEpiosdeNumber,
|
|
int? endingEpiosdeNumber,
|
|
DateTime? premiereDate,
|
|
DateTime? premiereDate,
|
|
- TvFileOrganizationOptions options,
|
|
|
|
|
|
+ AutoOrganizeOptions options,
|
|
bool overwriteExisting,
|
|
bool overwriteExisting,
|
|
|
|
+ bool rememberCorrection,
|
|
FileOrganizationResult result,
|
|
FileOrganizationResult result,
|
|
CancellationToken cancellationToken)
|
|
CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
_logger.Info("Sorting file {0} into series {1}", sourcePath, series.Path);
|
|
_logger.Info("Sorting file {0} into series {1}", sourcePath, series.Path);
|
|
|
|
|
|
|
|
+ var originalExtractedSeriesString = result.ExtractedName;
|
|
|
|
+
|
|
// Proceed to sort the file
|
|
// Proceed to sort the file
|
|
- var newPath = await GetNewPath(sourcePath, series, seasonNumber, episodeNumber, endingEpiosdeNumber, premiereDate, options, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
+ var newPath = await GetNewPath(sourcePath, series, seasonNumber, episodeNumber, endingEpiosdeNumber, premiereDate, options.TvOptions, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
if (string.IsNullOrEmpty(newPath))
|
|
if (string.IsNullOrEmpty(newPath))
|
|
{
|
|
{
|
|
@@ -234,7 +241,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
|
|
|
|
|
if (!overwriteExisting)
|
|
if (!overwriteExisting)
|
|
{
|
|
{
|
|
- if (options.CopyOriginalFile && fileExists && IsSameEpisode(sourcePath, newPath))
|
|
|
|
|
|
+ if (options.TvOptions.CopyOriginalFile && fileExists && IsSameEpisode(sourcePath, newPath))
|
|
{
|
|
{
|
|
_logger.Info("File {0} already copied to new path {1}, stopping organization", sourcePath, newPath);
|
|
_logger.Info("File {0} already copied to new path {1}, stopping organization", sourcePath, newPath);
|
|
result.Status = FileSortingStatus.SkippedExisting;
|
|
result.Status = FileSortingStatus.SkippedExisting;
|
|
@@ -251,7 +258,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- PerformFileSorting(options, result);
|
|
|
|
|
|
+ PerformFileSorting(options.TvOptions, result);
|
|
|
|
|
|
if (overwriteExisting)
|
|
if (overwriteExisting)
|
|
{
|
|
{
|
|
@@ -285,6 +292,31 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (rememberCorrection)
|
|
|
|
+ {
|
|
|
|
+ SaveSmartMatchString(originalExtractedSeriesString, series, options);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void SaveSmartMatchString(string matchString, Series series, AutoOrganizeOptions options)
|
|
|
|
+ {
|
|
|
|
+ SmartMatchInfo info = options.SmartMatchInfos.Find(i => i.Id == series.Id);
|
|
|
|
+
|
|
|
|
+ if (info == null)
|
|
|
|
+ {
|
|
|
|
+ info = new SmartMatchInfo();
|
|
|
|
+ info.Id = series.Id;
|
|
|
|
+ info.OrganizerType = FileOrganizerType.Episode;
|
|
|
|
+ info.Name = series.Name;
|
|
|
|
+ options.SmartMatchInfos.Add(info);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!info.MatchStrings.Contains(matchString, StringComparer.OrdinalIgnoreCase))
|
|
|
|
+ {
|
|
|
|
+ info.MatchStrings.Add(matchString);
|
|
|
|
+ _config.SaveAutoOrganizeOptions(options);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private void DeleteLibraryFile(string path, bool renameRelatedFiles, string targetPath)
|
|
private void DeleteLibraryFile(string path, bool renameRelatedFiles, string targetPath)
|
|
@@ -435,7 +467,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private Series GetMatchingSeries(string seriesName, FileOrganizationResult result)
|
|
|
|
|
|
+ private Series GetMatchingSeries(string seriesName, FileOrganizationResult result, AutoOrganizeOptions options)
|
|
{
|
|
{
|
|
var parsedName = _libraryManager.ParseName(seriesName);
|
|
var parsedName = _libraryManager.ParseName(seriesName);
|
|
|
|
|
|
@@ -445,13 +477,28 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
|
result.ExtractedName = nameWithoutYear;
|
|
result.ExtractedName = nameWithoutYear;
|
|
result.ExtractedYear = yearInName;
|
|
result.ExtractedYear = yearInName;
|
|
|
|
|
|
- return _libraryManager.RootFolder.GetRecursiveChildren(i => i is Series)
|
|
|
|
|
|
+ var series = _libraryManager.RootFolder.GetRecursiveChildren(i => i is Series)
|
|
.Cast<Series>()
|
|
.Cast<Series>()
|
|
.Select(i => NameUtils.GetMatchScore(nameWithoutYear, yearInName, i))
|
|
.Select(i => NameUtils.GetMatchScore(nameWithoutYear, yearInName, i))
|
|
.Where(i => i.Item2 > 0)
|
|
.Where(i => i.Item2 > 0)
|
|
.OrderByDescending(i => i.Item2)
|
|
.OrderByDescending(i => i.Item2)
|
|
.Select(i => i.Item1)
|
|
.Select(i => i.Item1)
|
|
.FirstOrDefault();
|
|
.FirstOrDefault();
|
|
|
|
+
|
|
|
|
+ if (series == null)
|
|
|
|
+ {
|
|
|
|
+ SmartMatchInfo info = options.SmartMatchInfos.Where(e => e.MatchStrings.Contains(seriesName, StringComparer.OrdinalIgnoreCase)).FirstOrDefault();
|
|
|
|
+
|
|
|
|
+ if (info != null)
|
|
|
|
+ {
|
|
|
|
+ series = _libraryManager.RootFolder.GetRecursiveChildren(i => i is Series)
|
|
|
|
+ .Cast<Series>()
|
|
|
|
+ .Where(i => i.Id == info.Id)
|
|
|
|
+ .FirstOrDefault();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return series ?? new Series();
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|