예제 #1
0
        // Метод, який витягує інформацію із html коду і заносить її в клас
        private void GetInformation()
        {
            try {
                StatusForm.LWork.Text = "Отримуємо зображення...";
                StatusForm.PBStatus.Value += 8;
                Regex RegexPicURL = new Regex("<link rel=\"image_src\" href=\"(.*)\" />");
                Match m = RegexPicURL.Match(HTMLCode);
                string PicURL = m.Groups[1].ToString();             // Звертаємося до першого елемента, в 0 лежить все сходження

                StatusForm.LWork.Text = "Отримуємо рік...";
                StatusForm.PBStatus.Value += 8;
                Regex RegexYear = new Regex("<td>\\s*Год:\\s*</td>\\s*<td class=\".*\">\\s*<a href=\".*\"\\s*class=\"tag\"><span>(\\d*)</span></a>\\s*</td>");
                m = RegexYear.Match(HTMLCode);
                string Year = m.Groups[1].ToString();

                StatusForm.LWork.Text = "Отримуємо країну...";
                StatusForm.PBStatus.Value += 8;
                Regex RegexCountry = new Regex("<td>\\s*Страна:\\s*</td>\\s*<td class=\".*\">\\s*<a href=\".*\"\\s*class=\"tag\"><span><span class=\"tag-country-flag\" style=\"background-image: .*;\"></span>&nbsp;(\\w*)</span></a>\\s*</td>");
                m = RegexCountry.Match(HTMLCode);
                string Country = m.Groups[1].ToString();

                StatusForm.LWork.Text = "Отримуємо режисера...";
                StatusForm.PBStatus.Value += 8;
                Regex RegexDirectorFirst = new Regex("<td>\\s*Режиссёр:\\s*</td>\\s*<td class=\".*\">\\s*<span itemprop=\"director\".*</td>");
                m = RegexDirectorFirst.Match(HTMLCode);
                string DirectorTemp = m.Groups[0].ToString();
                Regex RegexDirectorSecond = new Regex("\\s*class=\"tag\"><span itemprop=\"name\">([\\w\\s]*)</span></a></span>");
                MatchCollection n;
                n = RegexDirectorSecond.Matches(DirectorTemp);
                List<Director> Directors = new List<Director>();
                foreach (Match temp in n)
                {
                    Director tmp = new Director();
                    tmp.SetData(temp.Groups[1].ToString());
                    Directors.Add(tmp);
                }
                StatusForm.LWork.Text = "Отримуємо жанри...";
                StatusForm.PBStatus.Value += 8;
                Regex RegexGenreFirst = new Regex("<td>\\s*Жанр:\\s*</td>\\s*<td class=\".*\">\\s*<span itemprop=\"genre\">.*</td>");
                m = RegexGenreFirst.Match(HTMLCode);
                string GenreTemp = m.Groups[0].ToString();
                Regex RegexGenreSecond = new Regex("\\s*class=\"tag\"><span>(\\w*)</span></a></span>");
                n = RegexGenreSecond.Matches(GenreTemp);
                List<string> Genres = new List<string>();
                foreach (Match temp in n)
                {
                    Genres.Add(temp.Groups[1].ToString());
                }
                StatusForm.LWork.Text = "Отримуємо назву фільма...";
                StatusForm.PBStatus.Value += 8;
                Regex RegexFilmName = new Regex("<meta name=\"keywords\" content=\"(.*)\"");
                m = RegexFilmName.Match(HTMLCode);
                string FilmName = m.Groups[1].ToString();

                StatusForm.LWork.Text = "Отримуємо опис...";
                StatusForm.PBStatus.Value += 8;
                Regex RegexDescription = new Regex("<meta property=\"og:description\"\\scontent=\"([^\"]*)\"\\s/>");
                m = RegexDescription.Match(HTMLCode);
                string Description = m.Groups[1].ToString();

                StatusForm.LWork.Text = "Отримуємо інформацію про акторів...";
                StatusForm.PBStatus.Value += 8;
                Regex RegexActorsFirst = new Regex("<td>\\s*В ролях:\\s*</td>\\s*<td class=\".*\">\\s*<span itemprop=\"actor\".*</td>");
                m = RegexActorsFirst.Match(HTMLCode);
                string ActorsTemp = m.Groups[0].ToString();
                Regex RegexActorsSecond = new Regex("\\s*class=\"tag\"><span itemprop=\"name\">([\\w\\s]*)</span></a></span>");
                n = RegexDirectorSecond.Matches(ActorsTemp);
                List<Actor> Actors = new List<Actor>();
                foreach (Match temp in n)
                {
                    Actor tmp = new Actor();
                    tmp.SetData(temp.Groups[1].ToString());
                    Actors.Add(tmp);
                }
                ThisFilm.SetFilm(FilmName, Description, Int32.Parse(Year), Country, PicURL, Genres, Directors, Actors);

            }
            catch
            {
                StatusForm.Hide();
                StatusForm.PBStatus.Value = 0;
                return;
            }
        }