Пример #1
0
        public async Task <MovieContainer> GetMovieAsync(int movieId, CancellationToken cancellationToken)
        {
            MovieContainer container = Movies.FindById(movieId);

            if (container != null)
            {
                return(container);
            }

            MovieMethods methods    = MovieMethods.Credits | MovieMethods.Images | MovieMethods.Videos | MovieMethods.Translations | MovieMethods.Keywords;
            Movie        tmdbResult = await TMDbClient.GetMovieAsync(movieId, methods, cancellationToken);

            container = new MovieContainer(tmdbResult);

            ImdbHelper.GetImdbInfo(tmdbResult.ImdbId).ContinueWith(x =>
            {
                if (x.IsCompleted && !x.IsFaulted && x.Result != null)
                {
                    container.Votes      = x.Result.Resource.RatingCount;
                    container.TopRating  = x.Result.Resource.TopRank;
                    container.ImdbRating = x.Result.Resource.Rating;
                }
            }, TaskScheduler.FromCurrentSynchronizationContext()).LogIfFaulted();

            return(container);
        }
Пример #2
0
        public async Task <TvShowContainer> GetTvShowAsync(int tvShowId, CancellationToken cancellationToken)
        {
            TvShowContainer container = TvShows.FindById(tvShowId);

            if (container != null)
            {
                return(container);
            }

            TvShowMethods methods    = TvShowMethods.Credits | TvShowMethods.Images | TvShowMethods.Videos | TvShowMethods.Translations | TvShowMethods.Keywords | TvShowMethods.ExternalIds;
            TvShow        tmdbResult = await TMDbClient.GetTvShowAsync(tvShowId, methods, cancellationToken);

            container = new TvShowContainer(tmdbResult);

            ImdbHelper.GetImdbInfo(tmdbResult.ExternalIds.ImdbId).ContinueWith(x =>
            {
                if (x.IsCompleted && !x.IsFaulted && x.Result != null)
                {
                    container.Votes      = x.Result.Resource.RatingCount;
                    container.ImdbRating = x.Result.Resource.Rating;

                    if (x.Result.Resource.OtherRanks?.Length > 0)
                    {
                        container.TopRating = x.Result.Resource.OtherRanks[0].Rank;
                    }
                }
            }, TaskScheduler.FromCurrentSynchronizationContext()).LogIfFaulted();

            return(container);
        }
Пример #3
0
        private void btnGetByImdbId_Click(object sender, EventArgs e)
        {
            //IMDB ID
            if (!string.IsNullOrEmpty(txtImdbId.Text))
            {
                string imdbId = txtImdbId.Text;

                string logPath = @"D:\Development\Projects\MArchive\MArchiveImdbParser\_log";

                Directory.CreateDirectory(logPath);

                TextWriter tw    = new StreamWriter(logPath + logHelper.createLogFileName(string.Format("{0}", imdbId)));
                DateTime   start = DateTime.Now;
                tw.WriteLine("Start : " + start.ToString( ));

                ImdbModel iInfo = new ImdbModel( );
                try {
                    iInfo = ImdbHelper.getMovieInformation(imdbId, tw, start);
                    DateTime     finish      = DateTime.Now;
                    TimeSpan     processTime = finish - start;
                    imdbInfoForm frmImdbInfo = new imdbInfoForm(iInfo, this, "addnew");
                    //frmImdbInfo.MdiParent = this.MdiParent;
                    frmImdbInfo.Text += "  - " + processTime.Seconds.ToString( ) + "." + processTime.Milliseconds.ToString( ) + " saniye";
                    frmImdbInfo.Show( );
                } catch (Exception ex) { MessageBox.Show(ex.Message); }

                tw.WriteLine("End : " + DateTime.Now.ToString( ));
                tw.Close( );
            }
        }
Пример #4
0
        public async Task UpdateMovieAsync(MovieContainer container, CancellationToken cancellationToken)
        {
            MovieMethods methods    = MovieMethods.Credits | MovieMethods.Images | MovieMethods.Videos | MovieMethods.Translations | MovieMethods.Keywords;
            Movie        tmdbResult = await TMDbClient.GetMovieAsync(container.Id, methods, cancellationToken);

            container.Item = tmdbResult;

            ImdbInfo imdbInfo = await ImdbHelper.GetImdbInfo(tmdbResult.ImdbId);

            container.Votes      = imdbInfo.Resource.RatingCount;
            container.TopRating  = imdbInfo.Resource.TopRank;
            container.ImdbRating = imdbInfo.Resource.Rating;

            Movies.Update(container);
        }
Пример #5
0
        public async Task UpdateTvShowAsync(TvShowContainer container, CancellationToken cancellationToken)
        {
            TvShowMethods methods    = TvShowMethods.Credits | TvShowMethods.Images | TvShowMethods.Videos | TvShowMethods.Translations | TvShowMethods.Keywords | TvShowMethods.ExternalIds;
            TvShow        tmdbResult = await TMDbClient.GetTvShowAsync(container.Id, methods, cancellationToken);

            container.Item = tmdbResult;

            ImdbInfo imdbInfo = await ImdbHelper.GetImdbInfo(tmdbResult.ExternalIds.ImdbId);

            container.Votes      = imdbInfo.Resource.RatingCount;
            container.ImdbRating = imdbInfo.Resource.Rating;

            if (imdbInfo.Resource.OtherRanks?.Length > 0)
            {
                container.TopRating = imdbInfo.Resource.OtherRanks[0].Rank;
            }

            TvShows.Update(container);
        }
Пример #6
0
        public ActionResult Search(string key)
        {
            Movie movie;

            key = key.Trim();
            if (key.IsIMDB() || key.IsIMDBUrl())
            {
                if (key.IsIMDBUrl())
                {
                    key = ImdbHelper.GetImdbId(key);
                }

                //search for local record
                movie = _movieRepository.GetByImdbId(key);
                if (movie == null)
                {
                    var scrapper = new ImdbScrapper(_movieXPathRepository);
                    //movie = scrapper.LoadMovieFromFile("C:/GOT.txt");
                    movie = scrapper.GetMovie(key);
                }
            }
            else
            {
                movie = _movieRepository.GetByMovieName(key);
                if (movie == null)
                {
                    movie = _movieRepository.GetMovieByAKA(key);
                }
                if (movie == null)
                {
                    movie = new Movie();
                    TempData["NoSearchResult"] = true;
                }
            }

            ViewBag.Search = key;
            var viewModel = movie.MapItem <MovieViewModel>();

            return(View("Index", viewModel));
        }
Пример #7
0
        private void getMovieInfoByIdAndSave(string imdbId, MovieDO movie, TextWriter tw, DateTime start)
        {
            ImdbModel imdbInfo = new ImdbModel( );

            try {
                imdbInfo = ImdbHelper.getMovieInformation(imdbId, tw, start);

                logHelper.logLine(tw, "Imdb information parsed successfully. Starting operation 'Basic Info'");

                #region Basic Info (not updated in db yet)
                if (string.IsNullOrEmpty(movie.ImdbID))
                {
                    movie.ImdbID = imdbId;
                }
                if (string.IsNullOrEmpty(movie.ImdbPoster) && !string.IsNullOrEmpty(imdbInfo.picturePath))
                {
                    string savePath = getSavePath( );
                    string fileName = FileSystemHelper.prepareFileNameForPicture(imdbInfo.picturePath.Substring(imdbInfo.picturePath.LastIndexOf('/')), new MovieNameModel {
                        OriginalName = movie.OriginalName
                    }, savePath);
                    WebRequestHelper.Download(imdbInfo.picturePath, savePath + fileName);
                    movie.ImdbPoster = fileName;
                }

                movie.ImdbRating = imdbInfo.imdbRating;
                if (movie.Year == null || movie.Year == 0)
                {
                    movie.Year = imdbInfo.year;
                }
                #endregion Basic Info

                logHelper.logLine(tw, "Basic Info inserted");

                logHelper.logLine(tw, "Starting operation 'Genres'");

                #region types
                if (MovieTypeBL.GetAllByMovieID(movie.ID).Count() < 1)
                {
                    try {
                        if (imdbInfo.genres != null)
                        {
                            foreach (string item in imdbInfo.genres)
                            {
                                if (allTypes.ContainsKey(item))
                                {
                                    MovieTypeBL.Save(new MovieTypeDO( )
                                    {
                                        MovieID = movie.ID, TypeID = allTypes[item]
                                    }, 1);
                                }
                                else
                                {
                                    int currentID = TypeBL.Save(new MArchive.Domain.Lookup.TypeDO( )
                                    {
                                        Name = item
                                    }, 1).ID;
                                    //MovieTypeBL.Save( movie.ID, item, 1 );
                                    MovieTypeBL.Save(new MovieTypeDO( )
                                    {
                                        MovieID = movie.ID, TypeID = currentID
                                    }, 1);
                                    allTypes.Add(item, currentID);
                                }
                            }
                        }
                        logHelper.logLine(tw, "Genres inserted");
                    } catch (Exception ex) {
                        logHelper.logLine(tw, "Genres could not be inserted.");
                        logHelper.logException(tw, ex);
                        logHelper.logLine(tw);
                    }
                }
                #endregion types

                logHelper.logLine(tw, "Starting operation 'Actors'");

                #region actors
                if (MovieActorBL.GetAllByMovieID(movie.ID).Count( ) < 1)
                {
                    try {
                        if (imdbInfo.cast != null)
                        {
                            foreach (string item in imdbInfo.cast)
                            {
                                if (allActors.ContainsKey(item))
                                {
                                    MovieActorBL.Save(new MovieActorDO( )
                                    {
                                        MovieID = movie.ID, ActorID = allActors[item]
                                    }, 1);
                                }
                                else
                                {
                                    int currentID = ActorBL.Save(new MArchive.Domain.Lookup.ActorDO( )
                                    {
                                        Name = item
                                    }, 1).ID;
                                    MovieActorBL.Save(new MovieActorDO( )
                                    {
                                        MovieID = movie.ID, ActorID = currentID
                                    }, 1);
                                    allActors.Add(item, currentID);
                                }
                            }
                        }
                        logHelper.logLine(tw, "Actors inserted");
                    } catch (Exception ex) {
                        logHelper.logLine(tw, "Actors could not be inserted.");
                        logHelper.logException(tw, ex);
                        logHelper.logLine(tw);
                    }
                }
                #endregion actors

                logHelper.logLine(tw, "Starting operation 'Languages'");

                #region languages
                if (MovieLanguageBL.GetAllByMovieID(movie.ID).Count( ) < 1)
                {
                    try {
                        if (imdbInfo.languages != null)
                        {
                            foreach (string item in imdbInfo.languages)
                            {
                                if (allLanguages.ContainsKey(item))
                                {
                                    MovieLanguageBL.Save(new MovieLanguageDO( )
                                    {
                                        MovieID = movie.ID, LanguageID = allLanguages[item]
                                    }, 1);
                                }
                                else
                                {
                                    int currentID = LanguageBL.Save(new MArchive.Domain.Lookup.LanguageDO( )
                                    {
                                        Name = item
                                    }, 1).ID;
                                    MovieLanguageBL.Save(new MovieLanguageDO( )
                                    {
                                        MovieID = movie.ID, LanguageID = currentID
                                    }, 1);
                                    allLanguages.Add(item, currentID);
                                }
                            }
                        }
                        logHelper.logLine(tw, "Languages inserted");
                    } catch (Exception ex) {
                        logHelper.logLine(tw, "Languages could not be inserted.");
                        logHelper.logException(tw, ex);
                        logHelper.logLine(tw);
                    }
                }
                #endregion languages

                logHelper.logLine(tw, "Starting operation 'Directors'");

                #region directors
                if (MovieDirectorBL.GetAllByMovieID(movie.ID).Count( ) < 1)
                {
                    try {
                        if (imdbInfo.directors != null)
                        {
                            foreach (string item in imdbInfo.directors)
                            {
                                if (allDirectors.ContainsKey(item))
                                {
                                    MovieDirectorBL.Save(new MovieDirectorDO( )
                                    {
                                        MovieID = movie.ID, DirectorID = allDirectors[item]
                                    }, 1);
                                }
                                else
                                {
                                    int currentID = DirectorBL.Save(new MArchive.Domain.Lookup.DirectorDO( )
                                    {
                                        Name = item
                                    }, 1).ID;
                                    MovieDirectorBL.Save(new MovieDirectorDO( )
                                    {
                                        MovieID = movie.ID, DirectorID = currentID
                                    }, 1);
                                    allDirectors.Add(item, currentID);
                                }
                            }
                        }
                        logHelper.logLine(tw, "Directors inserted");
                    } catch (Exception ex) {
                        logHelper.logLine(tw, "Directors could not be inserted.");
                        logHelper.logException(tw, ex);
                        logHelper.logLine(tw);
                    }
                }
                #endregion directors

                logHelper.logLine(tw, "Starting operation 'Writers'");

                #region writers
                if (MovieWriterBL.GetAllByMovieID(movie.ID).Count( ) < 1)
                {
                    try {
                        if (imdbInfo.writers != null)
                        {
                            foreach (string item in imdbInfo.writers)
                            {
                                if (allWriters.ContainsKey(item))
                                {
                                    MovieWriterBL.Save(new MovieWriterDO( )
                                    {
                                        MovieID = movie.ID, WriterID = allWriters[item]
                                    }, 1);
                                }
                                else
                                {
                                    int currentID = WriterBL.Save(new MArchive.Domain.Lookup.WriterDO( )
                                    {
                                        Name = item
                                    }, 1).ID;
                                    MovieWriterBL.Save(new MovieWriterDO( )
                                    {
                                        MovieID = movie.ID, WriterID = currentID
                                    }, 1);
                                    allWriters.Add(item, currentID);
                                }
                            }
                        }
                        logHelper.logLine(tw, "Writers inserted");
                    } catch (Exception ex) {
                        logHelper.logLine(tw, "Writers could not be inserted.");
                        logHelper.logException(tw, ex);
                        logHelper.logLine(tw);
                    }
                }
                #endregion writers

                logHelper.logLine(tw, "Updating 'movie' table");

                movie.ImdbParsed        = true;
                movie.ImdbLastParseDate = movie.UpdateDate = DateTime.Now;

                MovieBL.Save(movie, 1);

                logHelper.logLine(tw, "Table update successful");
            } catch (Exception ex) { logHelper.logException(tw, ex); }
        }
Пример #8
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            //MOVIE NAME
            if (!string.IsNullOrEmpty(txtSearch.Text))
            {
                string search   = ImdbHelper.getSearchFriendlyString(txtSearch.Text);
                string imdbId   = "";
                string tempHtml = "";
                //StreamReader sr = new StreamReader ( @"E:\Projects\MArchive\MArchiveImdbParser\imdb_se.txt" );
                //tempHtml = sr.ReadToEnd ( );
                try {
                    tempHtml = WebRequestHelper.CallPage("http://www.imdb.com/find?tt=all&q=" + search.Replace(" ", "+"));
                } catch (Exception ex) { MessageBox.Show(ex.Message); }

                Regex           rgx;
                MatchCollection matches;

                if (tempHtml != "")
                {
                    string temp = "";

                    //check if this is the search page
                    //or if we've been redirected to the movie's page
                    string _searchPagePattern = "<link.*href.*imdb.com/find";

                    rgx     = new System.Text.RegularExpressions.Regex(_searchPagePattern);
                    matches = rgx.Matches(tempHtml);

                    if (matches.Count > 0)
                    {
                        //arama sayfasına gelmişiz

                        _searchPagePattern = string.Format("<div class={0}{1}findSection{0}{1}>.*<table class={0}{1}findList{0}{1}.*>(.*)</table>.*More title matches",
                                                           "\\", "\"");
                        rgx     = new Regex(_searchPagePattern, RegexOptions.Singleline);
                        matches = rgx.Matches(tempHtml);

                        if (matches.Count > 0)
                        {
                            string tableContent = matches[0].Groups[1].Value;

                            _searchPagePattern = string.Format("<a href=\"/title/(tt[0-9]{7,9})/");
                            //TODO: Burada kaldım
                        }

                        if (tempHtml.Contains("<b>Popular Titles</b>"))
                        {
                            //popüler sonuçlarda bulduk, onu alalım
                            temp   = tempHtml.Substring(tempHtml.IndexOf("<b>Popular Titles</b>"));
                            temp   = temp.Substring(temp.IndexOf("<a href=\"/title/tt") + 16);
                            imdbId = temp.Remove(temp.IndexOf("/"));
                        }
                        else
                        {
                            //popülerde yoksa, şimdilik salla, sonra bakalım ama - - -!!!
                            throw new Exception("I could not find the movie that you searched for.. Sorry.");
                        }
                    }
                    else
                    {
                        //sayfayı bulmuşuz
                        if (tempHtml.Contains("<link href=\"http://www.imdb.com/title/"))
                        {
                            temp = tempHtml.Substring(tempHtml.IndexOf("<link href=\"http://www.imdb.com/title/") + 38);
                        }
                        else if (tempHtml.Contains("<link rel=\"canonical\" href=\"http://www.imdb.com/title/"))
                        {
                            temp = tempHtml.Substring(tempHtml.IndexOf("<link rel=\"canonical\" href=\"http://www.imdb.com/title/") + 54);
                        }
                        imdbId = temp.Remove(temp.IndexOf("/"));
                    }
                }
                else
                {
                    throw new Exception("Error while connecting to IMDB");
                }

                MessageBox.Show(imdbId);
            }
        }