Fixed the issue where Ombi would pickup a TV Show/Movie as available when it has the same TMDB Id as something that is already available.

pull/4225/head
tidusjar 4 years ago
parent 0793050913
commit 31427c387e

@ -27,9 +27,12 @@ namespace Ombi.Core.Rule.Rules.Search
var useTheMovieDb = false; var useTheMovieDb = false;
var useId = false; var useId = false;
var useTvDb = false; var useTvDb = false;
PlexMediaTypeEntity type = ConvertType(obj.Type);
if (obj.ImdbId.HasValue()) if (obj.ImdbId.HasValue())
{ {
item = await PlexContentRepository.Get(obj.ImdbId, ProviderType.ImdbId); item = await PlexContentRepository.GetByType(obj.ImdbId, ProviderType.ImdbId, type);
if (item != null) if (item != null)
{ {
useImdb = true; useImdb = true;
@ -39,7 +42,7 @@ namespace Ombi.Core.Rule.Rules.Search
{ {
if (obj.Id > 0) if (obj.Id > 0)
{ {
item = await PlexContentRepository.Get(obj.Id.ToString(), ProviderType.TheMovieDbId); item = await PlexContentRepository.GetByType(obj.Id.ToString(), ProviderType.TheMovieDbId, type);
if (item != null) if (item != null)
{ {
useId = true; useId = true;
@ -47,7 +50,7 @@ namespace Ombi.Core.Rule.Rules.Search
} }
if (obj.TheMovieDbId.HasValue()) if (obj.TheMovieDbId.HasValue())
{ {
item = await PlexContentRepository.Get(obj.TheMovieDbId, ProviderType.TheMovieDbId); item = await PlexContentRepository.GetByType(obj.TheMovieDbId, ProviderType.TheMovieDbId, type);
if (item != null) if (item != null)
{ {
useTheMovieDb = true; useTheMovieDb = true;
@ -58,7 +61,7 @@ namespace Ombi.Core.Rule.Rules.Search
{ {
if (obj.TheTvDbId.HasValue()) if (obj.TheTvDbId.HasValue())
{ {
item = await PlexContentRepository.Get(obj.TheTvDbId, ProviderType.TvDbId); item = await PlexContentRepository.GetByType(obj.TheTvDbId, ProviderType.TvDbId, type);
if (item != null) if (item != null)
{ {
useTvDb = true; useTvDb = true;
@ -100,6 +103,12 @@ namespace Ombi.Core.Rule.Rules.Search
return Success(); return Success();
} }
private PlexMediaTypeEntity ConvertType(RequestType type) =>
type switch
{
RequestType.Movie => PlexMediaTypeEntity.Movie,
RequestType.TvShow => PlexMediaTypeEntity.Show,
_ => PlexMediaTypeEntity.Movie,
};
} }
} }

@ -12,6 +12,7 @@ namespace Ombi.Store.Repository
{ {
Task<bool> ContentExists(string providerId); Task<bool> ContentExists(string providerId);
Task<PlexServerContent> Get(string providerId, ProviderType type); Task<PlexServerContent> Get(string providerId, ProviderType type);
Task<PlexServerContent> GetByType(string providerId, ProviderType type, PlexMediaTypeEntity plexType);
Task<PlexServerContent> GetByKey(int key); Task<PlexServerContent> GetByKey(int key);
Task Update(PlexServerContent existingContent); Task Update(PlexServerContent existingContent);
IQueryable<PlexEpisode> GetAllEpisodes(); IQueryable<PlexEpisode> GetAllEpisodes();

@ -79,6 +79,23 @@ namespace Ombi.Store.Repository
return null; return null;
} }
public async Task<PlexServerContent> GetByType(string providerId, ProviderType type, PlexMediaTypeEntity plexType)
{
switch (type)
{
case ProviderType.ImdbId:
return await Db.PlexServerContent.FirstOrDefaultAsync(x => x.ImdbId == providerId && x.Type == plexType);
case ProviderType.TheMovieDbId:
return await Db.PlexServerContent.FirstOrDefaultAsync(x => x.TheMovieDbId == providerId && x.Type == plexType);
case ProviderType.TvDbId:
return await Db.PlexServerContent.FirstOrDefaultAsync(x => x.TvDbId == providerId && x.Type == plexType);
default:
break;
}
return null;
}
public async Task<PlexServerContent> GetByKey(int key) public async Task<PlexServerContent> GetByKey(int key)
{ {
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);

Loading…
Cancel
Save