* wip * start to add jellyfin tables to db * code cleanup * finish adding jellyfin media source * sync jellyfin libraries * display list of jellyfin libraries * toggle jellyfin library sync * edit jellyfin path replacements * noop jellyfin scanners * get jellyfin admin user id on startup * implement jellyfin disconnect * add jellyfin libraries to list; start to query jellyfin library items * code cleanup * start to project jellyfin movies * save new jellyfin movies to db * basic jellyfin movie update * load jellyfin actor artwork * load jellyfin movie poster and fan art * more jellyfin artwork fixes, sync audio streams * jellyfin playback sort of works * skip jellyfin movies that are inaccessible * use ffprobe for jellyfin movie statistics * code cleanup * store jellyfin operating system * more jellyfin movie updates * update jellyfin movie poster and fan art * add jellyfin tv types * sync jellyfin shows * sync jellyfin seasons * sync jellyfin episodes * remove missing jellyfin television items * delete empty jellyfin seasons and shows * fix jellyfin updates * fix indexing jellyfin movie and show languages
74 lines
2.6 KiB
C#
74 lines
2.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Core.Interfaces.Repositories;
|
|
using LanguageExt;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
|
|
|
namespace ErsatzTV.Infrastructure.Data.Repositories
|
|
{
|
|
public class FFmpegProfileRepository : IFFmpegProfileRepository
|
|
{
|
|
private readonly TvContext _dbContext;
|
|
private readonly IDbContextFactory<TvContext> _dbContextFactory;
|
|
|
|
public FFmpegProfileRepository(IDbContextFactory<TvContext> dbContextFactory, TvContext dbContext)
|
|
{
|
|
_dbContextFactory = dbContextFactory;
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
public async Task<FFmpegProfile> Add(FFmpegProfile ffmpegProfile)
|
|
{
|
|
await _dbContext.FFmpegProfiles.AddAsync(ffmpegProfile);
|
|
await _dbContext.SaveChangesAsync();
|
|
return ffmpegProfile;
|
|
}
|
|
|
|
public async Task<Option<FFmpegProfile>> Get(int id) =>
|
|
await _dbContext.FFmpegProfiles
|
|
.Include(p => p.Resolution)
|
|
.OrderBy(p => p.Id)
|
|
.SingleOrDefaultAsync(p => p.Id == id);
|
|
|
|
public Task<List<FFmpegProfile>> GetAll() =>
|
|
_dbContext.FFmpegProfiles
|
|
.Include(p => p.Resolution)
|
|
.ToListAsync();
|
|
|
|
public Task Update(FFmpegProfile ffmpegProfile)
|
|
{
|
|
_dbContext.FFmpegProfiles.Update(ffmpegProfile);
|
|
return _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task Delete(int ffmpegProfileId)
|
|
{
|
|
FFmpegProfile ffmpegProfile = await _dbContext.FFmpegProfiles.FindAsync(ffmpegProfileId);
|
|
_dbContext.FFmpegProfiles.Remove(ffmpegProfile);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task<FFmpegProfile> Copy(int ffmpegProfileId, string name)
|
|
{
|
|
await using TvContext dbContext = _dbContextFactory.CreateDbContext();
|
|
FFmpegProfile ffmpegProfile = await dbContext.FFmpegProfiles.FindAsync(ffmpegProfileId);
|
|
|
|
PropertyValues values = dbContext.Entry(ffmpegProfile).CurrentValues.Clone();
|
|
values["Id"] = 0;
|
|
|
|
var clone = new FFmpegProfile();
|
|
await dbContext.AddAsync(clone);
|
|
dbContext.Entry(clone).CurrentValues.SetValues(values);
|
|
clone.Name = name;
|
|
|
|
await dbContext.SaveChangesAsync();
|
|
await dbContext.Entry(clone).Reference(f => f.Resolution).LoadAsync();
|
|
|
|
return clone;
|
|
}
|
|
}
|
|
}
|