示例#1
0
        public async Task <IScrapeSession> GetScrapeSessionAsync(string source, ScraperType type, IScrapeSession lastSession = null, CancellationToken cancellationToken = default)
        {
            var scrapeFrom = type == ScraperType.Local
                ? (await _context.GetLatestLocalMovieBySourceAsync(source, cancellationToken))?.DateCreated
                : (await _context.GetLatestMovieBySourceAsync(source, cancellationToken))?.DateCreated;

            var movieImdbCodes = lastSession?.MovieImdbCodes ?? await _context.Set <Movie>().Select(x => x.ImdbCode).ToListAsync(cancellationToken);

            var localImdbCodes = lastSession?.LocalImdbCodes ?? await _context.Set <LocalMovie>().Select(x => x.ImdbCode).ToListAsync(cancellationToken);

            return(new ScrapeSession(source, type, scrapeFrom, movieImdbCodes, localImdbCodes, _context, _clock, cancellationToken, _options.Value));
        }
示例#2
0
 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);
示例#3
0
        public async Task <bool> ScrapeForLocalMovieAsync(int id, CancellationToken cancellationToken = default)
        {
            var movie = await _context.Set <Movie>().FindAsync(id);

            if (movie is null)
            {
                throw EntityNotFoundException.Of <Movie>(id);
            }

            IScrapeSession session = null;

            foreach (var scraper in _scrapers.Where(x => x.Type == ScraperType.Local))
            {
                session = await _movieService.GetScrapeSessionAsync(scraper.Source, scraper.Type, session, cancellationToken);

                await scraper.ScrapeAsync(session, cancellationToken);

                if (session.LocalImdbCodes.Contains(movie.ImdbCode))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#4
0
 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);
示例#5
0
        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 async Task <Paginated <TransmissionContextDto> > GetAllContextsAsync(PaginatedRequest request, CancellationToken cancellationToken = default)
        {
            var query = _context.Set <TransmissionContext>();
            var count = await query.CountAsync(cancellationToken);

            var page  = request.Page ?? 1;
            var limit = request.Limit ?? 20;
            var data  = count > 0
                ? await query
                        .OrderByDescending(x => x.Id)
                        .Skip((page - 1) * limit)
                        .Take(limit)
                        .ProjectTo <TransmissionContextDto>(_mapper.ConfigurationProvider)
                        .ToListAsync(cancellationToken)
                : new List <TransmissionContextDto>();

            return(new Paginated <TransmissionContextDto>
            {
                Page = page,
                Limit = limit,
                Count = count,
                Data = data
            });
        }
示例#7
0
 public static IQueryable <TransmissionContext> TransmissionContexts(this MolliesMoviesContext context) =>
 context.Set <TransmissionContext>().Include(x => x.Statuses);
示例#8
0
 public static async Task <Movie> GetMovieByImdbCodeAsync(this MolliesMoviesContext context, string imdbCode, CancellationToken cancellationToken = default) =>
 await context.Set <Movie>().FirstOrDefaultAsync(x => x.ImdbCode == imdbCode, cancellationToken);
示例#9
0
 public static IQueryable <Scrape> Scrapes(this MolliesMoviesContext context) =>
 context.Set <Scrape>().Include(x => x.ScrapeSources);