Example #1
0
        void bwScrapeAll_DoWork(object sender, DoWorkEventArgs e)
        {
            //Movie _movie = (Movie)listBox_Films.SelectedItem;

            int i = 0; int _progress = 0; int _nbrfilm = MovieManager.Movies.Count;

            foreach (Movie item in MovieManager.Movies)
            {
                if (bwScrapeAll.CancellationPending)
                {
                    goto Cancel;
                }
                i        += 1;
                _progress = (int)((float)i / (float)_nbrfilm * (float)100);
                if (!bwScrapeAll.CancellationPending)
                {
                    bwScrapeAll.ReportProgress((int)_progress, "Recherche " + item.MovieName);
                }

                //Le film a scraper
                Film _ScrapeFilm = new Film();
                _ScrapeFilm = item.updateItem();
                if (String.IsNullOrEmpty(_ScrapeFilm.Titre))
                {
                    _ScrapeFilm.Titre = item.MovieName;
                }
                ObservableCollection <Utils.ChampModifiable> _ListeChampsModif = new ObservableCollection <Utils.ChampModifiable>();
                _ListeChampsModif = Utils.GetChampsModifiables(_ScrapeFilm);

                //Teste si il y a des champs à mettre à jour
                bool _MAJAfaire = false;

                foreach (Utils.ChampModifiable c in ListeChampReplace)
                {
                    if (c.IsModifiable)
                    { //Le champ est paramétré comme modifiable
                        foreach (Utils.ChampModifiable ChampOriginal in _ListeChampsModif)
                        {
                            if (ChampOriginal.NomChamp == c.NomChamp) //On cherche le champ original pour savoir si il est null
                            {
                                if (ChampOriginal.IsModifiable)
                                {
                                    _MAJAfaire = true;
                                }
                            }
                        }
                    }
                }
                if (_MAJAfaire)
                {
                    List <Film> _ListResult = new List <Film>();
                    _ListResult = Scraper.SearchMovie(_ScrapeFilm);

                    if (_ListResult != null & _ListResult.Count > 0)
                    {
                        if (!bwScrapeAll.CancellationPending)
                        {
                            bwScrapeAll.ReportProgress((int)_progress, "Charge les détails de " + _ListResult[0].Titre);
                        }
                        Film _ScrapeFilmResult = new Film(); //Le film resultat du scraper
                        _ScrapeFilmResult = Scraper.GetMovie(_ListResult[0]);
                        if (_ScrapeFilmResult != null)
                        {
                            foreach (Utils.ChampModifiable c in ListeChampReplace)
                            {
                                if (c.IsModifiable)
                                { //Le champ est paramétré comme modifiable
                                    foreach (Utils.ChampModifiable ChampOriginal in _ListeChampsModif)
                                    {
                                        if (ChampOriginal.NomChamp == c.NomChamp) //On cherche le champ original pour savoir si il est null
                                        {
                                            if (ChampOriginal.IsModifiable)       //Il est null on le remplace par le champ du scrapper
                                            {
                                                c.PropertyInfo.SetValue(_ScrapeFilmResult, c.PropertyInfo.GetValue(_ScrapeFilmResult, null), null);
                                            }
                                            else //Il est déjà renseigné on garde tel quel
                                            {
                                                c.PropertyInfo.SetValue(_ScrapeFilmResult, c.PropertyInfo.GetValue(_ScrapeFilm, null), null);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    c.PropertyInfo.SetValue(_ScrapeFilmResult, c.PropertyInfo.GetValue(_ScrapeFilm, null), null);
                                }
                            }

                            foreach (IMMPluginImportExport plug in Master.Settings.PluginsImportExport)
                            {
                                try
                                {
                                    if (!bwScrapeAll.CancellationPending)
                                    {
                                        bwScrapeAll.ReportProgress((int)_progress, "Export " + plug.Name + " " + item.MovieName);
                                    }
                                    _ScrapeFilmResult.Cover.GetImage(true);
                                    _ScrapeFilmResult.Fanart.GetImage(true);

                                    while (_ScrapeFilmResult.Cover.IsLoading)
                                    {
                                        Thread.Sleep(1);
                                    }
                                    while (_ScrapeFilmResult.Fanart.IsLoading)
                                    {
                                        Thread.Sleep(1);
                                    }

                                    plug.Export(_ScrapeFilmResult, item.fileInfo);
                                }
                                catch (Exception exe)
                                {
                                    Console.WriteLine("Erreur Export " + plug.Name + Environment.NewLine + exe.Message);
                                }
                            }
                            _ScrapeFilm = item.updateItem();

                            if (_ScrapeFilm.Cover != null)
                            {
                                _ScrapeFilm.Cover.GetImage(true);
                            }
                            if (_ScrapeFilm.Fanart != null)
                            {
                                _ScrapeFilm.Fanart.GetImage(true);
                            }
                        }
                    }
                }
            }
Cancel:
            {
            }
        }
Example #2
0
 void BackWorkerRecherche_DoWork(object sender, DoWorkEventArgs e)
 {
     _Resultats = Scraper.SearchMovie(FilmRecherche);
 }