diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs index 5472d671d..e44deb1df 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs @@ -122,7 +122,12 @@ namespace Ombi.Schedule.Jobs.Plex } // Do we already have this item? - var existingContent = await Repo.GetByKey(show.ratingKey); + // Let's try and match + var existingContent = await Repo.GetFirstContentByCustom(x => x.Title == show.title + && x.ReleaseYear == show.year.ToString() + && x.Type == PlexMediaTypeEntity.Show); + // The ratingKey keeps changing... + //var existingContent = await Repo.GetByKey(show.ratingKey); if (existingContent != null) { try @@ -197,7 +202,12 @@ namespace Ombi.Schedule.Jobs.Plex foreach (var movie in content?.Metadata ?? new Metadata[] { }) { // Let's check if we have this movie - var existing = await Repo.GetByKey(movie.ratingKey); + + var existing = await Repo.GetFirstContentByCustom(x => x.Title == movie.title + && x.ReleaseYear == movie.year.ToString() + && x.Type == PlexMediaTypeEntity.Movie); + // The rating key keeps changing + //var existing = await Repo.GetByKey(movie.ratingKey); if (existing != null) { continue; diff --git a/src/Ombi.Store/Repository/IPlexContentRepository.cs b/src/Ombi.Store/Repository/IPlexContentRepository.cs index 87d811e5d..cb244dcd2 100644 --- a/src/Ombi.Store/Repository/IPlexContentRepository.cs +++ b/src/Ombi.Store/Repository/IPlexContentRepository.cs @@ -1,5 +1,7 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Threading.Tasks; using Ombi.Store.Entities; @@ -15,5 +17,7 @@ namespace Ombi.Store.Repository Task Add(PlexEpisode content); Task GetEpisodeByKey(int key); Task AddRange(IEnumerable content); + IEnumerable GetWhereContentByCustom(Expression> predicate); + Task GetFirstContentByCustom(Expression> predicate); } } \ No newline at end of file diff --git a/src/Ombi.Store/Repository/PlexContentRepository.cs b/src/Ombi.Store/Repository/PlexContentRepository.cs index 284489cf4..e1df9e183 100644 --- a/src/Ombi.Store/Repository/PlexContentRepository.cs +++ b/src/Ombi.Store/Repository/PlexContentRepository.cs @@ -25,8 +25,10 @@ // ************************************************************************/ #endregion +using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Ombi.Store.Context; @@ -74,6 +76,16 @@ namespace Ombi.Store.Repository return await Db.PlexServerContent.Include(x => x.Seasons).FirstOrDefaultAsync(x => x.Key == key); } + public IEnumerable GetWhereContentByCustom(Expression> predicate) + { + return Db.PlexServerContent.Where(predicate); + } + + public async Task GetFirstContentByCustom(Expression> predicate) + { + return await Db.PlexServerContent.FirstOrDefaultAsync(predicate); + } + public async Task Update(PlexServerContent existingContent) { Db.PlexServerContent.Update(existingContent);