@ -76,50 +76,50 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
{
var seasonNumber = episodeInfo . SeasonNumber ;
result . ExtractedSeasonNumber = seasonNumber ;
// Passing in true will include a few extra regex's
var episodeNumber = episodeInfo . EpisodeNumber ;
result . ExtractedEpisodeNumber = episodeNumber ;
var premiereDate = episodeInfo . IsByDate ?
new DateTime ( episodeInfo . Year . Value , episodeInfo . Month . Value , episodeInfo . Day . Value ) :
( DateTime ? ) null ;
if ( episodeInfo . IsByDate | | ( seasonNumber . HasValue & & episodeNumber . HasValue ) )
{
if ( episodeInfo . IsByDate )
{
_logger . Debug ( "Extracted information from {0}. Series name {1}, Date {2}" , path , seriesName , premiereDate . Value ) ;
}
else
{
_logger . Debug ( "Extracted information from {0}. Series name {1}, Season {2}, Episode {3}" , path , seriesName , seasonNumber , episodeNumber ) ;
}
var endingEpisodeNumber = episodeInfo . EndingEpsiodeNumber ;
result . ExtractedEndingEpisodeNumber = endingEpisodeNumber ;
await OrganizeEpisode ( path ,
seriesName ,
seasonNumber ,
episodeNumber ,
endingEpisodeNumber ,
premiereDate ,
options ,
overwriteExisting ,
result ,
cancellationToken ) . ConfigureAwait ( false ) ;
}
else
{
var msg = string . Format ( "Unable to determine episode number from {0}" , path ) ;
result . Status = FileSortingStatus . Failure ;
result . StatusMessage = msg ;
_logger . Warn ( msg ) ;
}
result . ExtractedSeasonNumber = seasonNumber ;
// Passing in true will include a few extra regex's
var episodeNumber = episodeInfo . EpisodeNumber ;
result . ExtractedEpisodeNumber = episodeNumber ;
var premiereDate = episodeInfo . IsByDate ?
new DateTime ( episodeInfo . Year . Value , episodeInfo . Month . Value , episodeInfo . Day . Value ) :
( DateTime ? ) null ;
if ( episodeInfo . IsByDate | | ( seasonNumber . HasValue & & episodeNumber . HasValue ) )
{
if ( episodeInfo . IsByDate )
{
_logger . Debug ( "Extracted information from {0}. Series name {1}, Date {2}" , path , seriesName , premiereDate . Value ) ;
}
else
{
_logger . Debug ( "Extracted information from {0}. Series name {1}, Season {2}, Episode {3}" , path , seriesName , seasonNumber , episodeNumber ) ;
}
var endingEpisodeNumber = episodeInfo . EndingEpsiodeNumber ;
result . ExtractedEndingEpisodeNumber = endingEpisodeNumber ;
await OrganizeEpisode ( path ,
seriesName ,
seasonNumber ,
episodeNumber ,
endingEpisodeNumber ,
premiereDate ,
options ,
overwriteExisting ,
result ,
cancellationToken ) . ConfigureAwait ( false ) ;
}
else
{
var msg = string . Format ( "Unable to determine episode number from {0}" , path ) ;
result . Status = FileSortingStatus . Failure ;
result . StatusMessage = msg ;
_logger . Warn ( msg ) ;
}
}
else
{
@ -151,32 +151,32 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
var series = ( Series ) _libraryManager . GetItemById ( new Guid ( request . SeriesId ) ) ;
await OrganizeEpisode ( result . OriginalPath ,
series ,
request . SeasonNumber ,
request . EpisodeNumber ,
request . EndingEpisodeNumber ,
null ,
options ,
true ,
result ,
cancellationToken ) . ConfigureAwait ( false ) ;
await OrganizeEpisode ( result . OriginalPath ,
series ,
request . SeasonNumber ,
request . EpisodeNumber ,
request . EndingEpisodeNumber ,
null ,
options ,
true ,
result ,
cancellationToken ) . ConfigureAwait ( false ) ;
await _organizationService . SaveResult ( result , CancellationToken . None ) . ConfigureAwait ( false ) ;
return result ;
}
private Task OrganizeEpisode ( string sourcePath ,
string seriesName ,
int? seasonNumber ,
int? episodeNumber ,
int? endingEpiosdeNumber ,
DateTime ? premiereDate ,
TvFileOrganizationOptions options ,
bool overwriteExisting ,
FileOrganizationResult result ,
CancellationToken cancellationToken )
private Task OrganizeEpisode ( string sourcePath ,
string seriesName ,
int? seasonNumber ,
int? episodeNumber ,
int? endingEpiosdeNumber ,
DateTime ? premiereDate ,
TvFileOrganizationOptions options ,
bool overwriteExisting ,
FileOrganizationResult result ,
CancellationToken cancellationToken )
{
var series = GetMatchingSeries ( seriesName , result ) ;
@ -189,33 +189,33 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
return Task . FromResult ( true ) ;
}
return OrganizeEpisode ( sourcePath ,
series ,
seasonNumber ,
episodeNumber ,
endingEpiosdeNumber ,
premiereDate ,
options ,
overwriteExisting ,
result ,
cancellationToken ) ;
return OrganizeEpisode ( sourcePath ,
series ,
seasonNumber ,
episodeNumber ,
endingEpiosdeNumber ,
premiereDate ,
options ,
overwriteExisting ,
result ,
cancellationToken ) ;
}
private async Task OrganizeEpisode ( string sourcePath ,
Series series ,
int? seasonNumber ,
int? episodeNumber ,
int? endingEpiosdeNumber ,
DateTime ? premiereDate ,
TvFileOrganizationOptions options ,
bool overwriteExisting ,
FileOrganizationResult result ,
CancellationToken cancellationToken )
private async Task OrganizeEpisode ( string sourcePath ,
Series series ,
int? seasonNumber ,
int? episodeNumber ,
int? endingEpiosdeNumber ,
DateTime ? premiereDate ,
TvFileOrganizationOptions options ,
bool overwriteExisting ,
FileOrganizationResult result ,
CancellationToken cancellationToken )
{
_logger . Info ( "Sorting file {0} into series {1}" , sourcePath , series . Path ) ;
// 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 ) )
{
@ -324,17 +324,17 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
}
}
private List < string > GetOtherDuplicatePaths ( string targetPath ,
Series series ,
int? seasonNumber ,
int? episodeNumber ,
int? endingEpisodeNumber )
private List < string > GetOtherDuplicatePaths ( string targetPath ,
Series series ,
int? seasonNumber ,
int? episodeNumber ,
int? endingEpisodeNumber )
{
// TODO: Support date-naming?
if ( ! seasonNumber . HasValue | | episodeNumber . HasValue )
{
return new List < string > ( ) ;
}
// TODO: Support date-naming?
if ( ! seasonNumber . HasValue | | episodeNumber . HasValue )
{
return new List < string > ( ) ;
}
var episodePaths = series . GetRecursiveChildren ( )
. OfType < Episode > ( )
@ -462,16 +462,18 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
/// <param name="seasonNumber">The season number.</param>
/// <param name="episodeNumber">The episode number.</param>
/// <param name="endingEpisodeNumber">The ending episode number.</param>
/// <param name="premiereDate">The premiere date.</param>
/// <param name="options">The options.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>System.String.</returns>
private async Task < string > GetNewPath ( string sourcePath ,
Series series ,
int? seasonNumber ,
int? episodeNumber ,
int? endingEpisodeNumber ,
DateTime ? premiereDate ,
TvFileOrganizationOptions options ,
CancellationToken cancellationToken )
private async Task < string > GetNewPath ( string sourcePath ,
Series series ,
int? seasonNumber ,
int? episodeNumber ,
int? endingEpisodeNumber ,
DateTime ? premiereDate ,
TvFileOrganizationOptions options ,
CancellationToken cancellationToken )
{
var episodeInfo = new EpisodeInfo
{
@ -481,7 +483,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
MetadataLanguage = series . GetPreferredMetadataLanguage ( ) ,
ParentIndexNumber = seasonNumber ,
SeriesProviderIds = series . ProviderIds ,
PremiereDate = premiereDate
PremiereDate = premiereDate
} ;
var searchResults = await _providerManager . GetRemoteSearchResults < Episode , EpisodeInfo > ( new RemoteSearchQuery < EpisodeInfo >
@ -491,22 +493,25 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
} , cancellationToken ) . ConfigureAwait ( false ) ;
var episode = searchResults . FirstOrDefault ( ) ;
string episodeName = string . Empty ;
if ( episode = = null )
{
var msg = string . Format ( "No provider metadata found for {0} season {1} episode {2}" , series . Name , seasonNumber , episodeNumber ) ;
_logger . Warn ( msg ) ;
//throw new Exception(msg) ;
return null ;
}
else
{
episodeName = episode . Name ;
}
seasonNumber = seasonNumber ? ? episode . ParentIndexNumber ;
episodeNumber = episodeNumber ? ? episode . IndexNumber ;
var episodeName = episode . Name ;
//if (string.IsNullOrWhiteSpace(episodeName))
//{
// var msg = string.Format("No provider metadata found for {0} season {1} episode {2}", series.Name, seasonNumber, episodeNumber);
// _logger.Warn(msg);
// return null;
//}
seasonNumber = seasonNumber ? ? episode . ParentIndexNumber ;
episodeNumber = episodeNumber ? ? episode . IndexNumber ;
var newPath = GetSeasonFolderPath ( series , seasonNumber . Value , options ) ;
@ -579,7 +584,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
{
seriesName = _fileSystem . GetValidFilename ( seriesName ) . Trim ( ) ;
if ( string . IsNullOr Empty ( episodeTitle ) )
if ( string . IsNullOr WhiteSpace ( episodeTitle ) )
{
episodeTitle = string . Empty ;
}