public MovieService(IMapper mapper, MolliesMoviesContext context, ISystemClock clock, IOptions <MovieOptions> options) { _mapper = mapper; _context = context; _clock = clock; _options = options; }
public static async Task <MovieSource> GetLatestMovieBySourceAsync(this MolliesMoviesContext context, string source, CancellationToken cancellationToken = default) => await context.Set <MovieSource>() .Where(x => x.Source == source) .OrderByDescending(x => x.DateCreated) .FirstOrDefaultAsync(cancellationToken);
public static IQueryable <Movie> Movies(this MolliesMoviesContext context) => context.Set <Movie>() .AsNoTracking() .Include(x => x.MovieGenres) .ThenInclude(x => x.Genre) .Include(x => x.MovieSources) .ThenInclude(x => x.Torrents) .Include(x => x.DownloadedMovies) .ThenInclude(x => x.LocalMovie) .Include(x => x.TransmissionContexts) .ThenInclude(x => x.Statuses);
public ScraperService( IEnumerable <IScraper> scrapers, ISystemClock clock, ILogger <ScraperService> logger, IMapper mapper, MolliesMoviesContext context, IMovieService movieService, IPlexApiClient plexApiClient, IOptions <ScraperOptions> options) { _clock = clock; _logger = logger; _mapper = mapper; _context = context; _movieService = movieService; _plexApiClient = plexApiClient; _options = options; _scrapers = scrapers.ToList(); }
public TransmissionService( IOptions <TransmissionOptions> options, IMovieService movieService, ILogger <TransmissionService> logger, MolliesMoviesContext context, ISystemClock clock, IScraperService scraperService, IScraperBackgroundService scraperBackgroundService, IMapper mapper) { _options = options; _movieService = movieService; _logger = logger; _context = context; _clock = clock; _scraperService = scraperService; _scraperBackgroundService = scraperBackgroundService; _mapper = mapper; }
public ScrapeSession( string source, ScraperType type, DateTime?scrapeFrom, List <string> movieImdbCodes, List <string> localImdbCodes, MolliesMoviesContext context, ISystemClock clock, CancellationToken cancellationToken, MovieOptions options) { ScrapeFrom = scrapeFrom; _source = source; _type = type; MovieImdbCodes = movieImdbCodes; LocalImdbCodes = localImdbCodes; _context = context; _scrapeDate = clock.UtcNow; _cancellationToken = cancellationToken; _options = options; }
public static async Task <ICollection <Genre> > AssertGenresAsync( this MolliesMoviesContext context, ICollection <string> toAssert, CancellationToken cancellationToken = default) { var cleaned = toAssert.Select(x => x.Trim()).ToList(); var result = await context.Set <Genre>() .Where(x => cleaned.Contains(x.Name)) .ToListAsync(cancellationToken); var newGenres = cleaned.Except(result.Select(x => x.Name)).ToList(); if (newGenres.Any()) { var toAdd = newGenres.Select(x => new Genre { Name = x }).ToList(); result.AddRange(toAdd); await context.AddRangeAsync(toAdd, cancellationToken); await context.SaveChangesAsync(cancellationToken); } return(result); }
public static IQueryable <TransmissionContext> TransmissionContexts(this MolliesMoviesContext context) => context.Set <TransmissionContext>().Include(x => x.Statuses);
public static async Task <PaginatedData <Movie> > SearchMoviesAsync(this MolliesMoviesContext context, PaginatedMovieQuery query, CancellationToken cancellationToken = default) { var dbQuery = context.Movies(); if (!(query.Title is null)) { var pattern = $"%{query.Title}%"; dbQuery = dbQuery.Where(m => EF.Functions.Like(m.Title, pattern)); } if (!(query.Quality is null)) { dbQuery = dbQuery.Where(m => m.MovieSources.Any(s => s.Torrents.Any(t => t.Quality == query.Quality))); } if (!(query.Language is null)) { dbQuery = dbQuery.Where(m => m.Language == query.Language); } if (query.Downloaded.HasValue) { dbQuery = query.Downloaded.Value ? dbQuery.Where(x => x.DownloadedMovies.Any()) : dbQuery.Where(x => !x.DownloadedMovies.Any()); } if (!string.IsNullOrEmpty(query.Genre)) { dbQuery = dbQuery.Where(x => x.MovieGenres.Any(g => g.Genre.Name == query.Genre)); } if (query.YearFrom.HasValue) { dbQuery = dbQuery.Where(m => m.Year >= query.YearFrom.Value); } if (query.YearTo.HasValue) { dbQuery = dbQuery.Where(m => m.Year <= query.YearTo.Value); } if (query.RatingFrom.HasValue) { dbQuery = dbQuery.Where(m => m.Rating >= query.RatingFrom.Value); } if (query.RatingTo.HasValue) { dbQuery = dbQuery.Where(m => m.Rating <= query.RatingTo.Value); } if (!(query.OrderBy is null)) { for (var i = 0; i < query.OrderBy.Count; i++) { var by = query.OrderBy.ElementAt(i); dbQuery = (i == 0, @by.Descending) switch { (true, false) => dbQuery.OrderBy(@by.Property), (true, true) => dbQuery.OrderByDescending(@by.Property), (false, false) => ((IOrderedQueryable <Movie>)dbQuery).ThenBy(@by.Property), (false, true) => ((IOrderedQueryable <Movie>)dbQuery).ThenByDescending(@by.Property) }; } } var count = await dbQuery.CountAsync(cancellationToken); var movies = count > 0 ? await dbQuery .Skip((query.Page - 1) *query.Limit) .Take(query.Limit) .ToListAsync(cancellationToken) : new List <Movie>(); return(new PaginatedData <Movie> { Page = query.Page, Limit = query.Limit, Count = count, Data = movies }); }
public static async Task <Movie> GetMovieByImdbCodeAsync(this MolliesMoviesContext context, string imdbCode, CancellationToken cancellationToken = default) => await context.Set <Movie>().FirstOrDefaultAsync(x => x.ImdbCode == imdbCode, cancellationToken);
public static async Task <Movie> GetMovieDetailByIdAsync(this MolliesMoviesContext context, int id, CancellationToken cancellationToken = default) => await context.Movies().FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
public static IQueryable <Scrape> Scrapes(this MolliesMoviesContext context) => context.Set <Scrape>().Include(x => x.ScrapeSources);