mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-23 06:25:24 -07:00
Media server entities into abstract classes
This commit is contained in:
parent
0ad5083ac9
commit
aeeba5b22d
11 changed files with 90 additions and 107 deletions
|
@ -914,10 +914,10 @@ namespace Ombi.Schedule.Jobs.Ombi
|
|||
var series = new List<PlexServerContent>();
|
||||
foreach (var plexEpisode in plexContent)
|
||||
{
|
||||
var alreadyAdded = series.FirstOrDefault(x => x.Key == plexEpisode.Series.Key);
|
||||
var alreadyAdded = series.FirstOrDefault(x => x.Key == plexEpisode.PlexSeries.Key);
|
||||
if (alreadyAdded != null)
|
||||
{
|
||||
var episodeExists = alreadyAdded.Episodes.Any(x => x.Key == plexEpisode.Key);
|
||||
var episodeExists = alreadyAdded.PlexEpisodes.Any(x => x.Key == plexEpisode.Key);
|
||||
if (!episodeExists)
|
||||
{
|
||||
alreadyAdded.Episodes.Add(plexEpisode);
|
||||
|
@ -925,8 +925,8 @@ namespace Ombi.Schedule.Jobs.Ombi
|
|||
}
|
||||
else
|
||||
{
|
||||
plexEpisode.Series.Episodes = new List<PlexEpisode> { plexEpisode };
|
||||
series.Add(plexEpisode.Series);
|
||||
plexEpisode.Series.Episodes = new List<IMediaServerEpisode> { plexEpisode };
|
||||
series.Add(plexEpisode.PlexSeries);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1042,18 +1042,18 @@ namespace Ombi.Schedule.Jobs.Ombi
|
|||
var series = new List<EmbyContent>();
|
||||
foreach (var episode in embyContent)
|
||||
{
|
||||
var alreadyAdded = series.FirstOrDefault(x => x.EmbyId == episode.Series.EmbyId);
|
||||
var alreadyAdded = series.FirstOrDefault(x => x.EmbyId == episode.EmbySeries.EmbyId);
|
||||
if (alreadyAdded != null)
|
||||
{
|
||||
alreadyAdded.Episodes.Add(episode);
|
||||
}
|
||||
else
|
||||
{
|
||||
episode.Series.Episodes = new List<EmbyEpisode>
|
||||
episode.Series.Episodes = new List<IMediaServerEpisode>
|
||||
{
|
||||
episode
|
||||
};
|
||||
series.Add(episode.Series);
|
||||
series.Add(episode.EmbySeries);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1145,18 +1145,18 @@ namespace Ombi.Schedule.Jobs.Ombi
|
|||
var series = new List<JellyfinContent>();
|
||||
foreach (var episode in jellyfinContent)
|
||||
{
|
||||
var alreadyAdded = series.FirstOrDefault(x => x.JellyfinId == episode.Series.JellyfinId);
|
||||
var alreadyAdded = series.FirstOrDefault(x => x.JellyfinId == episode.JellyfinSeries.JellyfinId);
|
||||
if (alreadyAdded != null)
|
||||
{
|
||||
alreadyAdded.Episodes.Add(episode);
|
||||
}
|
||||
else
|
||||
{
|
||||
episode.Series.Episodes = new List<JellyfinEpisode>
|
||||
episode.Series.Episodes = new List<IMediaServerEpisode>
|
||||
{
|
||||
episode
|
||||
};
|
||||
series.Add(episode.Series);
|
||||
series.Add(episode.JellyfinSeries);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ namespace Ombi.Schedule.Jobs.Plex
|
|||
// Let's try and match the series by name
|
||||
seriesEpisodes = plexEpisodes.Where(x =>
|
||||
x.Series.Title == child.Title &&
|
||||
x.Series.ReleaseYear == child.ParentRequest.ReleaseDate.Year.ToString());
|
||||
x.PlexSeries.ReleaseYear == child.ParentRequest.ReleaseDate.Year.ToString());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Store.Entities;
|
||||
|
@ -42,20 +43,20 @@ namespace Ombi.Store.Context
|
|||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
builder.Entity<PlexServerContent>().HasMany(x => x.Episodes)
|
||||
.WithOne(x => x.Series)
|
||||
builder.Entity<PlexServerContent>().HasMany(x => (ICollection<PlexEpisode>) x.Episodes)
|
||||
.WithOne(x => (PlexServerContent) x.Series)
|
||||
.HasPrincipalKey(x => x.Key)
|
||||
.HasForeignKey(x => x.GrandparentKey);
|
||||
|
||||
builder.Entity<EmbyEpisode>()
|
||||
.HasOne(p => p.Series)
|
||||
.WithMany(b => b.Episodes)
|
||||
.HasOne(p => (EmbyContent) p.Series)
|
||||
.WithMany(b => (ICollection<EmbyEpisode>) b.Episodes)
|
||||
.HasPrincipalKey(x => x.EmbyId)
|
||||
.HasForeignKey(p => p.ParentId);
|
||||
|
||||
builder.Entity<JellyfinEpisode>()
|
||||
.HasOne(p => p.Series)
|
||||
.WithMany(b => b.Episodes)
|
||||
.HasOne(p => (JellyfinContent) p.Series)
|
||||
.WithMany(b => (ICollection<JellyfinEpisode>) b.Episodes)
|
||||
.HasPrincipalKey(x => x.JellyfinId)
|
||||
.HasForeignKey(p => p.ParentId);
|
||||
|
||||
|
|
|
@ -32,34 +32,14 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||
namespace Ombi.Store.Entities
|
||||
{
|
||||
[Table("EmbyContent")]
|
||||
public class EmbyContent : Entity, IMediaServerContent<EmbyEpisode>
|
||||
public class EmbyContent : MediaServerContent
|
||||
{
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// OBSOLETE, Cannot delete due to DB migration issues with SQLite
|
||||
/// </summary>
|
||||
public string ProviderId { get; set; }
|
||||
public string EmbyId { get; set; }
|
||||
public MediaType Type { get; set; }
|
||||
public DateTime AddedAt { get; set; }
|
||||
|
||||
public string ImdbId { get; set; }
|
||||
public string TheMovieDbId { get; set; }
|
||||
public string TvDbId { get; set; }
|
||||
|
||||
public string Url { get; set; }
|
||||
|
||||
public ICollection<EmbyEpisode> Episodes { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public bool HasImdb => !string.IsNullOrEmpty(ImdbId);
|
||||
|
||||
[NotMapped]
|
||||
public bool HasTvDb => !string.IsNullOrEmpty(TvDbId);
|
||||
|
||||
[NotMapped]
|
||||
public bool HasTheMovieDb => !string.IsNullOrEmpty(TheMovieDbId);
|
||||
}
|
||||
|
||||
}
|
|
@ -32,12 +32,9 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
|||
namespace Ombi.Store.Entities
|
||||
{
|
||||
[Table("EmbyEpisode")]
|
||||
public class EmbyEpisode : Entity, IMediaServerEpisode<EmbyContent>
|
||||
public class EmbyEpisode : MediaServerEpisode
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string EmbyId { get; set; }
|
||||
public int EpisodeNumber { get; set; }
|
||||
public int SeasonNumber { get; set; }
|
||||
public string ParentId { get; set; }
|
||||
/// <summary>
|
||||
/// NOT USED
|
||||
|
@ -47,7 +44,11 @@ namespace Ombi.Store.Entities
|
|||
public string TvDbId { get; set; }
|
||||
public string ImdbId { get; set; }
|
||||
public string TheMovieDbId { get; set; }
|
||||
|
||||
public EmbyContent Series { get; set; }
|
||||
[NotMapped]
|
||||
public EmbyContent EmbySeries
|
||||
{
|
||||
get => (EmbyContent)Series;
|
||||
set => Series = value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||
|
||||
namespace Ombi.Store.Entities
|
||||
{
|
||||
public interface IMediaServerContent<IMediaServerEpisode>
|
||||
public interface IMediaServerContent
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string ImdbId { get; set; }
|
||||
|
@ -28,7 +28,7 @@ namespace Ombi.Store.Entities
|
|||
public bool HasTheMovieDb => !string.IsNullOrEmpty(TheMovieDbId);
|
||||
}
|
||||
|
||||
public interface IMediaServerEpisode<IMediaServerContent>
|
||||
public interface IMediaServerEpisode
|
||||
{
|
||||
public int EpisodeNumber { get; set; }
|
||||
public int SeasonNumber { get; set; }
|
||||
|
|
|
@ -32,34 +32,14 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||
namespace Ombi.Store.Entities
|
||||
{
|
||||
[Table("JellyfinContent")]
|
||||
public class JellyfinContent : Entity, IMediaServerContent<JellyfinEpisode>
|
||||
public class JellyfinContent : MediaServerContent
|
||||
{
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// OBSOLETE, Cannot delete due to DB migration issues with SQLite
|
||||
/// </summary>
|
||||
public string ProviderId { get; set; }
|
||||
public string JellyfinId { get; set; }
|
||||
public MediaType Type { get; set; }
|
||||
public DateTime AddedAt { get; set; }
|
||||
|
||||
public string ImdbId { get; set; }
|
||||
public string TheMovieDbId { get; set; }
|
||||
public string TvDbId { get; set; }
|
||||
|
||||
public string Url { get; set; }
|
||||
|
||||
public ICollection<JellyfinEpisode> Episodes { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public bool HasImdb => !string.IsNullOrEmpty(ImdbId);
|
||||
|
||||
[NotMapped]
|
||||
public bool HasTvDb => !string.IsNullOrEmpty(TvDbId);
|
||||
|
||||
[NotMapped]
|
||||
public bool HasTheMovieDb => !string.IsNullOrEmpty(TheMovieDbId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,12 +32,9 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
|||
namespace Ombi.Store.Entities
|
||||
{
|
||||
[Table("JellyfinEpisode")]
|
||||
public class JellyfinEpisode : Entity, IMediaServerEpisode<JellyfinContent>
|
||||
public class JellyfinEpisode : MediaServerEpisode
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string JellyfinId { get; set; }
|
||||
public int EpisodeNumber { get; set; }
|
||||
public int SeasonNumber { get; set; }
|
||||
public string ParentId { get; set; }
|
||||
/// <summary>
|
||||
/// NOT USED
|
||||
|
@ -47,7 +44,11 @@ namespace Ombi.Store.Entities
|
|||
public string TvDbId { get; set; }
|
||||
public string ImdbId { get; set; }
|
||||
public string TheMovieDbId { get; set; }
|
||||
|
||||
public JellyfinContent Series { get; set; }
|
||||
[NotMapped]
|
||||
public JellyfinContent JellyfinSeries
|
||||
{
|
||||
get => (JellyfinContent)Series;
|
||||
set => Series = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
39
src/Ombi.Store/Entities/MediaServerContent.cs
Normal file
39
src/Ombi.Store/Entities/MediaServerContent.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Ombi.Store.Entities
|
||||
{
|
||||
public abstract class MediaServerContent: Entity, IMediaServerContent
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string ImdbId { get; set; }
|
||||
public string TvDbId { get; set; }
|
||||
public string TheMovieDbId { get; set; }
|
||||
public MediaType Type { get; set; }
|
||||
|
||||
public string Url { get; set; }
|
||||
|
||||
public ICollection<IMediaServerEpisode> Episodes { get; set; }
|
||||
|
||||
public DateTime AddedAt { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public bool HasImdb => !string.IsNullOrEmpty(ImdbId);
|
||||
|
||||
[NotMapped]
|
||||
public bool HasTvDb => !string.IsNullOrEmpty(TvDbId);
|
||||
|
||||
[NotMapped]
|
||||
public bool HasTheMovieDb => !string.IsNullOrEmpty(TheMovieDbId);
|
||||
}
|
||||
|
||||
public abstract class MediaServerEpisode: Entity, IMediaServerEpisode
|
||||
{
|
||||
public int EpisodeNumber { get; set; }
|
||||
public int SeasonNumber { get; set; }
|
||||
public string Title { get; set; }
|
||||
|
||||
public IMediaServerContent Series { get; set; }
|
||||
}
|
||||
}
|
|
@ -3,28 +3,22 @@
|
|||
namespace Ombi.Store.Entities
|
||||
{
|
||||
[Table("PlexEpisode")]
|
||||
public class PlexEpisode : Entity, IMediaServerEpisode<PlexServerContent>
|
||||
public class PlexEpisode : MediaServerEpisode
|
||||
{
|
||||
public int EpisodeNumber { get; set; }
|
||||
public int SeasonNumber { get; set; }
|
||||
public int Key { get; set; } // RatingKey
|
||||
public string Title { get; set; }
|
||||
/// <summary>
|
||||
/// The Season key
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The parent key.
|
||||
/// </value>
|
||||
public int ParentKey { get; set; }
|
||||
/// <summary>
|
||||
/// The Series key
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The grandparent key.
|
||||
/// </value>
|
||||
public int GrandparentKey { get; set; }
|
||||
|
||||
|
||||
public PlexServerContent Series { get; set; }
|
||||
[NotMapped]
|
||||
public PlexServerContent PlexSeries
|
||||
{
|
||||
get => (PlexServerContent)Series;
|
||||
set => Series = value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -32,38 +32,25 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||
namespace Ombi.Store.Entities
|
||||
{
|
||||
[Table("PlexServerContent")]
|
||||
public class PlexServerContent : Entity, IMediaServerContent<PlexEpisode>
|
||||
public class PlexServerContent : MediaServerContent
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string ReleaseYear { get; set; }
|
||||
public string ImdbId { get; set; }
|
||||
public string TvDbId { get; set; }
|
||||
public string TheMovieDbId { get; set; }
|
||||
public MediaType Type { get; set; }
|
||||
|
||||
public string Url { get; set; }
|
||||
|
||||
//public IMediaServerEpisode Episode { get; set; }
|
||||
public ICollection<PlexEpisode> Episodes { get; set; }
|
||||
public ICollection<PlexSeasonsContent> Seasons { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Plex's internal ID for this item
|
||||
/// </summary>
|
||||
public int Key { get; set; }
|
||||
public DateTime AddedAt { get; set; }
|
||||
public string Quality { get; set; }
|
||||
|
||||
public int? RequestId { get; set; }
|
||||
|
||||
|
||||
[NotMapped]
|
||||
public bool HasImdb => !string.IsNullOrEmpty(ImdbId);
|
||||
|
||||
[NotMapped]
|
||||
public bool HasTvDb => !string.IsNullOrEmpty(TvDbId);
|
||||
|
||||
[NotMapped]
|
||||
public bool HasTheMovieDb => !string.IsNullOrEmpty(TheMovieDbId);
|
||||
public ICollection<PlexEpisode> PlexEpisodes
|
||||
{
|
||||
get => (ICollection<PlexEpisode>)Episodes;
|
||||
set => Episodes = (ICollection<IMediaServerEpisode>)value;
|
||||
}
|
||||
}
|
||||
|
||||
[Table("PlexSeasonsContent")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue