示例#1
0
        private void RemoveOldTorrents(OperationInfo op, TorrentsRepository torrentsRepo, OperationsRepository opsRepo)
        {
            op.StatusInfo = "Removing old torrents";

            this.UpdateOperationInfo(op, opsRepo);

            var torrentsRemoved = torrentsRepo.RemoveOldTorrents();

            op.ExtraData["removed"] = torrentsRemoved.ToString(CultureInfo.InvariantCulture);

            this.UpdateOperationInfo(op, opsRepo);
        }
示例#2
0
        public TorrentsServiceTests()
        {
            var options            = new DbContextOptionsBuilder <TorrentsContext>().Options;
            var catalogContextMock = new DbContextMock <TorrentsContext>(options);

            catalogContextMock.CreateDbSetMock(x => x.Forums, InitialEntities.Forums);
            catalogContextMock.CreateDbSetMock(x => x.Torrents, InitialEntities.Torrents);
            catalogContextMock.CreateDbSetMock(x => x.Files, InitialEntities.Files);

            var torrentsRepository = new TorrentsRepository(catalogContextMock.Object);

            _torrentsService = new TorrentsService(torrentsRepository);
        }
示例#3
0
        private void UpdateTorrents(int maxPages, string age, TorrentsRepository torrentsRepo, OperationInfo op, MoviesRepository moviesRepo, OperationsRepository opsRepo)
        {
            var counter  = 0;
            var scraper  = new KassScraper(torrentsRepo, maxPages, age);
            var torrents = scraper.GetLatestTorrents(op, o => this.UpdateOperationInfo(o, opsRepo));

            foreach (var t in torrents)
            {
                torrentsRepo.Save(t);

                if (t.ImdbId != "NA")
                {
                    var movie = moviesRepo.Find(t.ImdbId);
                    if (movie == null)
                    {
                        var newMovie = new Movie {
                            Id = t.ImdbId
                        };
                        if (!string.IsNullOrEmpty(t.Poster))
                        {
                            newMovie.Poster = t.Poster;
                        }

                        moviesRepo.Save(newMovie);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(t.Poster) && !t.Poster.Equals(movie.Poster))
                        {
                            movie.Poster = t.Poster;
                            moviesRepo.Save(movie);
                        }
                    }
                }

                counter++;
                op.ExtraData["updated"] = counter.ToString(CultureInfo.InvariantCulture);
                this.UpdateOperationInfo(op, opsRepo);

                op.CancellationTokenSource.Token.ThrowIfCancellationRequested();
            }
        }
示例#4
0
        private void RemoveUnwantedTorrents(MoviesRepository moviesRepo, TorrentsRepository torrentsRepo, OperationInfo op, OperationsRepository opsRepo)
        {
            op.StatusInfo = "Removing unwanted torrents";
            this.UpdateOperationInfo(op, opsRepo);

            var i = 0;
            var moviesToRemove = moviesRepo.GetUnwantedMovies();

            foreach (var m in moviesToRemove)
            {
                torrentsRepo.RemoveByImdbId(m.Id);
                moviesRepo.Remove(m.Id);

                i++;

                op.ExtraData["unwantedMoviesRemoved"] = i.ToString(CultureInfo.InvariantCulture);
                this.UpdateOperationInfo(op, opsRepo);
                op.CancellationTokenSource.Token.ThrowIfCancellationRequested();
            }
        }
示例#5
0
        public void ProcessTorrentNews(int maxPages, string age, OperationInfo operation)
        {
            Task.Factory.StartNew(
                (op) =>
            {
                var op2 = (OperationInfo)op;
                op2.CancellationTokenSource.Token.ThrowIfCancellationRequested();

                op2.Status    = OperationStatus.Running;
                op2.StartedOn = DateTime.UtcNow;
                op2.ExtraData.Add("removed", "N/A");
                op2.ExtraData.Add("updated", "N/A");
                op2.ExtraData.Add("scraped", "N/A");
                op2.ExtraData.Add("moviesScraped", "N/A");
                op2.ExtraData.Add("unwantedMoviesRemoved", "N/A");
                op2.ExtraData.Add("scoresUpdated", "N/A");

                var torrentsRepo = new TorrentsRepository();
                var moviesRepo   = new MoviesRepository();

                var opsRepo = new OperationsRepository();
                var o       = new Operation {
                    Id = op2.Id, Info = op2, AddedOn = DateTime.UtcNow
                };
                opsRepo.Save(o);

                this.RemoveOldTorrents(op2, torrentsRepo, opsRepo);
                this.UpdateTorrents(maxPages, age, torrentsRepo, op2, moviesRepo, opsRepo);
                this.UpdateMovies(moviesRepo, op2, opsRepo);
                this.RemoveUnwantedTorrents(moviesRepo, torrentsRepo, op2, opsRepo);
                this.UpdateAwards(moviesRepo, torrentsRepo, op2, opsRepo);
            },
                operation,
                operation.CancellationTokenSource.Token)
            .ContinueWith(
                (task, op) => this.UpdateProcessStatus(op, task),
                operation);
        }
 public TorrentsController()
 {
     this.usersRepo    = new UsersRepository();
     this.torrentsRepo = new TorrentsRepository();
     this.moviesRepo   = new MoviesRepository();
 }
示例#7
0
 public KassScraper(TorrentsRepository repo, int maxPages, string age)
 {
     this.repo     = repo;
     this.maxPages = maxPages;
     this.age      = age;
 }
示例#8
0
        private void UpdateAwards(MoviesRepository moviesRepo, TorrentsRepository torrentsRepo, OperationInfo op, OperationsRepository opsRepo)
        {
            op.StatusInfo = "Updating awards";
            this.UpdateOperationInfo(op, opsRepo);

            //Logic for updating Latest
            torrentsRepo.UpdateLatestToFalse();

            var moviesCache = new Dictionary <string, Movie>();
            var torrents    = torrentsRepo.GetAllSortedByImdbIdAndAddedOn();

            var     i = 0;
            string  previousImdbId = null;
            int     previousId     = 0;
            Torrent current        = null;

            foreach (var t in torrents)
            {
                current = t;

                //Logic for updating Latest
                if (previousImdbId != null)
                {
                    if (previousImdbId != current.ImdbId)
                    {
                        var previous = torrentsRepo.Find(previousId);
                        previous.Latest = true;
                        torrentsRepo.Save(previous);
                    }
                }

                previousImdbId = current.ImdbId;
                previousId     = current.Id;
                //

                var isDirty = false;

                Movie movie = null;
                if (current.HasImdbId())
                {
                    if (!moviesCache.TryGetValue(current.ImdbId, out movie))
                    {
                        movie = moviesRepo.Find(current.ImdbId);
                        moviesCache.Add(current.ImdbId, movie);
                    }
                }

                if (movie != null)
                {
                    current.ImdbAward       = this.GetValue(current.ImdbAward, movie.ImdbVotes >= 1000 && movie.ImdbRating >= 70, ref isDirty);
                    current.MetacriticAward = this.GetValue(current.MetacriticAward, movie.McMetascore >= 70, ref isDirty);
                }
                else
                {
                    current.ImdbAward       = this.GetValue(current.ImdbAward, false, ref isDirty);
                    current.MetacriticAward = this.GetValue(current.MetacriticAward, false, ref isDirty);
                }

                current.SuperPopularityAward = this.GetValue(current.SuperPopularityAward, current.Seed >= 3000 || current.CommentsCount >= 100, ref isDirty);
                current.PopularityAward      = this.GetValue(current.PopularityAward, !current.SuperPopularityAward && (current.Seed >= 1000 || current.CommentsCount >= 20), ref isDirty);

                current.Score = this.GetValue(current.Score, this.CalcScore(current), ref isDirty);

                if (isDirty)
                {
                    torrentsRepo.Save(current);
                }

                i++;

                op.ExtraData["scoresUpdated"] = i.ToString(CultureInfo.InvariantCulture);
                this.UpdateOperationInfo(op, opsRepo);
                op.CancellationTokenSource.Token.ThrowIfCancellationRequested();
            }

            //Logic for updating Latest
            if (current != null)
            {
                current.Latest = true;
                torrentsRepo.Save(current);
            }
        }