Esempio n. 1
0
        /// <summary>
        /// Add a new entry into the database only if it doesn't exist
        /// </summary>
        /// <param name="movie">A movie object containing the information of the movie</param>
        /// <returns>A boolean to inform if anything was added</returns>
        public bool Insert(fmmMovie movie)
        {
            int rowsAffected = DBConnection.Execute(@"
                INSERT OR IGNORE INTO
                    movie
                VALUES (
                    @id,
                    @imdbid,
                    @title,
                    @ogtitle,
                    @filename,
                    @filepath,
                    @adult,
                    @budget,
                    @homepage,
                    @runtime,
                    @tagline,
                    @voteaverage,
                    @oglanguage,
                    @overview,
                    @popularity,
                    @poster,
                    @releasedate,
                    @fk_collection
                );",
                                                    movie
                                                    );

            if (rowsAffected > 0)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Display single movie
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">event</param>
        void displaySingleMovie(object sender, MouseEventArgs e)
        {
            MovieRepository movieRepository = new MovieRepository();

            //change visibility button
            btnBack.Visibility       = Visibility.Visible;
            btnBackSearch.Visibility = Visibility.Hidden;
            btnPlay.Visibility       = Visibility.Visible;
            scrollPositionY          = containerMovies.VerticalOffset;

            //get the clicked element in grid
            var mouseWasDownOn = e.Source as FrameworkElement;

            if (mouseWasDownOn != null)
            {
                //get infos
                string elementName = mouseWasDownOn.Name;
                elementName = elementName.Replace("id_", "");
                fmmMovie        infos  = movieRepository.GetMovie(Convert.ToInt32(elementName));
                List <fmmCast>  casts  = movieRepository.GetMovieCasts(Convert.ToInt32(elementName));
                List <fmmCrew>  crews  = movieRepository.GetMovieCrews(Convert.ToInt32(elementName));
                List <fmmGenre> genres = movieRepository.GetMovieGenres(Convert.ToInt32(elementName));

                btnPlay.Tag = infos.filepath;

                //cover
                if (infos.poster == null || !internetConected)
                {
                    coverSingle.Source = new BitmapImage(new Uri(@"assets/img/notFound.png", UriKind.Relative));
                }
                else
                {
                    coverSingle.Source = new BitmapImage(new Uri("https://image.tmdb.org/t/p/w500" + infos.poster));
                }

                //reset field
                genresSingle.Text   = "";
                authorSingle.Text   = "";
                directorSingle.Text = "";

                //title
                titleSingle.Text = infos.title + " (" + infos.releasedate.Substring(6, 4) + ")";

                //duration
                durationSingle.Text = infos.runtime + " min";

                //gender
                foreach (var genre in genres)
                {
                    if (!(genres.First() == genre))
                    {
                        genresSingle.Text += ", ";
                    }

                    genresSingle.Text += genre.name;
                }

                //rated
                if (infos.adult)
                {
                    ratedSingle.Text = "Adult";
                }
                else
                {
                    ratedSingle.Text = "All public";
                }

                //director
                foreach (var crew in crews)
                {
                    if (crew.job == "Director")
                    {
                        if (directorSingle.Text != "")
                        {
                            directorSingle.Text += ", ";
                        }

                        directorSingle.Text += crew.name;
                    }
                }


                //actors
                foreach (var cast in casts)
                {
                    if (!(casts.First() == cast))
                    {
                        authorSingle.Text += ", ";
                    }

                    authorSingle.Text += cast.name + " (" + cast.character.Replace(" (voice)", "") + ")";
                }

                //description
                descSingle.Text = infos.overview;
            }

            IEnumerable <Image> covers = gridMovies.Children.OfType <Image>();

            foreach (Image child in covers)
            {
                child.Visibility = Visibility.Collapsed;
            }//foreach
            single.Visibility = Visibility.Visible;
        }
Esempio n. 3
0
        /// <summary>
        /// Populate DB with movie returned by API
        /// </summary>
        /// <param name="infos">Movie information</param>
        /// <param name="credit">Cast and crew linked to movie</param>
        /// <param name="originalName">Orignial Name of the movie</param>
        /// <param name="originalFilePath">Original name of the file</param>
        private void PopulateDB(Movie infos, Credits credit, string originalName, string originalFilePath)
        {
            MovieRepository      _movieRepo      = new MovieRepository();
            CollectionRepository _collectionRepo = new CollectionRepository();
            CrewRepository       _crewrepo       = new CrewRepository();
            CastRepository       _castrepo       = new CastRepository();
            CompanyRepository    _companyrepo    = new CompanyRepository();
            CountryRepository    _countryrepo    = new CountryRepository();
            GenreRepository      _genrerepo      = new GenreRepository();
            LanguageRepository   _languagerepo   = new LanguageRepository();


            bool collectionAdded = false;

            if (infos.BelongsToCollection != null)
            {
                fmmCollection collection = new fmmCollection {
                    id     = infos.BelongsToCollection.Id,
                    name   = infos.BelongsToCollection.Name,
                    poster = infos.BelongsToCollection.PosterPath
                };
                _collectionRepo.Insert(collection);

                collectionAdded = true;
            }

            fmmMovie movie = new fmmMovie {
                id          = infos.Id,
                imdbid      = infos.ImdbId,
                title       = infos.Title,
                ogtitle     = originalName,
                filename    = Path.GetFileName(originalFilePath),
                filepath    = originalFilePath,
                adult       = infos.Adult,
                budget      = infos.Budget,
                homepage    = infos.Homepage,
                runtime     = infos.Runtime,
                tagline     = infos.Tagline,
                voteaverage = infos.VoteAverage,
                oglanguage  = infos.OriginalLanguage,
                overview    = infos.Overview,
                popularity  = infos.Popularity,
                poster      = infos.PosterPath,
                releasedate = infos.ReleaseDate.ToString().Substring(0, 10)
            };

            if (collectionAdded)
            {
                movie.fk_collection = infos.BelongsToCollection.Id;
            }

            bool movieAdded = _movieRepo.Insert(movie);

            foreach (Crew crew in credit.Crew)
            {
                var ncrew = new fmmCrew {
                    id         = crew.Id,
                    creditid   = crew.CreditId,
                    name       = crew.Name,
                    image      = crew.ProfilePath,
                    department = crew.Department,
                    job        = crew.Job
                };

                _crewrepo.Insert(ncrew, movie.id);
            }

            foreach (Cast cast in credit.Cast)
            {
                var ncast = new fmmCast {
                    id        = cast.Id,
                    castid    = cast.CastId,
                    creditid  = cast.CreditId,
                    name      = cast.Name,
                    image     = cast.ProfilePath,
                    character = cast.Character,
                    aorder    = cast.Order
                };

                _castrepo.Insert(ncast, movie.id);
            }

            foreach (ProductionCompany company in infos.ProductionCompanies)
            {
                var ncompany = new fmmCompany {
                    id   = company.Id,
                    name = company.Name,
                };

                _companyrepo.Insert(ncompany, movie.id);
            }

            foreach (ProductionCountry country in infos.ProductionCountries)
            {
                var ncountry = new fmmCountry {
                    name = country.Name,
                };

                _countryrepo.Insert(ncountry, movie.id);
            }

            foreach (Genre genre in infos.Genres)
            {
                var ngenre = new fmmGenre {
                    id   = genre.Id,
                    name = genre.Name,
                };

                _genrerepo.Insert(ngenre, movie.id);
            }


            foreach (SpokenLanguage language in infos.SpokenLanguages)
            {
                var nlanguage = new fmmLanguage {
                    name = language.Name,
                };

                _languagerepo.Insert(nlanguage, movie.id);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Test if movie is in db or not and display it from DB or API
        /// </summary>
        private void displayMovies()
        {
            choosedirectory directoryClass  = new choosedirectory();
            MovieRepository movieRepository = new MovieRepository();

            //test internet connected
            if (!CheckConnection())
            {
                internetConected = false;
                MessageBox.Show("No internet connexion, new movie won't be added to the database and images won't be loaded !",
                                "Find My Movie",
                                MessageBoxButton.OK,
                                MessageBoxImage.Warning
                                );
            }

            var  allMovies      = interfaceClass.GetAllFilename();
            bool zeroMovieFound = true;

            List <int> alreadyDisplay = new List <int>(); //to avoid doublon

            foreach (var movie in allMovies)
            {
                bool displayMovie = false;

                //get movie name
                extractfileinfo extract   = new extractfileinfo(Path.GetFileName(movie));
                string          movieName = extract.GetMovieName().Trim();

                //check if in db
                int idMovie = movieRepository.MovieExists("ogtitle", movieName);

                string urlImg = "";

                //if in DB
                if (idMovie != 0)
                {
                    //get data from db
                    fmmMovie infos = movieRepository.GetMovie(idMovie);

                    //get cover
                    if (infos.poster != null && internetConected)
                    {
                        urlImg = "https://image.tmdb.org/t/p/w500" + infos.poster;
                    }

                    displayMovie = true;
                }//if
                else if (internetConected)
                {
                    //Thread.Sleep(200) are here for avoid the maximum request impose per The movie database (40 requets per second)

                    Thread.Sleep(200);

                    // init new api object
                    api api = new api(Path.GetFileName(movie));

                    // check if request to api worked
                    if (api.DidItWork())
                    {
                        //get data from api

                        Thread.Sleep(200);
                        Movie infos = api.GetMovieInfo();

                        if (infos.PosterPath != null)
                        {
                            urlImg = "https://image.tmdb.org/t/p/w500" + infos.PosterPath;
                        }

                        Thread.Sleep(200);
                        Credits credit = api.GetMovieCredits();

                        idMovie = infos.Id;

                        //add in DB
                        PopulateDB(infos, credit, movieName, movie);

                        displayMovie = true;
                    }
                }//else


                //display cover
                if (displayMovie && !alreadyDisplay.Contains(idMovie))
                {
                    this.Dispatcher.BeginInvoke(new Action(() => addMovieGrid(urlImg, idMovie)), System.Windows.Threading.DispatcherPriority.Background, null);
                    alreadyDisplay.Add(idMovie);
                    zeroMovieFound = false;
                }
            }//foreach

            if (zeroMovieFound)
            {
                this.Dispatcher.BeginInvoke(new Action(() => AppendTextBox()), System.Windows.Threading.DispatcherPriority.Background, null);
            }
        }