Browse Source

attach existing episodes to correct show and season when adding nfo metadata (#97)

pull/98/head
Jason Dove 5 years ago committed by GitHub
parent
commit
527d3c6e4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      ErsatzTV.Infrastructure/Data/Repositories/TelevisionRepository.cs

21
ErsatzTV.Infrastructure/Data/Repositories/TelevisionRepository.cs

@ -285,9 +285,24 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
.OrderBy(i => i.MediaVersions.First().MediaFiles.First().Path) .OrderBy(i => i.MediaVersions.First().MediaFiles.First().Path)
.SingleOrDefaultAsync(i => i.MediaVersions.First().MediaFiles.First().Path == path); .SingleOrDefaultAsync(i => i.MediaVersions.First().MediaFiles.First().Path == path);
return await maybeExisting.Match( return await maybeExisting.Match<Task<Either<BaseError, Episode>>>(
episode => Right<BaseError, Episode>(episode).AsTask(), async episode =>
() => AddEpisode(dbContext, season, libraryPath.Id, path)); {
// move the file to the new season if needed
// this can happen when adding NFO metadata to existing content
if (episode.SeasonId != season.Id)
{
episode.SeasonId = season.Id;
episode.Season = season;
await _dbConnection.ExecuteAsync(
@"UPDATE Episode SET SeasonId = @SeasonId WHERE Id = @EpisodeId",
new { SeasonId = season.Id, EpisodeId = episode.Id });
}
return episode;
},
async () => await AddEpisode(dbContext, season, libraryPath.Id, path));
} }
public Task<IEnumerable<string>> FindEpisodePaths(LibraryPath libraryPath) => public Task<IEnumerable<string>> FindEpisodePaths(LibraryPath libraryPath) =>

Loading…
Cancel
Save