/// <summary>
        /// Parse episode xml element and returns null if xml is not valid
        /// </summary>
        /// <param name="episodeXml">Episode xml element</param>
        /// <returns>Return parsed episode or null if xml is not valid</returns>
        public TheTvDbEpisode Parse(XElement episodeXml)
        {
            if (episodeXml == null) throw new ArgumentNullException(nameof(episodeXml));

            // If episode has no id or number skip parsing and return null
            var id = episodeXml.ElementAsUInt("id");
            if (!id.HasValue) throw new TheTvDbParseException("Error while parsing an episode xml element. Id is missing.");

            var number = episodeXml.ElementAsInt("EpisodeNumber");
            if (!number.HasValue) throw new TheTvDbParseException("Error while parsing an episode xml element. EpisodeNumber is missing.");

            return new TheTvDbEpisode(id.Value)
            {
                SeasonId = episodeXml.ElementAsUInt("seasonid"),
                SeasonNumber = episodeXml.ElementAsUInt("SeasonNumber"),
                EpisodeNumber = number.Value,
                EpisodeName = episodeXml.ElementAsString("EpisodeName"),
                SeriesId = episodeXml.ElementAsUInt("seriesId"),
                FirstAired = episodeXml.ElementAsDateTime("FirstAired"),
                Directors = episodeXml.ElementAsString("Director").SplitByPipe(),
                GuestStars = episodeXml.ElementAsString("GuestStars").SplitByPipe(),
                Description = episodeXml.ElementAsString("Overview", true),
                Rating = episodeXml.ElementAsDouble("Rating"),
                Writers = episodeXml.ElementAsString("Writer").SplitByPipe(),
                RatingCount = episodeXml.ElementAsInt("RatingCount"),
                ThumbWidth = episodeXml.ElementAsInt("thumb_width"),
                ThumbHeight = episodeXml.ElementAsInt("thumb_height"),
                ThumbRemotePath = episodeXml.ElementAsString("filename"),
                Language = episodeXml.ElementAsString("Language").ToTheTvDbLanguage(),
                LastUpdated = episodeXml.ElementFromEpochToDateTime("lastupdated")
            };
        }
        internal override void Parse(XElement element)
        {
            // Search results have different pagination fields for some reason...
            if (element.Name == "search")
            {
                Start = element.ElementAsInt("results-start");
                End = element.ElementAsInt("results-end");
                TotalItems = element.ElementAsInt("total-results");
                return;
            }

            var startAttribute = element.Attribute("start");
            var endAttribute = element.Attribute("end");
            var totalAttribute = element.Attribute("total");

            if (startAttribute != null &&
                endAttribute != null &&
                totalAttribute != null)
            {
                int start = 0, end = 0, total = 0;
                int.TryParse(startAttribute.Value, out start);
                int.TryParse(endAttribute.Value, out end);
                int.TryParse(totalAttribute.Value, out total);

                Start = start;
                End = end;
                TotalItems = total;
            }
        }
Example #3
0
 internal override void Parse(XElement element)
 {
     Id = element.ElementAsInt("id");
     Status = element.ElementAsString("status");
     UpdatedAt = element.ElementAsDateTime("updated_at");
     RatingsCount = element.ElementAsInt("ratings_count");
     CommentsCount = element.ElementAsInt("comments_count");
 }
Example #4
0
        internal override void Parse(XElement element)
        {
            Id = element.ElementAsInt("id");
            Title = element.ElementAsString("title");

            var authorElement = element.Element("author");
            if (authorElement != null)
            {
                AuthorId = authorElement.ElementAsInt("id");
                AuthorName = authorElement.ElementAsString("name");
            }

            ImageUrl = element.ElementAsString("image_url");
        }
Example #5
0
        internal override void Parse(XElement element)
        {
            Id = element.ElementAsInt("id");
            Body = element.ElementAsString("body");

            var userElement = element.Element("user");
            if (userElement != null)
            {
                User = new UserSummary();
                User.Parse(userElement);
            }

            CreatedAt = element.ElementAsDateTime("created_at");
            UpdatedAt = element.ElementAsDateTime("updated_at");
        }
        /// <summary>
        /// Parse an actor xml element and returns null if xml not valid
        /// </summary>
        /// <param name="actorXml">Actor xml element</param>
        /// <returns>Returns parsed actor or null if xml is not valid</returns>
        public TheTvDbActor Parse(XElement actorXml)
        {
            if (actorXml == null) throw new ArgumentNullException(nameof(actorXml));

            // If actor has no id throw ParseException
            var id = actorXml.ElementAsUInt("id");
            if (!id.HasValue) throw new TheTvDbParseException("Error while parsing an actor xml element. EpisodeId is missing.");

            return new TheTvDbActor(id.Value)
            {
                ImageRemotePath = actorXml.ElementAsString("Image"),
                Name = actorXml.ElementAsString("Name"),
                Role = actorXml.ElementAsString("Role"),
                SortOrder = actorXml.ElementAsInt("SortOrder").GetValueOrDefault()
            };
        }
        /// <summary>
        /// Parse banner xml element and returns null if xml is not valid
        /// </summary>
        /// <param name="bannerXml">Banner xml element</param>
        /// <returns>Return the created banner or null if xml is not valid</returns>
        public TheTvDbBanner Parse(XElement bannerXml)
        {
            if (bannerXml == null) throw new ArgumentNullException(nameof(bannerXml));

            TheTvDbBanner banner;

            // If banner has no id return null
            var id = bannerXml.ElementAsUInt("id");
            if (!id.HasValue) throw new TheTvDbParseException("Error while parsing a banner xml element. Banner id is missing.");

            var bannerType = bannerXml.ElementAsString("BannerType");
            switch (bannerType)
            {
                case "fanart":
                    banner = CreateFanart(bannerXml, id.Value);
                    break;
                case "poster":
                    banner = CreatePoster(bannerXml, id.Value);
                    break;
                case "season":
                    banner = CreateSeason(bannerXml, id.Value);
                    break;
                case "series":
                    banner = CreateSeries(bannerXml, id.Value);
                    break;
                default:
                    throw new TheTvDbParseException(
                        $"Error while parsing a banner xml element. BannerType '{bannerType}' is unknown.");
            }

            banner.Language = bannerXml.ElementAsString("Language").ToTheTvDbLanguage();
            banner.Rating = bannerXml.ElementAsDouble("Rating");
            banner.RatingCount = bannerXml.ElementAsInt("RatingCount");
            banner.RemotePath = bannerXml.ElementAsString("BannerPath");

            return banner;
        }
Example #8
0
        internal override void Parse(XElement element)
        {
            Id = element.ElementAsInt("id");
            Name = element.ElementAsString("name");
            BookCount = element.ElementAsInt("book_count");
            Description = element.ElementAsString("description");
            Sort = element.ElementAsString("sort");
            IsExclusive = element.ElementAsBool("exclusive_flag");
            IsFeatured = element.ElementAsBool("featured");
            IsRecommendedFor = element.ElementAsBool("recommended_for");

            var orderElement = element.Element("order");
            if (orderElement != null)
            {
                var orderValue = orderElement.Value;
                if (!string.IsNullOrWhiteSpace(orderValue))
                {
                    if (orderValue == "a")
                    {
                        Order = Response.Order.Ascending;
                    }
                    else if (orderValue == "d")
                    {
                        Order = Response.Order.Descending;
                    }
                }
            }
        }
Example #9
0
        internal override void Parse(XElement element)
        {
            Id = element.ElementAsInt("id");

            var bookElement = element.Element("book");
            if (bookElement != null)
            {
                Book = new BookSummary();
                Book.Parse(bookElement);
            }

            Rating = element.ElementAsInt("rating");
            Votes = element.ElementAsInt("votes");
            IsSpoiler = element.ElementAsBool("spoiler_flag");
            SpoilersState = element.ElementAsString("spoilers_state");
            Shelves = element.ParseChildren<ReviewShelf>("shelves", "shelf");
            RecommendedFor = element.ElementAsString("recommended_for");
            RecommendedBy = element.ElementAsString("recommended_by");
            DateStarted = element.ElementAsDateTime("started_at");
            DateRead = element.ElementAsDateTime("read_at");
            DateAdded = element.ElementAsDateTime("date_added");
            DateUpdated = element.ElementAsDateTime("date_updated");
            ReadCount = element.ElementAsInt("read_count");
            Body = element.ElementAsString("body");
            CommentsCount = element.ElementAsInt("comments_count");
            Url = element.ElementAsString("url");
            Owned = element.ElementAsInt("owned");
        }
        private static TheTvDbBanner CreateSeason(XElement bannerXml, uint id)
        {
            if (bannerXml == null) throw new ArgumentNullException(nameof(bannerXml));

            return new TheTvDbSeasonBanner(id)
            {
                Season = bannerXml.ElementAsInt("Season"),
                IsWide = bannerXml.ElementAsString("BannerType2") == "seasonwide"
            };
        }
Example #11
0
 internal override void Parse(XElement element)
 {
     Id = element.ElementAsInt("id");
     Name = element.ElementAsString("name");
     Role = element.ElementAsString("role");
     ImageUrl = element.ElementAsString("image_url");
     SmallImageUrl = element.ElementAsString("small_image_url");
     Link = element.ElementAsString("link");
     AverageRating = element.ElementAsNullableDecimal("average_rating");
     RatingsCount = element.ElementAsNullableInt("ratings_count");
     TextReviewsCount = element.ElementAsNullableInt("text_reviews_count");
 }
Example #12
0
        internal override void Parse(XElement element)
        {
            Id = element.ElementAsInt("id");
            Title = element.ElementAsString("title");
            Isbn = element.ElementAsString("isbn");
            Isbn13 = element.ElementAsString("isbn13");
            Asin = element.ElementAsString("asin");
            KindleAsin = element.ElementAsString("kindle_asin");
            MarketplaceId = element.ElementAsString("marketplace_id");
            CountryCode = element.ElementAsString("country_code");
            ImageUrl = element.ElementAsString("image_url");
            SmallImageUrl = element.ElementAsString("small_image_url");
            PublicationDate = element.ElementAsMultiDateField("publication");
            Publisher = element.ElementAsString("publisher");
            LanguageCode = element.ElementAsString("language_code");
            IsEbook = element.ElementAsBool("is_ebook");
            Description = element.ElementAsString("description");
            AverageRating = element.ElementAsDecimal("average_rating");
            Pages = element.ElementAsInt("num_pages");
            Format = element.ElementAsString("format");
            EditionInformation = element.ElementAsString("edition_information");
            RatingsCount = element.ElementAsInt("ratings_count");
            TextReviewsCount = element.ElementAsInt("text_reviews_count");
            Url = element.ElementAsString("url");
            ReviewsWidget = element.ElementAsString("reviews_widget");

            var workElement = element.Element("work");
            if (workElement != null)
            {
                Work = new Work();
                Work.Parse(element.Element("work"));
            }

            Authors = element.ParseChildren<AuthorSummary>("authors", "author");
            SimilarBooks = element.ParseChildren<BookSummary>("similar_books", "book");

            var bookLinks = element.ParseChildren<BookLink>("book_links", "book_link");
            if (bookLinks != null)
            {
                bookLinks.ForEach(x => x.FixBookLink(Id));
                BookLinks = bookLinks;
            }

            var buyLinks = element.ParseChildren<BookLink>("buy_links", "buy_link");
            if (buyLinks != null)
            {
                buyLinks.ForEach(x => x.FixBookLink(Id));
                BuyLinks = buyLinks;
            }

            var shelves = element.ParseChildren(
                "popular_shelves",
                "shelf",
                (shelfElement) =>
            {
                var shelfName = shelfElement.Attribute("name").Value;
                var shelfCountValue = shelfElement.Attribute("count").Value;

                int shelfCount = 0;
                int.TryParse(shelfCountValue, out shelfCount);
                return new KeyValuePair<string, int>(shelfName, shelfCount);
            });

            if (shelves != null)
            {
                PopularShelves = shelves.ToDictionary(x => x.Key, x => x.Value);
            }
        }
Example #13
0
        internal override void Parse(XElement element)
        {
            Id = element.ElementAsInt("id");

            var bestBookElement = element.Element("best_book");
            if (bestBookElement != null)
            {
                BestBook = new BestBook();
                BestBook.Parse(bestBookElement);
            }

            BestBookId = element.ElementAsNullableInt("best_book_id");
            BooksCount = element.ElementAsInt("books_count");
            ReviewsCount = element.ElementAsInt("reviews_count");
            RatingsSum = element.ElementAsInt("ratings_sum");
            RatingsCount = element.ElementAsInt("ratings_count");
            TextReviewsCount = element.ElementAsInt("text_reviews_count");

            // Merge the Goodreads publication fields into one date property
            var originalPublicationYear = element.ElementAsInt("original_publication_year");
            var originalPublicationMonth = element.ElementAsInt("original_publication_month");
            var originalPublicationDay = element.ElementAsInt("original_publication_day");
            if (originalPublicationYear != 0 && originalPublicationMonth != 0 && originalPublicationDay != 0)
            {
                OriginalPublicationDate = new DateTime(originalPublicationYear, originalPublicationMonth, originalPublicationDay);
            }

            OriginalTitle = element.ElementAsString("original_title");
            OriginalLanguageId = element.ElementAsNullableInt("original_language_id");
            MediaType = element.ElementAsString("media_type");

            // Parse out the rating distribution
            var ratingDistributionElement = element.ElementAsString("rating_dist");
            if (ratingDistributionElement != null)
            {
                var parts = ratingDistributionElement.Split('|');
                if (parts != null && parts.Length > 0)
                {
                    var ratingDistribution = new Dictionary<int, int>();

                    var ratings = parts.Select(x => x.Split(':'))
                                       .Where(x => x[0] != "total")
                                       .OrderBy(x => x[0]);

                    foreach (var rating in ratings)
                    {
                        int star = 0, count = 0;
                        int.TryParse(rating[0], out star);
                        int.TryParse(rating[1], out count);

                        ratingDistribution.Add(star, count);
                    }

                    RatingDistribution = ratingDistribution;
                }
            }
        }
Example #14
0
 internal override void Parse(XElement element)
 {
     Id = element.ElementAsInt("id");
     Name = element.ElementAsString("name");
     Link = element.ElementAsString("link");
     ImageUrl = element.ElementAsString("image_url");
     SmallImageUrl = element.ElementAsString("small_image_url");
     FriendsCount = element.ElementAsInt("friends_count");
     ReviewsCount = element.ElementAsInt("reviews_count");
     CreatedAt = element.ElementAsDateTime("created_at");
 }
        /// <summary>
        /// Parse series metadata as xml element and returns null if xml is not valid (series has no id) 
        /// </summary>
        /// <param name="seriesXml">Series metadata as xml element</param>
        /// <param name="isSearchElement"></param>
        /// <returns>Returns the successfully parsed series</returns>
        public TheTvDbSeries Parse(XElement seriesXml, bool isSearchElement = false)
        {
            if (seriesXml == null) throw new ArgumentNullException(nameof(seriesXml));

            // If series has no id throw ParseException
            var id = seriesXml.ElementAsUInt("id");
            if (!id.HasValue) throw new TheTvDbParseException("Error while parsing a series xml element. Id is missing.");

            var series = new TheTvDbSeries(id.Value)
            {
                ImdbId = seriesXml.ElementAsString("IMDB_ID"),
                SeriesName = seriesXml.ElementAsString("SeriesName", true),
                Language = seriesXml.ElementAsString(isSearchElement ? "language" : "Language").ToTheTvDbLanguage(),
                Network = seriesXml.ElementAsString("Network"),
                Description = seriesXml.ElementAsString("Overview", true),
                Rating = seriesXml.ElementAsDouble("Rating"),
                RatingCount = seriesXml.ElementAsInt("RatingCount"),
                Runtime = seriesXml.ElementAsInt("Runtime"),
                BannerRemotePath = seriesXml.ElementAsString("banner"),
                FanartRemotePath = seriesXml.ElementAsString("fanart"),
                LastUpdated = seriesXml.ElementFromEpochToDateTime("lastupdated"),
                PosterRemotePath = seriesXml.ElementAsString("poster"),
                Zap2ItId = seriesXml.ElementAsString("zap2it_id"),
                FirstAired = seriesXml.ElementAsDateTime("FirstAired"),
                AirTime = seriesXml.ElementAsTimeSpan("Airs_Time"),
                AirDay = seriesXml.ElementAsEnum<TheTvDbFrequency>("Airs_DayOfWeek"),
                Status = seriesXml.ElementAsEnum<TheTvDbStatus>("Status"),
                ContentRating = seriesXml.ElementAsString("ContentRating").ToTheTvDbContentRating(),
                Genres = seriesXml.ElementAsString("Genre").SplitByPipe()
            };

            if (series.FirstAired.HasValue)
            {
                series.SeriesName = series.SeriesName.Replace(string.Format(" ({0})", series.FirstAired.Value.Year), "");
            }

            return series;
        }
Example #16
0
        internal override void Parse(XElement element)
        {
            Id = element.ElementAsInt("id");
            Title = element.ElementAsString("title");
            TitleWithoutSeries = element.ElementAsString("title_without_series");
            Link = element.ElementAsString("link");
            ImageUrl = element.ElementAsString("image_url");
            SmallImageUrl = element.ElementAsString("small_image_url");
            Isbn = element.ElementAsString("isbn");
            Isbn13 = element.ElementAsString("isbn13");
            AverageRating = element.ElementAsNullableDecimal("average_rating");
            RatingsCount = element.ElementAsNullableInt("ratings_count");
            PublicationDate = element.ElementAsMultiDateField("publication");
            Authors = element.ParseChildren<AuthorSummary>("authors", "author");

            var workElement = element.Element("work");
            if (workElement != null)
            {
                WorkId = workElement.ElementAsNullableInt("id");
            }
        }
Example #17
0
        internal override void Parse(XElement element)
        {
            Id = element.ElementAsInt("id");
            Name = element.ElementAsString("name");
            Link = element.ElementAsString("link");
            FollowersCount = element.ElementAsInt("author_followers_count");
            LargeImageUrl = element.ElementAsString("large_image_url");
            ImageUrl = element.ElementAsString("image_url");
            SmallImageUrl = element.ElementAsString("small_image_url");
            About = element.ElementAsString("about");
            Influences = element.ElementAsString("influences");
            WorksCount = element.ElementAsInt("works_count");
            Gender = element.ElementAsString("gender");
            Hometown = element.ElementAsString("hometown");
            BornOnDate = element.ElementAsDate("born_at");
            DiedOnDate = element.ElementAsDate("died_at");

            IsGoodreadsAuthor = element.ElementAsBool("goodreads_author");
            if (IsGoodreadsAuthor)
            {
                var goodreadsUser = element.Element("user");
                if (goodreadsUser != null)
                {
                    GoodreadsUserId = goodreadsUser.ElementAsInt("id");
                }
            }

            #pragma warning disable 0618
            // We know fans are deprecated but we still populate
            // this value just in case someone needs it.
            FansCount = element.ElementAsInt("fans_count");
            #pragma warning restore 0618
        }
Example #18
0
 internal override void Parse(XElement element)
 {
     Id = element.ElementAsInt("id");
     Name = element.ElementAsString("name");
     Username = element.ElementAsString("user_name");
     Link = element.ElementAsString("link");
     ImageUrl = element.ElementAsString("image_url");
     SmallImageUrl = element.ElementAsString("small_image_url");
     About = element.ElementAsString("about");
     Age = element.ElementAsNullableInt("age");
     Gender = element.ElementAsString("gender");
     Location = element.ElementAsString("location");
     Website = element.ElementAsString("website");
     JoinedDate = element.ElementAsMonthYear("joined");
     LastActiveDate = element.ElementAsMonthYear("last_active");
     Interests = element.ElementAsString("interests");
     FavoriteBooks = element.ElementAsString("favorite_books");
     FavoriteAuthors = element.ParseChildren<AuthorSummary>("favorite_authors", "author");
     UpdatesRssUrl = element.ElementAsString("updates_rss_url");
     ReviewsRssUrl = element.ElementAsString("reviews_rss_url");
     FriendsCount = element.ElementAsInt("friends_count");
     GroupsCount = element.ElementAsInt("groups_count");
     ReviewsCount = element.ElementAsInt("reviews_count");
     Shelves = element.ParseChildren<UserShelf>("user_shelves", "user_shelf");
     IsPrivate = element.ElementAsBool("private");
 }
Example #19
0
 internal override void Parse(XElement element)
 {
     Id = element.ElementAsInt("id");
     Name = element.ElementAsString("name");
     Link = element.ElementAsString("link");
 }
Example #20
0
        internal override void Parse(XElement element)
        {
            Id = element.ElementAsInt("id");
            Title = element.ElementAsString("title", true);
            Description = element.ElementAsString("description", true);
            Note = element.ElementAsString("note", true);
            SeriesWorksCount = element.ElementAsInt("series_works_count");
            PrimaryWorksCount = element.ElementAsInt("primary_work_count");
            IsNumbered = element.ElementAsBool("numbered");

            var seriesWorksElement = element.Element("series_works");
            if (seriesWorksElement != null)
            {
                ParseSeriesWorks(seriesWorksElement);
            }
        }