Exemple #1
0
        /// <summary>
        /// Connects to the seasons's info about a serie and parses the episodes's infos.
        /// </summary>
        /// <param name="url">url of the page.</param>
        /// <param name="eSeas">Parse till this season.</param>
        /// <param name="title">The title object that holds the infos.</param>
        private void parseSeason(String url, int eSeas, IMDbTitle title)
        {
            if (getPage(url))
            {
                StringBuilder strB = new StringBuilder(page);
                Regex         reg;
                string        pat;
                Match         match;
                int           season;
                if (eSeas != -1)
                {
                    season = Int32.Parse(url.Substring(url.Length - 1));
                }
                else //detect last available season
                {
                    season = 1;
                    eSeas  = 0;

                    pat   = "name=\"season-";
                    reg   = new Regex(pat);
                    match = reg.Match(strB.ToString());
                    while (match.Success)
                    {
                        eSeas++;
                        match = match.NextMatch();
                    }
                }
                List <IMDbSerieSeason> seasons = new List <IMDbSerieSeason>();
                while (season <= eSeas)
                {
                    pat = @"Season " + season + "\n</a></h3>(.*?)\n\n</div>\n";
                    reg = new Regex(pat, RegexOptions.Singleline);
                    if (reg.Match(strB.ToString()).Success)
                    {
                        IMDbSerieSeason seas = new IMDbSerieSeason();
                        seas.Number = season;
                        string   epList = reg.Match(strB.ToString()).Groups[1].Value;
                        string[] ep     = epList.Split(Environment.NewLine.ToCharArray());
                        int      epis   = 1;
                        List <IMDbSerieEpisode> episodes = new List <IMDbSerieEpisode>();
                        foreach (string line in ep)
                        {
                            if (line.Length > 10)
                            {
                                IMDbSerieEpisode episode = new IMDbSerieEpisode();
                                pat   = @"<a href="".{17}"">(.*?)</a>.*?<strong>(.*?)</strong>.*?<br>\s*(.*?)<";
                                reg   = new Regex(pat);
                                match = reg.Match(line);

                                episode.Number  = epis;
                                episode.Title   = cleanText(match.Groups[1].Value);
                                episode.AirDate = match.Groups[2].Value;
                                string plot = match.Groups[3].Value;
                                if (plot != null && plot != "")
                                {
                                    episode.Plot = cleanText(match.Groups[3].Value);
                                }
                                episodes.Add(episode);

                                epis++;
                            }
                        }
                        seas.Episodes = episodes;
                        seasons.Add(seas);
                    }
                    season++;
                }
                title.Seasons = seasons;
            }
        }
Exemple #2
0
        /// <summary>
        /// Connects to the seasons's info about a serie and parses the episodes's infos.
        /// </summary>
        /// <param name="url">url of the page.</param>
        /// <param name="eSeas">Parse till this season.</param>
        /// <param name="title">The title object that holds the infos.</param>
        private void parseSeason(String url, int eSeas, IMDbTitle title)
        {
            if (getPage(url))
            {
                StringBuilder strB = new StringBuilder(page);
                Regex reg;
                string pat;
                Match match;
                int season;
                if (eSeas != -1)
                    season = Int32.Parse(url.Substring(url.Length - 1));
                else //detect last available season
                {
                    season = 1;
                    eSeas = 0;

                    pat = "name=\"season-";
                    reg = new Regex(pat);
                    match = reg.Match(strB.ToString());
                    while (match.Success)
                    {
                        eSeas++;
                        match = match.NextMatch();
                    }
                }
                List<IMDbSerieSeason> seasons = new List<IMDbSerieSeason>();
                while (season <= eSeas)
                {
                    pat = @"Season "+season+"\n</a></h3>(.*?)\n\n</div>\n";
                    reg = new Regex(pat, RegexOptions.Singleline);
                    if (reg.Match(strB.ToString()).Success)
                    {
                        IMDbSerieSeason seas = new IMDbSerieSeason();
                        seas.Number = season;
                        string epList = reg.Match(strB.ToString()).Groups[1].Value;
                        string[] ep = epList.Split(Environment.NewLine.ToCharArray());
                        int epis = 1;
                        List<IMDbSerieEpisode> episodes = new List<IMDbSerieEpisode>();
                        foreach (string line in ep)
                        {
                            if (line.Length > 10)
                            {
                                IMDbSerieEpisode episode = new IMDbSerieEpisode();
                                pat = @"<a href="".{17}"">(.*?)</a>.*?<strong>(.*?)</strong>.*?<br>\s*(.*?)<";
                                reg = new Regex(pat);
                                match = reg.Match(line);

                                episode.Number = epis;
                                episode.Title = cleanText(match.Groups[1].Value);
                                episode.AirDate = match.Groups[2].Value;
                                string plot = match.Groups[3].Value;
                                if (plot != null && plot != "")
                                {
                                    episode.Plot = cleanText(match.Groups[3].Value);
                                }
                                episodes.Add(episode);

                                epis++;
                            }
                        }
                        seas.Episodes = episodes;
                        seasons.Add(seas);
                    }
                    season++;
                }
                title.Seasons = seasons;
            }
        }