@ -76,50 +76,50 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
{
{
var seasonNumber = episodeInfo . SeasonNumber ;
var seasonNumber = episodeInfo . SeasonNumber ;
result . ExtractedSeasonNumber = seasonNumber ;
result . ExtractedSeasonNumber = seasonNumber ;
// Passing in true will include a few extra regex's
// Passing in true will include a few extra regex's
var episodeNumber = episodeInfo . EpisodeNumber ;
var episodeNumber = episodeInfo . EpisodeNumber ;
result . ExtractedEpisodeNumber = episodeNumber ;
result . ExtractedEpisodeNumber = episodeNumber ;
var premiereDate = episodeInfo . IsByDate ?
var premiereDate = episodeInfo . IsByDate ?
new DateTime ( episodeInfo . Year . Value , episodeInfo . Month . Value , episodeInfo . Day . Value ) :
new DateTime ( episodeInfo . Year . Value , episodeInfo . Month . Value , episodeInfo . Day . Value ) :
( DateTime ? ) null ;
( DateTime ? ) null ;
if ( episodeInfo . IsByDate | | ( seasonNumber . HasValue & & episodeNumber . HasValue ) )
if ( episodeInfo . IsByDate | | ( seasonNumber . HasValue & & episodeNumber . HasValue ) )
{
{
if ( episodeInfo . IsByDate )
if ( episodeInfo . IsByDate )
{
{
_logger . Debug ( "Extracted information from {0}. Series name {1}, Date {2}" , path , seriesName , premiereDate . Value ) ;
_logger . Debug ( "Extracted information from {0}. Series name {1}, Date {2}" , path , seriesName , premiereDate . Value ) ;
}
}
else
else
{
{
_logger . Debug ( "Extracted information from {0}. Series name {1}, Season {2}, Episode {3}" , path , seriesName , seasonNumber , episodeNumber ) ;
_logger . Debug ( "Extracted information from {0}. Series name {1}, Season {2}, Episode {3}" , path , seriesName , seasonNumber , episodeNumber ) ;
}
}
var endingEpisodeNumber = episodeInfo . EndingEpsiodeNumber ;
var endingEpisodeNumber = episodeInfo . EndingEpsiodeNumber ;
result . ExtractedEndingEpisodeNumber = endingEpisodeNumber ;
result . ExtractedEndingEpisodeNumber = endingEpisodeNumber ;
await OrganizeEpisode ( path ,
await OrganizeEpisode ( path ,
seriesName ,
seriesName ,
seasonNumber ,
seasonNumber ,
episodeNumber ,
episodeNumber ,
endingEpisodeNumber ,
endingEpisodeNumber ,
premiereDate ,
premiereDate ,
options ,
options ,
overwriteExisting ,
overwriteExisting ,
result ,
result ,
cancellationToken ) . ConfigureAwait ( false ) ;
cancellationToken ) . ConfigureAwait ( false ) ;
}
}
else
else
{
{
var msg = string . Format ( "Unable to determine episode number from {0}" , path ) ;
var msg = string . Format ( "Unable to determine episode number from {0}" , path ) ;
result . Status = FileSortingStatus . Failure ;
result . Status = FileSortingStatus . Failure ;
result . StatusMessage = msg ;
result . StatusMessage = msg ;
_logger . Warn ( msg ) ;
_logger . Warn ( msg ) ;
}
}
}
}
else
else
{
{
@ -152,15 +152,15 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
var series = ( Series ) _libraryManager . GetItemById ( new Guid ( request . SeriesId ) ) ;
var series = ( Series ) _libraryManager . GetItemById ( new Guid ( request . SeriesId ) ) ;
await OrganizeEpisode ( result . OriginalPath ,
await OrganizeEpisode ( result . OriginalPath ,
series ,
series ,
request . SeasonNumber ,
request . SeasonNumber ,
request . EpisodeNumber ,
request . EpisodeNumber ,
request . EndingEpisodeNumber ,
request . EndingEpisodeNumber ,
null ,
null ,
options ,
options ,
true ,
true ,
result ,
result ,
cancellationToken ) . ConfigureAwait ( false ) ;
cancellationToken ) . ConfigureAwait ( false ) ;
await _organizationService . SaveResult ( result , CancellationToken . None ) . ConfigureAwait ( false ) ;
await _organizationService . SaveResult ( result , CancellationToken . None ) . ConfigureAwait ( false ) ;
@ -168,15 +168,15 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
}
}
private Task OrganizeEpisode ( string sourcePath ,
private Task OrganizeEpisode ( string sourcePath ,
string seriesName ,
string seriesName ,
int? seasonNumber ,
int? seasonNumber ,
int? episodeNumber ,
int? episodeNumber ,
int? endingEpiosdeNumber ,
int? endingEpiosdeNumber ,
DateTime ? premiereDate ,
DateTime ? premiereDate ,
TvFileOrganizationOptions options ,
TvFileOrganizationOptions options ,
bool overwriteExisting ,
bool overwriteExisting ,
FileOrganizationResult result ,
FileOrganizationResult result ,
CancellationToken cancellationToken )
CancellationToken cancellationToken )
{
{
var series = GetMatchingSeries ( seriesName , result ) ;
var series = GetMatchingSeries ( seriesName , result ) ;
@ -189,33 +189,42 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
return Task . FromResult ( true ) ;
return Task . FromResult ( true ) ;
}
}
if ( ! series . ProviderIds . Any ( ) )
{
var msg = string . Format ( "Series has not yet been identified: {0}. If you just added the series, please run a library scan or use the identify feature to identify it." , seriesName ) ;
result . Status = FileSortingStatus . Failure ;
result . StatusMessage = msg ;
_logger . Warn ( msg ) ;
return Task . FromResult ( true ) ;
}
return OrganizeEpisode ( sourcePath ,
return OrganizeEpisode ( sourcePath ,
series ,
series ,
seasonNumber ,
seasonNumber ,
episodeNumber ,
episodeNumber ,
endingEpiosdeNumber ,
endingEpiosdeNumber ,
premiereDate ,
premiereDate ,
options ,
options ,
overwriteExisting ,
overwriteExisting ,
result ,
result ,
cancellationToken ) ;
cancellationToken ) ;
}
}
private async Task OrganizeEpisode ( string sourcePath ,
private async Task OrganizeEpisode ( string sourcePath ,
Series series ,
Series series ,
int? seasonNumber ,
int? seasonNumber ,
int? episodeNumber ,
int? episodeNumber ,
int? endingEpiosdeNumber ,
int? endingEpiosdeNumber ,
DateTime ? premiereDate ,
DateTime ? premiereDate ,
TvFileOrganizationOptions options ,
TvFileOrganizationOptions options ,
bool overwriteExisting ,
bool overwriteExisting ,
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 ) ;
// 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 , cancellationToken ) . ConfigureAwait ( false ) ;
if ( string . IsNullOrEmpty ( newPath ) )
if ( string . IsNullOrEmpty ( newPath ) )
{
{
@ -325,16 +334,16 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
}
}
private List < string > GetOtherDuplicatePaths ( string targetPath ,
private List < string > GetOtherDuplicatePaths ( string targetPath ,
Series series ,
Series series ,
int? seasonNumber ,
int? seasonNumber ,
int? episodeNumber ,
int? episodeNumber ,
int? endingEpisodeNumber )
int? endingEpisodeNumber )
{
{
// TODO: Support date-naming?
// TODO: Support date-naming?
if ( ! seasonNumber . HasValue | | episodeNumber . HasValue )
if ( ! seasonNumber . HasValue | | episodeNumber . HasValue )
{
{
return new List < string > ( ) ;
return new List < string > ( ) ;
}
}
var episodePaths = series . GetRecursiveChildren ( )
var episodePaths = series . GetRecursiveChildren ( )
. OfType < Episode > ( )
. OfType < Episode > ( )
@ -465,13 +474,13 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
/// <param name="options">The options.</param>
/// <param name="options">The options.</param>
/// <returns>System.String.</returns>
/// <returns>System.String.</returns>
private async Task < string > GetNewPath ( string sourcePath ,
private async Task < string > GetNewPath ( string sourcePath ,
Series series ,
Series series ,
int? seasonNumber ,
int? seasonNumber ,
int? episodeNumber ,
int? episodeNumber ,
int? endingEpisodeNumber ,
int? endingEpisodeNumber ,
DateTime ? premiereDate ,
DateTime ? premiereDate ,
TvFileOrganizationOptions options ,
TvFileOrganizationOptions options ,
CancellationToken cancellationToken )
CancellationToken cancellationToken )
{
{
var episodeInfo = new EpisodeInfo
var episodeInfo = new EpisodeInfo
{
{
@ -481,7 +490,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
MetadataLanguage = series . GetPreferredMetadataLanguage ( ) ,
MetadataLanguage = series . GetPreferredMetadataLanguage ( ) ,
ParentIndexNumber = seasonNumber ,
ParentIndexNumber = seasonNumber ,
SeriesProviderIds = series . ProviderIds ,
SeriesProviderIds = series . ProviderIds ,
PremiereDate = premiereDate
PremiereDate = premiereDate
} ;
} ;
var searchResults = await _providerManager . GetRemoteSearchResults < Episode , EpisodeInfo > ( new RemoteSearchQuery < EpisodeInfo >
var searchResults = await _providerManager . GetRemoteSearchResults < Episode , EpisodeInfo > ( new RemoteSearchQuery < EpisodeInfo >
@ -503,10 +512,10 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
else
else
{
{
episodeName = episode . Name ;
episodeName = episode . Name ;
}
}
seasonNumber = seasonNumber ? ? episode . ParentIndexNumber ;
seasonNumber = seasonNumber ? ? episode . ParentIndexNumber ;
episodeNumber = episodeNumber ? ? episode . IndexNumber ;
episodeNumber = episodeNumber ? ? episode . IndexNumber ;
var newPath = GetSeasonFolderPath ( series , seasonNumber . Value , options ) ;
var newPath = GetSeasonFolderPath ( series , seasonNumber . Value , options ) ;