private async Task <Either <BaseError, Unit> > ScanSeasons( PlexLibrary plexMediaSourceLibrary, PlexShow show, PlexConnection connection, PlexServerAuthToken token) { Either <BaseError, List <PlexSeason> > entries = await _plexServerApiClient.GetShowSeasons( plexMediaSourceLibrary, show, connection, token); return(await entries.Match <Task <Either <BaseError, Unit> > >( async seasonEntries => { foreach (PlexSeason incoming in seasonEntries) { incoming.ShowId = show.Id; // TODO: figure out how to rebuild playlists Either <BaseError, PlexSeason> maybeSeason = await _televisionRepository .GetOrAddPlexSeason(plexMediaSourceLibrary, incoming) .BindT(existing => UpdateArtwork(existing, incoming)); await maybeSeason.Match( async season => await ScanEpisodes(plexMediaSourceLibrary, season, connection, token), error => { _logger.LogWarning( "Error processing plex show at {Key}: {Error}", incoming.Key, error.Value); return Task.CompletedTask; }); } var seasonKeys = seasonEntries.Map(s => s.Key).ToList(); await _televisionRepository.RemoveMissingPlexSeasons(show.Key, seasonKeys); return Unit.Default; }, error => { _logger.LogWarning( "Error synchronizing plex library {Path}: {Error}", plexMediaSourceLibrary.Name, error.Value); return Left <BaseError, Unit>(error).AsTask(); })); }