Example #1
0
        /// <summary>
        /// Scrapes the Year value
        /// </summary>
        /// <param name="id">The Id for the scraper.</param>
        /// <param name="threadID">The thread MovieUniqueId.</param>
        /// <param name="output">The scraped Year value.</param>
        /// <param name="logCatagory">The log catagory.</param>
        /// <returns>
        /// Scrape succeeded [true/false]
        /// </returns>
        public new bool ScrapeYear(string id, int threadID, out int output, string logCatagory)
        {
            output = 0;

            try
            {
                var xml = this.GetHtml("main", threadID, id);
                output = XRead.GetInt(XRead.OpenXml(xml), "year");

                return(output.IsFilled());
            }
            catch (Exception ex)
            {
                Log.WriteToLog(LogSeverity.Error, threadID, logCatagory, ex.Message);
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// Populates the current episode with episodeXml.
        /// </summary>
        /// <param name="xml">The XML used to populate the values of the episode object.</param>
        /// <returns>
        /// Population sucessful.
        /// </returns>
        public bool Populate(string xml)
        {
            var doc = new XmlDocument();

            doc.LoadXml(xml);

            string title = XRead.GetString(doc, "EpisodeName");

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

            this.ID = XRead.GetUInt(doc, "Id");
            this.CombinedEpisodenumber = XRead.GetDouble(doc, "Combined_episodenumber");
            this.CombinedSeason        = XRead.GetInt(doc, "Combined_season");
            this.DvdChapter            = XRead.GetInt(doc, "DVD_chapter");
            this.DvdDiscid             = XRead.GetInt(doc, "DVD_discid");
            this.DvdEpisodenumber      = XRead.GetDouble(doc, "DVD_episodenumber");
            this.DvdSeason             = XRead.GetInt(doc, "DVD_season");
            this.Director             = XRead.GetString(doc, "Director").ToPersonList('|');
            this.EpisodeImgFlag       = XRead.GetInt(doc, "EpImgFlag");
            this.EpisodeName          = title;
            this.EpisodeNumber        = XRead.GetInt(doc, "EpisodeNumber");
            this.FirstAired           = XRead.GetDateTime(doc, "FirstAired", "yyyy-MM-dd");
            this.GuestStars           = XRead.GetString(doc, "GuestStars").ToPersonList('|', "http://cache.thetvdb.com/banners/");
            this.IMDBID               = XRead.GetString(doc, "IMDB_ID");
            this.Language             = XRead.GetString(doc, "Language");
            this.Overview             = XRead.GetString(doc, "Overview");
            this.ProductionCode       = XRead.GetString(doc, "ProductionCode");
            this.Rating               = XRead.GetDouble(doc, "Rating");
            this.SeasonNumber         = XRead.GetInt(doc, "SeasonNumber");
            this.Writers              = XRead.GetString(doc, "Director").ToPersonList('|');
            this.AbsoluteNumber       = XRead.GetString(doc, "absolute_number");
            this.EpisodeScreenshotUrl = XRead.GetString(doc, "filename");
            this.Lastupdated          = XRead.GetString(doc, "lastupdated");
            this.Seasonid             = XRead.GetUInt(doc, "seasonid");
            this.Seriesid             = XRead.GetUInt(doc, "seriesid");

            return(true);
        }
Example #3
0
        /// <summary>
        /// Loads the movie.
        /// </summary>
        /// <param name="movieModel">
        /// The movie model.
        /// </param>
        public void LoadMovie(MovieModel movieModel)
        {
            XmlDocument xmlReader = XRead.OpenPath(movieModel.NfoPathOnDisk);

            if (xmlReader == null)
            {
                return;
            }

            // Ids
            XmlNodeList ids = xmlReader.GetElementsByTagName("id");

            foreach (XmlElement id in ids)
            {
                if (id.Attributes["moviedb"] == null)
                {
                    movieModel.ImdbId = id.InnerXml.Replace("tt", string.Empty);
                }
                else
                {
                    switch (id.Attributes["moviedb"].Value)
                    {
                    case "tmdb":
                        movieModel.TmdbId = id.InnerXml;
                        break;
                    }
                }
            }

            // Title
            movieModel.Title = XRead.GetString(xmlReader, "title");

            // Year
            movieModel.Year = XRead.GetInt(xmlReader, "year");

            // Release Date
            movieModel.ReleaseDate = XRead.GetDateTime(xmlReader, "releasedate");

            // Rating
            movieModel.Rating = XRead.GetDouble(xmlReader, "rating");

            // Votes
            movieModel.Votes = XRead.GetInt(xmlReader, "votes");

            // Plot
            movieModel.Plot = XRead.GetString(xmlReader, "plot");

            // Outline
            movieModel.Outline = XRead.GetString(xmlReader, "outline");

            // Tagline
            movieModel.Tagline = XRead.GetString(xmlReader, "tagline");

            // Runtime
            string check = XRead.GetString(xmlReader, "runtime");

            if (check.Contains("m"))
            {
                movieModel.RuntimeInHourMin = check;
            }
            else
            {
                movieModel.Runtime = XRead.GetInt(xmlReader, "runtime");
            }

            // Mpaa
            movieModel.Mpaa = XRead.GetString(xmlReader, "mpaa");

            // Certification
            movieModel.Certification = XRead.GetString(xmlReader, "certification");

            // Company
            movieModel.SetStudio = XRead.GetString(xmlReader, "company");
            if (movieModel.SetStudio == string.Empty)
            {
                movieModel.SetStudio = XRead.GetString(xmlReader, "studio");
            }

            // Genre
            string genreList = XRead.GetString(xmlReader, "genre");

            movieModel.GenreAsString = genreList.Replace(" / ", ",");

            // Credits
            movieModel.Writers.Clear();
            XmlNodeList writers = xmlReader.GetElementsByTagName("writer");

            foreach (XmlElement writer in writers)
            {
                movieModel.Writers.Add(new PersonModel(writer.InnerXml));
            }

            // Director
            string directorList = XRead.GetString(xmlReader, "director");

            movieModel.DirectorAsString = directorList.Replace(" / ", ",");

            // Country
            movieModel.CountryAsString = XRead.GetString(xmlReader, "country");

            // Language
            movieModel.LanguageAsString = XRead.GetString(xmlReader, "language");

            // Actors
            XmlNodeList actors = xmlReader.GetElementsByTagName("actor");

            movieModel.Cast.Clear();

            foreach (XmlElement actor in actors)
            {
                XmlDocument document = XRead.OpenXml("<x>" + actor.InnerXml + "</x>");

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

                movieModel.Cast.Add(new PersonModel(name, thumb, role));
            }

            movieModel.VideoSource = XRead.GetString(xmlReader, "videosource");

            // Watched
            movieModel.Watched = XRead.GetBool(xmlReader, "watched");

            // Sets
            XmlNodeList sets = xmlReader.GetElementsByTagName("set");

            foreach (XmlElement set in sets)
            {
                if (set.HasAttribute("order"))
                {
                    int order = int.Parse(set.GetAttribute("order"));

                    MovieSetManager.AddMovieToSet(movieModel, set.InnerXml, order);
                }
                else
                {
                    MovieSetManager.AddMovieToSet(movieModel, set.InnerXml);
                }
            }
        }
Example #4
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];
                    //this.AddHighPriorityToBackgroundQueueWithCache(season.BannerUrl);
                }

                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];
                    //this.AddHighPriorityToBackgroundQueueWithCache(season.PosterUrl);
                }

                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;
                }

                if (!string.IsNullOrEmpty(season.FanartUrl))
                {
                    //this.AddHighPriorityToBackgroundQueueWithCache(season.FanartUrl);
                }

                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);
                }
            }

            this.PreCacheSeriesThumbs();
        }
Example #5
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);
        }