Exemple #1
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();
            }
        }
Exemple #2
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);
            }
        }