Added the emby episode cacher and the job to check if items are available on emby #1464 #865

This commit is contained in:
tidusjar 2017-09-02 00:46:04 +01:00
parent 012a82ca2d
commit b8224f5895
12 changed files with 358 additions and 21 deletions

View file

@ -18,6 +18,7 @@ namespace Ombi.Store.Context
DbSet<PlexEpisode> PlexEpisode { get; set; }
DbSet<RadarrCache> RadarrCache { get; set; }
DbSet<EmbyContent> EmbyContent { get; set; }
DbSet<EmbyEpisode> EmbyEpisode { get; set; }
DatabaseFacade Database { get; }
EntityEntry<T> Entry<T>(T entry) where T : class;
EntityEntry<TEntity> Attach<TEntity>(TEntity entity) where TEntity : class;

View file

@ -29,6 +29,7 @@ namespace Ombi.Store.Context
public DbSet<PlexEpisode> PlexEpisode { get; set; }
public DbSet<RadarrCache> RadarrCache { get; set; }
public DbSet<EmbyContent> EmbyContent { get; set; }
public DbSet<EmbyEpisode> EmbyEpisode { get; set; }
public DbSet<MovieRequests> MovieRequests { get; set; }
public DbSet<TvRequests> TvRequests { get; set; }
@ -53,6 +54,12 @@ namespace Ombi.Store.Context
.WithMany(b => b.Episodes)
.HasPrincipalKey(x => x.Key)
.HasForeignKey(p => p.GrandparentKey);
builder.Entity<EmbyEpisode>()
.HasOne(p => p.Series)
.WithMany(b => b.Episodes)
.HasPrincipalKey(x => x.EmbyId)
.HasForeignKey(p => p.ParentId);
base.OnModelCreating(builder);
}

View file

@ -26,6 +26,7 @@
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace Ombi.Store.Entities
@ -38,6 +39,9 @@ namespace Ombi.Store.Entities
public string EmbyId { get; set; }
public EmbyMediaType Type { get; set; }
public DateTime AddedAt { get; set; }
public ICollection<EmbyEpisode> Episodes { get; set; }
}
public enum EmbyMediaType

View file

@ -0,0 +1,47 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2017 Jamie Rees
// File: EmbyEpisode.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore.Metadata;
namespace Ombi.Store.Entities
{
[Table("EmbyEpisode")]
public class EmbyEpisode : Entity
{
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; }
public string ProviderId { get; set; }
public DateTime AddedAt { get; set; }
public EmbyContent Series { get; set; }
}
}

View file

@ -88,25 +88,26 @@ namespace Ombi.Store.Repository
await Db.SaveChangesAsync();
}
//public IQueryable<PlexEpisode> GetAllEpisodes()
//{
// return Db.PlexEpisode.AsQueryable();
//}
public IQueryable<EmbyEpisode> GetAllEpisodes()
{
return Db.EmbyEpisode.AsQueryable();
}
//public async Task<PlexEpisode> Add(PlexEpisode content)
//{
// await Db.PlexEpisode.AddAsync(content);
// await Db.SaveChangesAsync();
// return content;
//}
//public async Task<PlexEpisode> GetEpisodeByKey(int key)
//{
// return await Db.PlexEpisode.FirstOrDefaultAsync(x => x.Key == key);
//}
//public async Task AddRange(IEnumerable<PlexEpisode> content)
//{
// Db.PlexEpisode.AddRange(content);
// await Db.SaveChangesAsync();
//}
public async Task<EmbyEpisode> Add(EmbyEpisode content)
{
await Db.EmbyEpisode.AddAsync(content);
await Db.SaveChangesAsync();
return content;
}
public async Task<EmbyEpisode> GetEpisodeByEmbyId(string key)
{
return await Db.EmbyEpisode.FirstOrDefaultAsync(x => x.EmbyId == key);
}
public async Task AddRange(IEnumerable<EmbyEpisode> content)
{
Db.EmbyEpisode.AddRange(content);
await Db.SaveChangesAsync();
}
}
}

View file

@ -15,5 +15,9 @@ namespace Ombi.Store.Repository
Task<IEnumerable<EmbyContent>> GetAll();
Task<EmbyContent> GetByEmbyId(string embyId);
Task Update(EmbyContent existingContent);
IQueryable<EmbyEpisode> GetAllEpisodes();
Task<EmbyEpisode> Add(EmbyEpisode content);
Task<EmbyEpisode> GetEpisodeByEmbyId(string key);
Task AddRange(IEnumerable<EmbyEpisode> content);
}
}