* rework television media * refactor poster saving * television and movie views are working again * remove dead code * use paper styling for all cards * add show poster, plot to seasons page * remove missing shows; cleanup interfaces * fix split show display (same show in different folders/sources) * add placeholder "add to schedule" button * no more duplicate television shows, even with the same show split across sources * stop releasing CLI for now * use season number as season placeholder * add television shows to collections * add television seasons to collections * add television episodes to collections * add movies to collections * remove movies, shows, seasons, episodes from collections * fix page width and menus * fix buffer size defaults * fix chronological episode ordering * allow deleting media collections * don't get stuck building a playout with an empty collection * schedule editing and playouts work again * minor cleanup * remove dead code * fix bugs with viewing movies as they are loading * add scanner tests; support nested movie folders * update collections docs * rearrange order of schedule items * add show and season to schedule * delete schedules that use legacy collections, reset all posters * move cleanup to new migration * load fallback metadata when nfo fails; don't require metadata in ui * update readme and screenshots
73 lines
2.5 KiB
C#
73 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using ErsatzTV.Core;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Core.Interfaces.Repositories;
|
|
using LanguageExt;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using static LanguageExt.Prelude;
|
|
|
|
namespace ErsatzTV.Infrastructure.Data.Repositories
|
|
{
|
|
public class MovieRepository : IMovieRepository
|
|
{
|
|
private readonly TvContext _dbContext;
|
|
|
|
public MovieRepository(TvContext dbContext) => _dbContext = dbContext;
|
|
|
|
public Task<Option<MovieMediaItem>> GetMovie(int movieId) =>
|
|
_dbContext.MovieMediaItems
|
|
.Include(m => m.Metadata)
|
|
.SingleOrDefaultAsync(m => m.Id == movieId)
|
|
.Map(Optional);
|
|
|
|
public async Task<Either<BaseError, MovieMediaItem>> GetOrAdd(int mediaSourceId, string path)
|
|
{
|
|
Option<MovieMediaItem> maybeExisting = await _dbContext.MovieMediaItems
|
|
.Include(i => i.Metadata)
|
|
.SingleOrDefaultAsync(i => i.Path == path);
|
|
|
|
return await maybeExisting.Match(
|
|
mediaItem => Right<BaseError, MovieMediaItem>(mediaItem).AsTask(),
|
|
async () => await AddMovie(mediaSourceId, path));
|
|
}
|
|
|
|
public async Task<bool> Update(MovieMediaItem movie)
|
|
{
|
|
_dbContext.MovieMediaItems.Update(movie);
|
|
return await _dbContext.SaveChangesAsync() > 0;
|
|
}
|
|
|
|
public Task<int> GetMovieCount() =>
|
|
_dbContext.MovieMediaItems
|
|
.AsNoTracking()
|
|
.CountAsync();
|
|
|
|
public Task<List<MovieMediaItem>> GetPagedMovies(int pageNumber, int pageSize) =>
|
|
_dbContext.MovieMediaItems
|
|
.Include(s => s.Metadata)
|
|
.OrderBy(s => s.Metadata.SortTitle)
|
|
.Skip((pageNumber - 1) * pageSize)
|
|
.Take(pageSize)
|
|
.AsNoTracking()
|
|
.ToListAsync();
|
|
|
|
private async Task<Either<BaseError, MovieMediaItem>> AddMovie(int mediaSourceId, string path)
|
|
{
|
|
try
|
|
{
|
|
var movie = new MovieMediaItem { MediaSourceId = mediaSourceId, Path = path };
|
|
await _dbContext.MovieMediaItems.AddAsync(movie);
|
|
await _dbContext.SaveChangesAsync();
|
|
return movie;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BaseError.New(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|