예제 #1
0
        private void UpdateMovies(MoviesRepository moviesRepo, OperationInfo op, OperationsRepository opsRepo)
        {
            op.StatusInfo = "Scraping movies";
            this.UpdateOperationInfo(op, opsRepo);

            var scraper = new ImdbScraper();

            var moviesScraped  = 0;
            var moviesToUpdate = moviesRepo.GetMoviesToUpdate();

            foreach (var movie in moviesToUpdate)
            {
                scraper.UpdateMovieDetails(movie);
                moviesRepo.Save(movie);

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

                op.CancellationTokenSource.Token.ThrowIfCancellationRequested();
            }
        }
예제 #2
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);
        }
예제 #3
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);
            }
        }
예제 #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
        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();
            }
        }