|
|
|
|
@ -1,4 +1,5 @@
@@ -1,4 +1,5 @@
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
using ErsatzTV.Core.Domain; |
|
|
|
|
using ErsatzTV.Core.Interfaces.Plex; |
|
|
|
|
@ -38,19 +39,26 @@ namespace ErsatzTV.Core.Plex
@@ -38,19 +39,26 @@ namespace ErsatzTV.Core.Plex
|
|
|
|
|
await entries.Match( |
|
|
|
|
async movieEntries => |
|
|
|
|
{ |
|
|
|
|
foreach (PlexMovie entry in movieEntries) |
|
|
|
|
foreach (PlexMovie incoming in movieEntries) |
|
|
|
|
{ |
|
|
|
|
// TODO: optimize dbcontext use here, do we need tracking? can we make partial updates with dapper?
|
|
|
|
|
// TODO: figure out how to rebuild playlists
|
|
|
|
|
Either<BaseError, PlexMovie> maybeMovie = await _movieRepository |
|
|
|
|
.GetOrAdd(plexMediaSourceLibrary, entry) |
|
|
|
|
.BindT(UpdateIfNeeded); |
|
|
|
|
.GetOrAdd(plexMediaSourceLibrary, incoming) |
|
|
|
|
.BindT(existing => UpdateStatistics(existing, incoming)) |
|
|
|
|
.BindT(existing => UpdateMetadata(existing, incoming)) |
|
|
|
|
.BindT(existing => UpdateArtwork(existing, incoming)); |
|
|
|
|
|
|
|
|
|
maybeMovie.IfLeft( |
|
|
|
|
error => _logger.LogWarning( |
|
|
|
|
"Error processing plex movie at {Key}: {Error}", |
|
|
|
|
entry.Key, |
|
|
|
|
error.Value)); |
|
|
|
|
await maybeMovie.Match( |
|
|
|
|
async movie => await _movieRepository.Update(movie), |
|
|
|
|
error => |
|
|
|
|
{ |
|
|
|
|
_logger.LogWarning( |
|
|
|
|
"Error processing plex movie at {Key}: {Error}", |
|
|
|
|
incoming.Key, |
|
|
|
|
error.Value); |
|
|
|
|
return Task.CompletedTask; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
error => |
|
|
|
|
@ -68,10 +76,32 @@ namespace ErsatzTV.Core.Plex
@@ -68,10 +76,32 @@ namespace ErsatzTV.Core.Plex
|
|
|
|
|
return Unit.Default; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Task<Either<BaseError, PlexMovie>> UpdateIfNeeded(PlexMovie plexMovie) => |
|
|
|
|
// .BindT(movie => UpdateStatistics(movie, ffprobePath).MapT(_ => movie))
|
|
|
|
|
// .BindT(UpdateMetadata)
|
|
|
|
|
// .BindT(UpdatePoster);
|
|
|
|
|
Right<BaseError, PlexMovie>(plexMovie).AsTask(); |
|
|
|
|
private Task<Either<BaseError, PlexMovie>> UpdateStatistics(PlexMovie existing, PlexMovie incoming) => |
|
|
|
|
Right<BaseError, PlexMovie>(existing).AsTask(); |
|
|
|
|
|
|
|
|
|
private Task<Either<BaseError, PlexMovie>> UpdateMetadata(PlexMovie existing, PlexMovie incoming) |
|
|
|
|
{ |
|
|
|
|
MovieMetadata existingMetadata = existing.MovieMetadata.Head(); |
|
|
|
|
MovieMetadata incomingMetadata = incoming.MovieMetadata.Head(); |
|
|
|
|
|
|
|
|
|
foreach (Genre genre in existingMetadata.Genres |
|
|
|
|
.Filter(g => incomingMetadata.Genres.All(g2 => g2.Name != g.Name)) |
|
|
|
|
.ToList()) |
|
|
|
|
{ |
|
|
|
|
existingMetadata.Genres.Remove(genre); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach (Genre genre in incomingMetadata.Genres |
|
|
|
|
.Filter(g => existingMetadata.Genres.All(g2 => g2.Name != g.Name)) |
|
|
|
|
.ToList()) |
|
|
|
|
{ |
|
|
|
|
existingMetadata.Genres.Add(genre); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return Right<BaseError, PlexMovie>(existing).AsTask(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Task<Either<BaseError, PlexMovie>> UpdateArtwork(PlexMovie existing, PlexMovie incoming) => |
|
|
|
|
Right<BaseError, PlexMovie>(existing).AsTask(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|