Exemple #1
0
        private void lst_movies_SelectedIndexChanged(object sender, EventArgs e)
        {
            lbl_moviename.Text = "";
            lbl_rating.Text    = "";
            lst_star.Items.Clear();
            lst_director.Items.Clear();
            lst_writer.Items.Clear();
            lst_casts.Items.Clear();
            panelImage.Controls.Clear();
            pct_poster.Image = null;
            film.Casts.Clear();
            film   = (Movie)lst_movies.SelectedItem;
            person = new Cast();
            film   = DAL.DBControl(film);
            if (film == null)
            {
                WebClient webclient = new WebClient();
                webclient.Encoding = Encoding.UTF8;
                html = webclient.DownloadString("https://www.imdb.com" + film.ImdbId);
                if (html.Contains("<div class=\"combined-see-more see-more\">"))
                {
                    string[] article = html.Split(new string[] { "<div class=\"article\"" }, StringSplitOptions.None);

                    foreach (var item in article)
                    {
                        #region Photos
                        if (item.Contains("<div class=\"mediastrip\">"))
                        {
                            start = item.IndexOf("<div class=\"mediastrip\">");
                            string picdiv = item.Substring(start);
                            start = picdiv.IndexOf("<a");
                            end   = picdiv.IndexOf("</div>");

                            picdiv = picdiv.Substring(start, end - start);
                            string[] picture = picdiv.Split(new string[] { "<a href=", "</a>" }, StringSplitOptions.None);

                            for (int i = 0; i < picture.Length; i++)
                            {
                                if (picture[i].Contains("src"))
                                {
                                    start = picture[i].IndexOf("loadlate=\"") + 10;
                                    end   = picture[i].IndexOf(".jpg");
                                    string photo = picture[i].Substring(start, end - start + 5);
                                    film.Images.Add(photo);
                                }
                            }
                            ImagesList(film.Images);
                            start = item.IndexOf("<div class=\"combined-see-more see-more\">");
                            end   = item.IndexOf("See all") + 7;
                            string   seeAll      = item.Substring(start, end - start);
                            string[] otherPhotos = seeAll.Split(new string[] { "<a href=", "</a>" }, StringSplitOptions.None);
                            for (int i = 0; i < otherPhotos.Length; i++)
                            {
                                if (otherPhotos[i].Contains("See all"))
                                {
                                    start = otherPhotos[i].IndexOf("/title");
                                    end   = otherPhotos[i].IndexOf('>');
                                    person.OtherPhotos = otherPhotos[i].Substring(start, end - start);
                                }
                            }
                        }
                        #endregion

                        #region Casts
                        else if (item.Contains("<table class=\"cast_list\">"))
                        {
                            string[] a = item.Split(new string[] { "<tr>", "</tr>" }, StringSplitOptions.None);
                            a = item.Split(new string[] { "<a href=", "</a>" }, StringSplitOptions.None);
                            for (int i = 0; i < a.Length; i++)
                            {
                                if (a[i].Contains("/name"))
                                {
                                    start = a[i].IndexOf('>') + 1;
                                    end   = a[i].LastIndexOf('\n');
                                    if (end > start)
                                    {
                                        lst_casts.Items.Add(a[i].Substring(start, end - start));
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                }
                else
                {
                    #region TV Series Casts
                    string[] article = html.Split(new string[] { "<div class=\"article\"" }, StringSplitOptions.None);

                    foreach (var item in article)
                    {
                        if (item.Contains("<table class=\"cast_list\">"))
                        {
                            string[] a = item.Split(new string[] { "<tr>", "</tr>" }, StringSplitOptions.None);
                            a = item.Split(new string[] { "<a href=", "</a>" }, StringSplitOptions.None);
                            for (int i = 0; i < a.Length; i++)
                            {
                                if (a[i].Contains("/name"))
                                {
                                    start = a[i].IndexOf('>') + 1;
                                    end   = a[i].LastIndexOf('\n');
                                    if (end > start)
                                    {
                                        lst_casts.Items.Add(a[i].Substring(start, end - start));
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                }
                Poster();
                Ratings();
                Cast();
                pct_poster.Load(film.Poster);
                lbl_moviename.Text = film.Name;
                lbl_rating.Text    = film.Raiting + " Imdb Point";
                DAL.MovieSave(film);
            }
            else
            {
                Cast person;
                lbl_moviename.Text   = film.Name;
                lbl_rating.Text      = film.Raiting + " Imdb Point";
                txt_description.Text = film.Description;
                pct_poster.Load(film.Poster);
                ImagesList(film.Images);
                foreach (var item in film.Casts)
                {
                    person        = new Cast();
                    person.Name   = item.Name;
                    person.ID     = item.ID;
                    person.ImdbId = item.ImdbId;
                    foreach (var role in item.Roles)
                    {
                        if (role.ToString() == "Director")
                        {
                            person.Roles.Add(Role.Director);
                            lst_director.Items.Add(item.Name);
                        }
                        else if (role.ToString() == "Writer")
                        {
                            person.Roles.Add(Role.Writer);
                            lst_writer.Items.Add(item.Name);
                        }
                        else if (role.ToString() == "Actor")
                        {
                            person.Roles.Add(Role.Actor);
                            lst_star.Items.Add(item.Name);
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void MovieDetails_Load(object sender, EventArgs e)
        {
            film.ImdbId = key;
            person      = new Cast();
            movie       = DAL.DBControl(film);
            if (movie == null)
            {
                WebClient webclient = new WebClient();
                webclient.Encoding = Encoding.UTF8;
                html = webclient.DownloadString("https://www.imdb.com" + film.ImdbId);
                if (html.Contains("<div class=\"combined-see-more see-more\">"))
                {
                    string[] article = html.Split(new string[] { "<div class=\"article\"" }, StringSplitOptions.None);
                    string[] subtext = article[0].Split(new string[] { "<div class=\"subtext\"" }, StringSplitOptions.None);
                    start = subtext[0].LastIndexOf("<h1 class=\"\">") + 12;
                    end   = subtext[0].LastIndexOf("&") - 1;
                    string name = subtext[0].Substring(start + 1, end - start);
                    film.Name = name;
                    end       = subtext[1].IndexOf("</div>");
                    string   categorylink = subtext[1].Substring(0, end);
                    string[] category     = categorylink.Split(new string[] { "<a href=", "</a>" }, StringSplitOptions.None);
                    foreach (var item in category)
                    {
                        Category cat;
                        if (item.Contains("\n>"))
                        {
                            cat      = new Category();
                            start    = item.IndexOf(">") + 1;
                            cat.Type = item.Substring(start);
                            DAL.CategorySave(cat.Type);
                            film.Categories.Add(cat);
                        }
                    }
                    foreach (var item in article)
                    {
                        #region Photos
                        if (item.Contains("<div class=\"mediastrip\">"))
                        {
                            start = item.IndexOf("<div class=\"mediastrip\">");
                            string picdiv = item.Substring(start);
                            start = picdiv.IndexOf("<a");
                            end   = picdiv.IndexOf("</div>");

                            picdiv = picdiv.Substring(start, end - start);
                            string[] picture = picdiv.Split(new string[] { "<a href=", "</a>" }, StringSplitOptions.None);

                            for (int i = 0; i < picture.Length; i++)
                            {
                                if (picture[i].Contains("src"))
                                {
                                    start = picture[i].IndexOf("loadlate=\"") + 10;
                                    end   = picture[i].IndexOf(".jpg");
                                    string photo = picture[i].Substring(start, end - start + 5);
                                    film.Images.Add(photo);
                                }
                            }
                            ImagesList(film.Images);
                            start = item.IndexOf("<div class=\"combined-see-more see-more\">");
                            end   = item.IndexOf("See all") + 7;
                            string   seeAll      = item.Substring(start, end - start);
                            string[] otherPhotos = seeAll.Split(new string[] { "<a href=", "</a>" }, StringSplitOptions.None);
                            for (int i = 0; i < otherPhotos.Length; i++)
                            {
                                if (otherPhotos[i].Contains("See all"))
                                {
                                    start = otherPhotos[i].IndexOf("/title");
                                    end   = otherPhotos[i].IndexOf('>');
                                    person.OtherPhotos = otherPhotos[i].Substring(start, end - start);
                                }
                            }
                        }
                        #endregion

                        #region Casts
                        else if (item.Contains("<table class=\"cast_list\">"))
                        {
                            string[] a = item.Split(new string[] { "<tr>", "</tr>" }, StringSplitOptions.None);
                            a = item.Split(new string[] { "<a href=", "</a>" }, StringSplitOptions.None);
                            for (int i = 0; i < a.Length; i++)
                            {
                                if (a[i].Contains("/name"))
                                {
                                    start = a[i].IndexOf('>') + 1;
                                    end   = a[i].LastIndexOf('\n');
                                    if (end > start)
                                    {
                                        lst_casts.Items.Add(a[i].Substring(start, end - start));
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                }
                else
                {
                    #region TV Series Casts
                    string[] article = html.Split(new string[] { "<div class=\"article\"" }, StringSplitOptions.None);

                    foreach (var item in article)
                    {
                        if (item.Contains("<table class=\"cast_list\">"))
                        {
                            string[] a = item.Split(new string[] { "<tr>", "</tr>" }, StringSplitOptions.None);
                            a = item.Split(new string[] { "<a href=", "</a>" }, StringSplitOptions.None);
                            for (int i = 0; i < a.Length; i++)
                            {
                                if (a[i].Contains("/name"))
                                {
                                    start = a[i].IndexOf('>') + 1;
                                    end   = a[i].LastIndexOf('\n');
                                    if (end > start)
                                    {
                                        lst_casts.Items.Add(a[i].Substring(start, end - start));
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                }
                Poster(film);
                Ratings();
                Cast();
                if (film.Poster != null)
                {
                    pct_poster.Load(film.Poster);
                }
                lbl_moviename.Text = film.Name;
                lbl_rating.Text    = film.Raiting + " Imdb Point";
                DAL.MovieSave(film);
            }
            else
            {
                //Cast person;
                lbl_moviename.Text   = movie.Name;
                lbl_rating.Text      = movie.Raiting + " Imdb Point";
                txt_description.Text = movie.Description;
                if (movie.Poster == "")
                {
                    Poster(movie);
                }
                else
                {
                    pct_poster.Load(movie.Poster);
                }
                ImagesList(movie.Images);
                foreach (Cast item in movie.Casts)
                {
                    foreach (Role role in item.Roles)
                    {
                        if (role.RoleName == "Director")
                        {
                            lst_director.Items.Add(item.Name);
                        }
                        else if (role.RoleName == "Writer")
                        {
                            lst_writer.Items.Add(item.Name);
                        }
                        else if (role.RoleName == "Actor")
                        {
                            lst_star.Items.Add(item.Name);
                        }
                    }
                }
            }
        }