Ejemplo n.º 1
0
        /// <summary>
        /// Scrapes the Cast collection.
        /// </summary>
        /// <param name="id">The MovieUniqueId for the scraper.</param>
        /// <param name="threadID">The thread MovieUniqueId.</param>
        /// <param name="output">The scraped Cast value.</param>
        /// <param name="logCatagory">The log catagory.</param>
        /// <returns>Scrape succeeded [true/false]</returns>
        public new bool ScrapeCast(string id, int threadID, out BindingList<PersonModel> output, string logCatagory)
        {
            output = new BindingList<PersonModel>();
            
            try
            {
                var html = this.GetHtml("cast", threadID, id).RemoveCharacterReturn();

                var castBlock =
                    Regex.Match(html, "<h2>Acteurs(?<body>.*?)Production", RegexOptions.IgnoreCase).Groups[0].Value;

                var m = Regex.Matches(
                    castBlock,
                    "\">(?<actor>.{0,25})</a></h3></div><p>Rôle : (?<role>.*?)</p>",
                    RegexOptions.IgnoreCase);

                foreach (Match match in m)
                {
                    var actor = new PersonModel(match.Groups["actor"].Value, role: match.Groups["role"].Value);

                    output.Add(actor);
                }

                return true;
            }
            catch (Exception ex)
            {
                Log.WriteToLog(LogSeverity.Error, threadID, logCatagory, ex.Message);
                return false;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Populates the the series object with details from a series xml object.
        /// </summary>
        /// <param name="xml">The series xml.</param>
        public void PopulateFullDetails(SeriesXml xml)
        {
            var docList = new XmlDocument();
            docList.LoadXml(xml.En);

            XmlNodeList nodes = docList.GetElementsByTagName("Series");

            var doc = new XmlDocument();
            doc.LoadXml(nodes[0].OuterXml);

            this.ID = XRead.GetUInt(doc, "id");
            this.AirsDayOfWeek = XRead.GetString(doc, "Airs_DayOfWeek");
            this.AirsTime = XRead.GetString(doc, "Airs_Time");
            this.ContentRating = XRead.GetString(doc, "ContentRating");
            this.FirstAired = XRead.GetDateTime(doc, "FirstAired", "yyyy-MM-dd");
            this.Genre = XRead.GetString(doc, "Genre").ToBindingStringList('|');
            this.ImdbId = XRead.GetString(doc, "IMDB_ID");
            this.Language = XRead.GetString(doc, "Language");
            this.Network = XRead.GetString(doc, "Network");
            this.NetworkID = XRead.GetString(doc, "NetworkID");
            this.Overview = XRead.GetString(doc, "Overview");
            this.Rating = XRead.GetDouble(doc, "Rating");
            this.Runtime = XRead.GetInt(doc, "Runtime");
            this.SeriesID = XRead.GetUInt(doc, "id");
            this.SeriesName = XRead.GetString(doc, "SeriesName");
            this.Status = XRead.GetString(doc, "Status");
            this.Added = XRead.GetString(doc, "added");
            this.AddedBy = XRead.GetString(doc, "addedby");
            this.SeriesBannerUrl = XRead.GetString(doc, "banner");
            this.FanartUrl = XRead.GetString(doc, "fanart");
            this.Lastupdated = XRead.GetString(doc, "lastupdated");
            this.Zap2It_Id = XRead.GetString(doc, "zap2it_id");

            this.PosterUrl = XRead.GetString(doc, "poster");

            nodes = docList.GetElementsByTagName("Episode");

            int? count = 0;

            // Count Seasons
            foreach (XmlNode node in nodes)
            {
                var episode = new Episode();
                episode.Populate(node.OuterXml);

                if (episode.SeasonNumber > count)
                {
                    count = episode.SeasonNumber;
                }
            }

            // Extract main Actors
            var actorsDoc = new XDocument(XDocument.Parse(xml.Actors));

            IEnumerable<XElement> linqActors = from a in actorsDoc.Descendants("Actor") select a;

            foreach (XElement a in linqActors)
            {
                string image = a.Element("Image").Value;

                if (!string.IsNullOrEmpty(image))
                {
                    image = TvDBFactory.GetImageUrl(image);
                }

                var m = new PersonModel(a.Element("Name").Value, image, a.Element("Role").Value);
                this.Actors.Add(m);
            }

            this.Banner.Populate(xml.Banners);

            // Create Seasons
            int count2;
            int.TryParse(count.ToString(), out count2);

            for (int i = 0; i < count2 + 1; i++)
            {
                var season = new Season
                    {
                        SeasonNumber = i
                    };

                List<string> seasonBanner = (from p in this.Banner.Season
                                             where
                                                 p.BannerType2 == BannerType2.seasonwide &&
                                                 p.Season == season.SeasonNumber.ToString()
                                             select p.BannerPath).ToList();

                if (seasonBanner.Count > 0)
                {
                    season.BannerUrl = seasonBanner[0];
                }

                List<string> seasonPoster =
                    (from p in this.Banner.Season where p.Season == season.SeasonNumber.ToString() select p.BannerPath).
                        ToList();

                if (this.posterUrl != null && seasonPoster.Count > 0)
                {
                    season.PosterUrl = seasonPoster[0];
                }

                List<BannerDetails> seasonFanart = (from p in this.Banner.Fanart select p).ToList();

                if (seasonFanart.Count > i)
                {
                    season.FanartUrl = seasonFanart[i].BannerPath;
                }
                else if (seasonFanart.Count > 0)
                {
                    season.FanartUrl = seasonFanart[0].BannerPath;
                }

                this.Seasons.Add(i, season);
            }

            foreach (XmlNode node in nodes)
            {
                var episode = new Episode();
                bool result = episode.Populate(node.OuterXml);

                if (result)
                {
                    int episodeNumber;
                    int.TryParse(episode.SeasonNumber.ToString(), out episodeNumber);

                    this.Seasons[episodeNumber].Episodes.Add(episode);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the series.
        /// </summary>
        /// <param name="series">
        /// The series.
        /// </param>
        /// <returns>
        /// Loaded succeeded
        /// </returns>
        public bool LoadSeries(Series series)
        {
            string seriesName = series.SeriesName;
            string seriesPath = series.GetSeriesPath();

            if (!string.IsNullOrEmpty(seriesName) || !string.IsNullOrEmpty(seriesPath))
            {

                var seriesNameHex = "Set_"
                                    +
                                    FileSystemCharChange.To(
                                        seriesName,
                                        FileSystemCharChange.ConvertArea.Tv,
                                        FileSystemCharChange.ConvertType.Hex) + "_1";

                var seriesNameChar = "Set_"
                                     +
                                     FileSystemCharChange.To(
                                         seriesName,
                                         FileSystemCharChange.ConvertArea.Tv,
                                         FileSystemCharChange.ConvertType.Char) + "_1";

                string nfo = Find.FindNFO("Set_" + seriesName + "_1", seriesPath);

                if (string.IsNullOrEmpty(nfo))
                {
                    nfo = Find.FindNFO(seriesNameHex, seriesPath);

                    if (string.IsNullOrEmpty(nfo))
                    {
                        nfo = Find.FindNFO(seriesNameChar, seriesPath);

                        if (!string.IsNullOrEmpty(nfo))
                        {
                            XmlDocument doc = XRead.OpenPath(nfo);

                            series.SeriesName = XRead.GetString(doc, "title");
                            series.SeriesID = XRead.GetUInt(doc, "id");
                            series.Rating = XRead.GetDouble(doc, "rating");
                            series.Overview = XRead.GetString(doc, "plot");
                            series.ContentRating = XRead.GetString(doc, "certification");
                            series.Genre = XRead.GetStrings(doc, "genre").ToBindingList();
                            series.FirstAired = XRead.GetDateTime(doc, "premiered", "yyyy-MM-dd");
                            series.Network = XRead.GetString(doc, "country");

                            if (doc.GetElementsByTagName("actor").Count > 0)
                            {
                                series.Actors = new BindingList<PersonModel>();

                                foreach (XmlNode actor in doc.GetElementsByTagName("actor"))
                                {
                                    string xmlActor = actor.InnerXml;

                                    XmlDocument docActor = XRead.OpenXml("<x>" + xmlActor + "</x>");

                                    string name = XRead.GetString(docActor, "name");
                                    string role = XRead.GetString(docActor, "role");
                                    string imageurl = XRead.GetString(docActor, "thumb");

                                    var personModel = new PersonModel(name, imageurl, role);

                                    series.Actors.Add(personModel);
                                }
                            }
                        }
                    }
                }
            }

            foreach (var season in series.Seasons)
            {
                foreach (var episode in season.Value.Episodes)
                {
                    if (File.Exists(episode.FilePath.PathAndFilename))
                    {
                        var nfoPath = Path.Combine(
                            episode.FilePath.FolderPath, episode.FilePath.FilenameWithOutExt + ".nfo");

                        if (File.Exists(nfoPath))
                        {
                            var doc = XRead.OpenPath(nfoPath);

                            episode.SeasonNumber = XRead.GetInt(doc, "season");
                            episode.EpisodeNumber = XRead.GetInt(doc, "episode");
                            episode.EpisodeName = XRead.GetString(doc, "title");
                            episode.Overview = XRead.GetString(doc, "plot");
                            episode.FirstAired = XRead.GetDateTime(doc, "aired");
                        }
                    }
                }
            }

            return true;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns a person list via a regex match
        /// </summary>
        /// <param name="regex">The regex to apply.</param>
        /// <param name="html">The HTML to apply the regex on.</param>
        /// <param name="name">The name group</param>
        /// <param name="role">The role group</param>
        /// <param name="imageurl">The imageurl group</param>
        /// <returns></returns>
        public static BindingList<PersonModel> MatchesToPersonList(
            string regex, 
            string matchHhtml, 
            string matchName, 
            string role = null, 
            string imageurl = null)
        {

            var personList = new BindingList<PersonModel>();
            var matches = Regex.Matches(matchHhtml, regex);

            foreach (Match m in matches)
            {
                var p = new PersonModel(m.Groups[matchName].Value.Clean());

                if (role != null && !string.IsNullOrEmpty(m.Groups[role].Value))
                {
                    p.Role = m.Groups[role].Value.Clean();
                }

                if (imageurl != null && !string.IsNullOrEmpty(m.Groups[imageurl].Value))
                {
                    p.ImageUrl = m.Groups[imageurl].Value;
                }

                p.Name = Clean.Text.ValidizeResult(p.Name);
                p.Role = Clean.Text.ValidizeResult(p.Role);

                personList.Add(p);
            }

            return personList;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Scrapes the Cast collection.
        /// </summary>
        /// <param name="id">The MovieUniqueId for the scraper.</param>
        /// <param name="threadID">The thread MovieUniqueId.</param>
        /// <param name="output">The scraped Cast value.</param>
        /// <param name="logCatagory">The log catagory.</param>
        /// <returns>Scrape succeeded [true/false]</returns>
        public new bool ScrapeCast(string id, int threadID, out BindingList<PersonModel> output, string logCatagory)
        {
            output = new BindingList<PersonModel>();
            
            try
            {
                var html = Downloader.ProcessDownload(this.GetHtml("cast", threadID, id), DownloadType.Html, Section.Movies).RemoveCharacterReturn();

                var castBlock =
                    Regex.Match(html, "<h2>Acteurs(?<body>.*?)Production", RegexOptions.IgnoreCase).Groups[0].Value;

                var m = Regex.Matches(
                    castBlock,
                    @"/personne/fichepersonne_gen_cpersonne=\d*\.html"">\t\t\t*?<img src='(?<image>.*?)'.*?title='(?<actor>.*?)'.*?Rôle : (?<role>.*?)\t",
                    RegexOptions.IgnoreCase);

                const string EmptyImage = "http://images.allocine.fr/r_60_80/commons/emptymedia/AffichetteAllocine.gif";

                foreach (Match match in m)
                {
                    var actor = new PersonModel(match.Groups["actor"].Value, match.Groups["role"].Value);

                    if (match.Groups["image"].Value != EmptyImage)
                    {
                        actor.ImageUrl = match.Groups["image"].Value;
                    }

                    output.Add(actor);
                }

                return true;
            }
            catch (Exception ex)
            {
                Log.WriteToLog(LogSeverity.Error, threadID, logCatagory, ex.Message);
                return false;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Loads the series.
        /// </summary>
        /// <param name="series">
        /// The series.
        /// </param>
        /// <returns>
        /// Loaded succeeded
        /// </returns>
        public bool LoadSeries(Series series)
        {
            string seriesName = series.GetSeriesNameOnDisk();
            string seriesPath = series.GetSeriesPath();

            if (string.IsNullOrEmpty(seriesName) || string.IsNullOrEmpty(seriesPath))
            {
                return false;
            }

            string nfo = Find.FindNFO(seriesName, seriesPath);

            if (string.IsNullOrEmpty(nfo))
            {
                return false;
            }

            XmlDocument doc = XRead.OpenPath(nfo);

            series.SeriesName = XRead.GetString(doc, "title");
            series.SeriesID = XRead.GetUInt(doc, "id");
            series.Rating = XRead.GetDouble(doc, "rating");
            series.Overview = XRead.GetString(doc, "plot");
            series.ContentRating = XRead.GetString(doc, "certification");
            series.Genre = XRead.GetStrings(doc, "genre").ToBindingList();
            series.FirstAired = XRead.GetDateTime(doc, "premiered", "yyyy-MM-dd");
            series.Network = XRead.GetString(doc, "country");

            if (doc.GetElementsByTagName("actor").Count > 0)
            {
                series.Actors = new BindingList<PersonModel>();

                foreach (XmlNode actor in doc.GetElementsByTagName("actor"))
                {
                    string xmlActor = actor.InnerXml;

                    XmlDocument docActor = XRead.OpenXml("<x>" + xmlActor + "</x>");

                    string name = XRead.GetString(docActor, "name");
                    string role = XRead.GetString(docActor, "role");
                    string imageurl = XRead.GetString(docActor, "thumb");

                    var personModel = new PersonModel(name, role, imageurl);

                    series.Actors.Add(personModel);
                }
            }

            return true;
        }
Ejemplo n.º 7
0
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        private MovieModel CreateTestMovie()
        {
            var movieModel = new MovieModel();

            movieModel.Title = "this is a title";
            movieModel.Year = 2008;
            movieModel.Top250 = 2;
            movieModel.ReleaseDate = new DateTime(2008, 02, 03);
            movieModel.Rating = 6.5;
            movieModel.Votes = 199999;
            movieModel.Plot = "This is a plot";
            movieModel.Tagline = "This is a tagline";
            movieModel.Runtime = 199;
            movieModel.Mpaa = "Rated G";
            movieModel.Certification = "USA:G";
            movieModel.SetStudio = "Fox Studios";
            movieModel.Country = new BindingList<string> { "USA", "UK" };
            movieModel.Genre = new BindingList<string> { "Comedy", "Drama" };
            var person1 = new PersonModel("Russell Lewis", role: "Actors person");
            movieModel.Writers = new BindingList<PersonModel> { person1, person1 };
            movieModel.Director = new BindingList<PersonModel> { person1 };
            movieModel.Cast = new BindingList<PersonModel> { person1, person1 };
            movieModel.CurrentPosterImageUrl = "http://cf1.themoviedb.org/posters/011/4cdb8b335e73d605e6000011/toy-story-3-cover.jpg";
            movieModel.CurrentFanartImageUrl = "http://cf1.themoviedb.org/backdrops/0bf/4bc92cb5017a3c57fe0120bf/toy-story-3-thumb.jpg";

            movieModel.AssociatedFiles.AddToMediaCollection(this.CreateTextMediaPathFileModel());

            return movieModel;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Loads the episode.
        /// </summary>
        /// <param name="episode">The episode.</param>
        /// <returns>
        /// Episode Object
        /// </returns>
        public bool LoadEpisode(Episode episode)
        {
            string episodeName = episode.EpisodeName;
            string episodePath = episode.FilePath.FolderPath;

            string nfo = Find.FindNFO(episodeName, episodePath);

            if (string.IsNullOrEmpty(nfo))
            {
                return false;
            }

            XmlDocument doc = XRead.OpenPath(nfo);

            episode.SeasonNumber = XRead.GetInt(doc, "season");
            episode.EpisodeNumber = XRead.GetInt(doc, "episode");
            episode.EpisodeName = XRead.GetString(doc, "title");
            episode.Rating = XRead.GetDouble(doc, "rating");
            episode.Overview = XRead.GetString(doc, "plot");
            //episode.PlayCount = XRead.GetInt(doc, "playcount");
            //episode.LastPlayed = XRead.GetString(doc, "lastplayed");
            //episode.Credits = XRead.GetString(doc, "credits");
            List<string> directorList = XRead.GetStrings(doc, "director");
            foreach (string director in directorList)
            {
                episode.Director.Add(new PersonModel(director));
            }
            episode.FirstAired = XRead.GetDateTime(doc, "aired");
            //episode.Premiered = XRead.GetString(doc, "premiered");
            //episode.Studio = XRead.GetString(doc, "studio");
            //episode.Mpaa = XRead.GetString(doc, "mpaa");
            //episode.DisplayEpisode = XRead.GetInt(doc, "displayepisode");


            // Actor
            if (doc.GetElementsByTagName("actor").Count > 0)
            {
                episode.GuestStars = new BindingList<PersonModel>();

                foreach (XmlNode actor in doc.GetElementsByTagName("actor"))
                {
                    string xmlActor = actor.InnerXml;

                    XmlDocument docActor = XRead.OpenXml("<x>" + xmlActor + "</x>");

                    string name = XRead.GetString(docActor, "name");
                    string role = XRead.GetString(docActor, "role");
                    string imageurl = XRead.GetString(docActor, "thumb");

                    var personModel = new PersonModel(name, role, imageurl);

                    episode.GuestStars.Add(personModel);
                }
            }

            // Load fileinfo

            return true;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Loads the series.
        /// </summary>
        /// <param name="series">
        /// The series.
        /// </param>
        /// <returns>
        /// Loaded succeeded
        /// </returns>
        public bool LoadSeries(Series series)
        {
            string seriesName = series.GetSeriesNameOnDisk();
            string seriesPath = series.GetSeriesPath();

            if (string.IsNullOrEmpty(seriesName) || string.IsNullOrEmpty(seriesPath))
            {
                return false;
            }

            string nfo = Find.FindNFO(seriesName, seriesPath);

            if (string.IsNullOrEmpty(nfo))
            {
                return false;
            }

            XmlDocument doc = XRead.OpenPath(nfo);

            series.SeriesID = XRead.GetUInt(doc, "id");
            series.SeriesName = XRead.GetString(doc, "title");
            series.Rating = XRead.GetDouble(doc, "rating");
            series.ContentRating = XRead.GetString(doc, "mpaa");
            //series.Votes = XRead.GetInt(doc, "votes");
            series.Overview = XRead.GetString(doc, "plot");
            series.Runtime = XRead.GetInt(doc, "runtime");
            //series.Tagline = XRead.GetString(doc, "tagline");
            // Thumb
            // Fanart
            //series.EpisodeGuide = XRead.GetString(doc, "url"); // url is located in episodeguide tags
            series.Genre = XRead.GetStrings(doc, "genre").ToBindingList();
            //series.Director = XRead.GetString(doc, "director");
            series.FirstAired = XRead.GetDateTime(doc, "premiered", "yyyy-MM-dd");
            series.Status = XRead.GetString(doc, "status");
            //series.Aired = XRead.GetString(doc, "aired");
            series.Network = XRead.GetString(doc, "studio");
            //series.Trailer = XRead.GetString(doc, "trailer");

            if (doc.GetElementsByTagName("actor").Count > 0)
            {
                series.Actors = new BindingList<PersonModel>();

                foreach (XmlNode actor in doc.GetElementsByTagName("actor"))
                {
                    string xmlActor = actor.InnerXml;

                    XmlDocument docActor = XRead.OpenXml("<x>" + xmlActor + "</x>");

                    string name = XRead.GetString(docActor, "name");
                    string role = XRead.GetString(docActor, "role");
                    string imageurl = XRead.GetString(docActor, "thumb");

                    var personModel = new PersonModel(name, role, imageurl);

                    series.Actors.Add(personModel);
                }
            }

            return true;
        }