@ -46,12 +46,12 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
public Task < FileOrganizationResult > OrganizeEpisodeFile ( string path , CancellationToken cancellationToken )
{
var options = _config . GetAutoOrganizeOptions ( ) .TvOptions ;
var options = _config . GetAutoOrganizeOptions ( ) ;
return OrganizeEpisodeFile ( path , options , false , cancellationToken ) ;
}
public async Task < FileOrganizationResult > OrganizeEpisodeFile ( string path , TvFileOrganization Options options , bool overwriteExisting , CancellationToken cancellationToken )
public async Task < FileOrganizationResult > OrganizeEpisodeFile ( string path , AutoOrganize Options options , bool overwriteExisting , CancellationToken cancellationToken )
{
_logger . Info ( "Sorting file {0}" , path ) ;
@ -110,6 +110,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
premiereDate ,
options ,
overwriteExisting ,
false ,
result ,
cancellationToken ) . ConfigureAwait ( false ) ;
}
@ -145,7 +146,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
return result ;
}
public async Task < FileOrganizationResult > OrganizeWithCorrection ( EpisodeFileOrganizationRequest request , TvFileOrganization Options options , CancellationToken cancellationToken )
public async Task < FileOrganizationResult > OrganizeWithCorrection ( EpisodeFileOrganizationRequest request , AutoOrganize Options options , CancellationToken cancellationToken )
{
var result = _organizationService . GetResult ( request . ResultId ) ;
@ -159,6 +160,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
null ,
options ,
true ,
request . RememberCorrection ,
result ,
cancellationToken ) . ConfigureAwait ( false ) ;
@ -173,12 +175,13 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
int? episodeNumber ,
int? endingEpiosdeNumber ,
DateTime ? premiereDate ,
TvFileOrganization Options options ,
AutoOrganize Options options ,
bool overwriteExisting ,
bool rememberCorrection ,
FileOrganizationResult result ,
CancellationToken cancellationToken )
{
var series = GetMatchingSeries ( seriesName , result );
var series = GetMatchingSeries ( seriesName , result , options );
if ( series = = null )
{
@ -197,6 +200,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
premiereDate ,
options ,
overwriteExisting ,
rememberCorrection ,
result ,
cancellationToken ) ;
}
@ -207,15 +211,18 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
int? episodeNumber ,
int? endingEpiosdeNumber ,
DateTime ? premiereDate ,
TvFileOrganization Options options ,
AutoOrganize Options options ,
bool overwriteExisting ,
bool rememberCorrection ,
FileOrganizationResult result ,
CancellationToken cancellationToken )
{
_logger . Info ( "Sorting file {0} into series {1}" , sourcePath , series . Path ) ;
var originalExtractedSeriesString = result . ExtractedName ;
// 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 ) )
{
@ -234,7 +241,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
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 ) ;
result . Status = FileSortingStatus . SkippedExisting ;
@ -251,7 +258,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
}
}
PerformFileSorting ( options , result ) ;
PerformFileSorting ( options .TvOptions , result ) ;
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 )
@ -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 ) ;
@ -445,13 +477,28 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
result . ExtractedName = nameWithoutYear ;
result . ExtractedYear = yearInName ;
return _libraryManager . RootFolder . GetRecursiveChildren ( i = > i is Series )
var series = _libraryManager . RootFolder . GetRecursiveChildren ( i = > i is Series )
. Cast < Series > ( )
. Select ( i = > NameUtils . GetMatchScore ( nameWithoutYear , yearInName , i ) )
. Where ( i = > i . Item2 > 0 )
. OrderByDescending ( i = > i . Item2 )
. Select ( i = > i . Item1 )
. 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>