@@ -30,22 +30,19 @@ public class EpisodeFileOrganizer
30
30
private readonly ILogger _logger ;
31
31
private readonly IFileSystem _fileSystem ;
32
32
private readonly IFileOrganizationService _organizationService ;
33
- private readonly IServerConfigurationManager _config ;
34
33
private readonly IProviderManager _providerManager ;
35
34
36
35
private readonly CultureInfo _usCulture = new CultureInfo ( "en-US" ) ;
37
36
38
37
public EpisodeFileOrganizer (
39
38
IFileOrganizationService organizationService ,
40
- IServerConfigurationManager config ,
41
39
IFileSystem fileSystem ,
42
40
ILogger logger ,
43
41
ILibraryManager libraryManager ,
44
42
ILibraryMonitor libraryMonitor ,
45
43
IProviderManager providerManager )
46
44
{
47
45
_organizationService = organizationService ;
48
- _config = config ;
49
46
_fileSystem = fileSystem ;
50
47
_logger = logger ;
51
48
_libraryManager = libraryManager ;
@@ -167,15 +164,15 @@ await OrganizeEpisode(path,
167
164
}
168
165
else
169
166
{
170
- var msg = string . Format ( "Unable to determine episode number from {0}" , path ) ;
167
+ var msg = "Unable to determine episode number from " + path ;
171
168
result . Status = FileSortingStatus . Failure ;
172
169
result . StatusMessage = msg ;
173
170
_logger . LogWarning ( msg ) ;
174
171
}
175
172
}
176
173
else
177
174
{
178
- var msg = string . Format ( "Unable to determine series name from {0}" , path ) ;
175
+ var msg = "Unable to determine series name from " + path ;
179
176
result . Status = FileSortingStatus . Failure ;
180
177
result . StatusMessage = msg ;
181
178
_logger . LogWarning ( msg ) ;
@@ -228,16 +225,13 @@ private async Task<Series> AutoDetectSeries(
228
225
Year = seriesYear
229
226
} ;
230
227
231
- var searchResultsTask = await _providerManager . GetRemoteSearchResults < Series , SeriesInfo > ( new RemoteSearchQuery < SeriesInfo >
232
- {
233
- SearchInfo = seriesInfo
234
-
235
- } , cancellationToken ) ;
228
+ var searchQuery = new RemoteSearchQuery < SeriesInfo > { SearchInfo = seriesInfo } ;
229
+ var searchResults = await _providerManager . GetRemoteSearchResults < Series , SeriesInfo > ( searchQuery , cancellationToken ) . ConfigureAwait ( false ) ;
236
230
237
231
#endregion
238
232
239
233
// Group series by name and year (if 2 series with the exact same name, the same year ...)
240
- var groupedResult = searchResultsTask . GroupBy ( p => new { p . Name , p . ProductionYear } ,
234
+ var groupedResult = searchResults . GroupBy ( p => new { p . Name , p . ProductionYear } ,
241
235
p => p ,
242
236
( key , g ) => new { Key = key , Result = g . ToList ( ) } ) . ToList ( ) ;
243
237
@@ -307,7 +301,7 @@ private async Task<Series> CreateNewSeries(
307
301
// Create the folder
308
302
Directory . CreateDirectory ( series . Path ) ;
309
303
310
- series . ProviderIds = request . NewSeriesProviderIds ;
304
+ series . ProviderIds = request . NewSeriesProviderIds . ToDictionary ( x => x . Key , x => x . Value ) ;
311
305
}
312
306
}
313
307
@@ -388,7 +382,7 @@ private Task OrganizeEpisode(string sourcePath,
388
382
389
383
if ( series == null )
390
384
{
391
- var msg = string . Format ( "Unable to find series in library matching name {0}" , seriesName ) ;
385
+ var msg = "Unable to find series in library matching name " + seriesName ;
392
386
result . Status = FileSortingStatus . Failure ;
393
387
result . StatusMessage = msg ;
394
388
_logger . LogWarning ( msg ) ;
@@ -418,7 +412,6 @@ private Task OrganizeEpisode(string sourcePath,
418
412
/// <param name="endingEpiosdeNumber"></param>
419
413
/// <param name="premiereDate"></param>
420
414
/// <param name="options"></param>
421
- /// <param name="smartMatch"></param>
422
415
/// <param name="rememberCorrection"></param>
423
416
/// <param name="result"></param>
424
417
/// <param name="cancellationToken"></param>
@@ -434,29 +427,38 @@ private async Task OrganizeEpisode(string sourcePath,
434
427
FileOrganizationResult result ,
435
428
CancellationToken cancellationToken )
436
429
{
437
- var episode = await GetMatchingEpisode ( series , seasonNumber , episodeNumber , endingEpiosdeNumber , result , premiereDate , cancellationToken ) ;
430
+ var episode = await GetMatchingEpisode (
431
+ series ,
432
+ seasonNumber ,
433
+ episodeNumber ,
434
+ endingEpiosdeNumber ,
435
+ result ,
436
+ premiereDate ,
437
+ cancellationToken ) . ConfigureAwait ( false ) ;
438
438
439
439
Season season ;
440
440
season = ! string . IsNullOrEmpty ( episode . Season ? . Path )
441
441
? episode . Season
442
- : GetMatchingSeason ( series , episode , options , cancellationToken ) ;
442
+ : GetMatchingSeason ( series , episode , options ) ;
443
443
444
444
// Now we can check the episode Path
445
445
if ( string . IsNullOrEmpty ( episode . Path ) )
446
446
{
447
447
SetEpisodeFileName ( sourcePath , series , season , episode , options ) ;
448
448
}
449
449
450
- await OrganizeEpisode ( sourcePath ,
450
+ await OrganizeEpisode (
451
+ sourcePath ,
451
452
series ,
452
453
episode ,
453
454
options ,
454
455
rememberCorrection ,
455
456
result ,
456
- cancellationToken ) ;
457
+ cancellationToken ) . ConfigureAwait ( false ) ;
457
458
}
458
459
459
- private async Task OrganizeEpisode ( string sourcePath ,
460
+ private Task OrganizeEpisode (
461
+ string sourcePath ,
460
462
Series series ,
461
463
Episode episode ,
462
464
TvFileOrganizationOptions options ,
@@ -487,7 +489,7 @@ private async Task OrganizeEpisode(string sourcePath,
487
489
488
490
if ( string . IsNullOrEmpty ( newPath ) )
489
491
{
490
- var msg = string . Format ( "Unable to sort {0 } because target path could not be determined." , sourcePath ) ;
492
+ var msg = $ "Unable to sort { sourcePath } because target path could not be determined.";
491
493
throw new OrganizationException ( msg ) ;
492
494
}
493
495
@@ -501,31 +503,31 @@ private async Task OrganizeEpisode(string sourcePath,
501
503
{
502
504
if ( options . CopyOriginalFile && fileExists && IsSameEpisode ( sourcePath , newPath ) )
503
505
{
504
- var msg = string . Format ( "File '{0 }' already copied to new path '{1 }', stopping organization" , sourcePath , newPath ) ;
506
+ var msg = $ "File '{ sourcePath } ' already copied to new path '{ newPath } ', stopping organization";
505
507
_logger . LogInformation ( msg ) ;
506
508
result . Status = FileSortingStatus . SkippedExisting ;
507
509
result . StatusMessage = msg ;
508
- return ;
510
+ return Task . CompletedTask ;
509
511
}
510
512
511
513
if ( fileExists )
512
514
{
513
- var msg = string . Format ( "File '{0 }' already exists as '{1 }', stopping organization" , sourcePath , newPath ) ;
515
+ var msg = $ "File '{ sourcePath } ' already exists as '{ newPath } ', stopping organization";
514
516
_logger . LogInformation ( msg ) ;
515
517
result . Status = FileSortingStatus . SkippedExisting ;
516
518
result . StatusMessage = msg ;
517
519
result . TargetPath = newPath ;
518
- return ;
520
+ return Task . CompletedTask ;
519
521
}
520
522
521
523
if ( otherDuplicatePaths . Count > 0 )
522
524
{
523
- var msg = string . Format ( "File '{0 }' already exists as these:'{1}'. Stopping organization" , sourcePath , string . Join ( "', '" , otherDuplicatePaths ) ) ;
525
+ var msg = $ "File '{ sourcePath } ' already exists as these:'{ string . Join ( "', '" , otherDuplicatePaths ) } '. Stopping organization" ;
524
526
_logger . LogInformation ( msg ) ;
525
527
result . Status = FileSortingStatus . SkippedExisting ;
526
528
result . StatusMessage = msg ;
527
529
result . DuplicatePaths = otherDuplicatePaths ;
528
- return ;
530
+ return Task . CompletedTask ;
529
531
}
530
532
}
531
533
@@ -569,7 +571,7 @@ private async Task OrganizeEpisode(string sourcePath,
569
571
result . Status = FileSortingStatus . Failure ;
570
572
result . StatusMessage = ex . Message ;
571
573
_logger . LogError ( ex , "Caught a generic exception while organizing an episode" ) ;
572
- return ;
574
+ return Task . CompletedTask ;
573
575
}
574
576
finally
575
577
{
@@ -580,6 +582,8 @@ private async Task OrganizeEpisode(string sourcePath,
580
582
{
581
583
SaveSmartMatchString ( originalExtractedSeriesString , series , cancellationToken ) ;
582
584
}
585
+
586
+ return Task . CompletedTask ;
583
587
}
584
588
585
589
private void SaveSmartMatchString ( string matchString , Series series , CancellationToken cancellationToken )
@@ -734,7 +738,7 @@ private void PerformFileSorting(TvFileOrganizationOptions options, FileOrganizat
734
738
}
735
739
catch ( Exception ex )
736
740
{
737
- var errorMsg = string . Format ( "Failed to move file from {0 } to {1}: {2}" , result . OriginalPath , result . TargetPath , ex . Message ) ;
741
+ var errorMsg = $ "Failed to move file from { result . OriginalPath } to { result . TargetPath } : { ex . Message } " ;
738
742
739
743
result . Status = FileSortingStatus . Failure ;
740
744
result . StatusMessage = errorMsg ;
@@ -784,7 +788,7 @@ private async Task<Episode> GetMatchingEpisode(Series series,
784
788
return episode ;
785
789
}
786
790
787
- private Season GetMatchingSeason ( Series series , Episode episode , TvFileOrganizationOptions options , CancellationToken cancellationToken )
791
+ private Season GetMatchingSeason ( Series series , Episode episode , TvFileOrganizationOptions options )
788
792
{
789
793
var season = episode . Season ;
790
794
@@ -799,8 +803,7 @@ private Season GetMatchingSeason(Series series, Episode episode, TvFileOrganizat
799
803
{
800
804
if ( ! episode . ParentIndexNumber . HasValue )
801
805
{
802
- var msg = string . Format ( "No season found for {0} season {1} episode {2}" , series . Name ,
803
- episode . ParentIndexNumber , episode . IndexNumber ) ;
806
+ var msg = $ "No season found for { series . Name } season { episode . ParentIndexNumber } episode { episode . IndexNumber } .";
804
807
_logger . LogWarning ( msg ) ;
805
808
throw new OrganizationException ( msg ) ;
806
809
}
@@ -843,7 +846,7 @@ private Series GetMatchingSeries(string seriesName, int? seriesYear, string targ
843
846
. Where ( i => i . Item2 > 0 )
844
847
. OrderByDescending ( i => i . Item2 )
845
848
. Select ( i => i . Item1 )
846
- . FirstOrDefault ( s => s . Path . StartsWith ( targetFolder ) ) ;
849
+ . FirstOrDefault ( s => s . Path . StartsWith ( targetFolder , StringComparison . Ordinal ) ) ;
847
850
848
851
if ( series == null )
849
852
{
@@ -858,7 +861,7 @@ private Series GetMatchingSeries(string seriesName, int? seriesYear, string targ
858
861
Name = info . ItemName ,
859
862
DtoOptions = new DtoOptions ( true )
860
863
861
- } ) . Cast < Series > ( ) . FirstOrDefault ( s => s . Path . StartsWith ( targetFolder ) ) ;
864
+ } ) . Cast < Series > ( ) . FirstOrDefault ( s => s . Path . StartsWith ( targetFolder , StringComparison . Ordinal ) ) ;
862
865
}
863
866
}
864
867
@@ -878,7 +881,7 @@ private string GetSeriesDirectoryName(Series series, TvFileOrganizationOptions o
878
881
var seriesFullName = seriesName ;
879
882
if ( series . ProductionYear . HasValue )
880
883
{
881
- seriesFullName = string . Format ( "{0 } ({1})" , seriesFullName , series . ProductionYear ) ;
884
+ seriesFullName = $ " { seriesFullName } ({ series . ProductionYear } )" ;
882
885
}
883
886
884
887
var seasonFolderName = options . SeriesFolderPattern .
@@ -930,7 +933,7 @@ private async Task<Episode> CreateNewEpisode(
930
933
931
934
if ( episodeSearch == null )
932
935
{
933
- var msg = string . Format ( "No provider metadata found for {0 } season {1 } episode {2}" , series . Name , seasonNumber , episodeNumber ) ;
936
+ var msg = $ "No provider metadata found for { series . Name } season { seasonNumber } episode { episodeNumber } " ;
934
937
_logger . LogWarning ( msg ) ;
935
938
throw new OrganizationException ( msg ) ;
936
939
}
0 commit comments