Working on the movie matching. Stop dupes #1869

pull/1941/head
tidusjar 7 years ago
parent c7d88f8808
commit 6002b202d9

@ -122,7 +122,12 @@ namespace Ombi.Schedule.Jobs.Plex
} }
// Do we already have this item? // 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) if (existingContent != null)
{ {
try try
@ -197,7 +202,12 @@ namespace Ombi.Schedule.Jobs.Plex
foreach (var movie in content?.Metadata ?? new Metadata[] { }) foreach (var movie in content?.Metadata ?? new Metadata[] { })
{ {
// Let's check if we have this movie // 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) if (existing != null)
{ {
continue; continue;

@ -1,5 +1,7 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Ombi.Store.Entities; using Ombi.Store.Entities;
@ -15,5 +17,7 @@ namespace Ombi.Store.Repository
Task<PlexEpisode> Add(PlexEpisode content); Task<PlexEpisode> Add(PlexEpisode content);
Task<PlexEpisode> GetEpisodeByKey(int key); Task<PlexEpisode> GetEpisodeByKey(int key);
Task AddRange(IEnumerable<PlexEpisode> content); Task AddRange(IEnumerable<PlexEpisode> content);
IEnumerable<PlexServerContent> GetWhereContentByCustom(Expression<Func<PlexServerContent, bool>> predicate);
Task<PlexServerContent> GetFirstContentByCustom(Expression<Func<PlexServerContent, bool>> predicate);
} }
} }

@ -25,8 +25,10 @@
// ************************************************************************/ // ************************************************************************/
#endregion #endregion
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Ombi.Store.Context; 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); return await Db.PlexServerContent.Include(x => x.Seasons).FirstOrDefaultAsync(x => x.Key == key);
} }
public IEnumerable<PlexServerContent> GetWhereContentByCustom(Expression<Func<PlexServerContent, bool>> predicate)
{
return Db.PlexServerContent.Where(predicate);
}
public async Task<PlexServerContent> GetFirstContentByCustom(Expression<Func<PlexServerContent, bool>> predicate)
{
return await Db.PlexServerContent.FirstOrDefaultAsync(predicate);
}
public async Task Update(PlexServerContent existingContent) public async Task Update(PlexServerContent existingContent)
{ {
Db.PlexServerContent.Update(existingContent); Db.PlexServerContent.Update(existingContent);

Loading…
Cancel
Save