/// <summary>
        /// Create a <see cref="Roles"/> instance and populate it with anime data
        /// </summary>
        /// <param name="roleNodes">Nodes containing role information</param>
        /// <returns>Role instance with populated anime data</returns>
        private static Roles CreateRoleAndPopulateWithAnimeInformation(IReadOnlyList <HtmlNode> roleNodes)
        {
            var role = new Roles
            {
                AnimeUrl = MalRouteBuilder.MalCleanUrl(roleNodes[0]
                                                       .ChildNodes["div"]
                                                       .ChildNodes["a"]
                                                       ?.Attributes["href"]
                                                       .Value)
            };

            int id;

            int.TryParse(role.AnimeUrl.Split('/')[4], out id);
            role.AnimeId = id;

            var animeImg = roleNodes[0]
                           .ChildNodes["div"]
                           .ChildNodes["a"]
                           ?.ChildNodes["img"];

            role.AnimePicUrl = (animeImg?.Attributes["data-src"] ?? animeImg?.Attributes["src"])?.Value;
            role.AnimeTitle  = roleNodes[1]
                               .ChildNodes["a"]
                               ?.InnerText;

            return(role);
        }
        /// <summary>
        /// Populate a <see cref="Roles"/> with character information
        /// </summary>
        /// <param name="role">Role instance that should be populated</param>
        /// <param name="roleNodes">Nodes containing role information</param>
        private static Roles PopulateRoleWithCharacterInformation(this Roles role, IReadOnlyList <HtmlNode> roleNodes)
        {
            role.CharacterName = roleNodes[2]
                                 .ChildNodes["a"]
                                 .InnerText
                                 .Trim();

            role.CharacterUrl = MalRouteBuilder.MalCleanUrl(roleNodes[2]
                                                            .ChildNodes["a"]
                                                            .Attributes["href"]
                                                            .Value);

            int id;

            int.TryParse(role.CharacterUrl.Split('/')[4], out id);
            role.CharacterId = id;

            role.RoleType = roleNodes[2]
                            .ChildNodes["div"]
                            .InnerText
                            .Replace("&nbsp;", "")
                            .Trim();

            var charImage = roleNodes[3]
                            .ChildNodes["div"]
                            .ChildNodes["a"]
                            .ChildNodes["img"];

            role.CharacterPic = (charImage?.Attributes["data-src"] ?? charImage?.Attributes["src"])?.Value;

            return(role);
        }
        /// <summary>
        /// Parse the node data for Related items into a list of <see cref="Related"/> items
        /// </summary>
        /// <param name="node">Node that should be processed</param>
        /// <returns>List of related anime</returns>
        private static IEnumerable <Related> ParseRelatedNodeData(HtmlNode node)
        {
            var relatedShows = new List <Related>();

            var linkNodes = node
                            .ChildNodes[1]
                            .ChildNodes
                            .Where(x => x.Name == "a")
                            .ToList();

            foreach (var link in linkNodes)
            {
                var url = MalRouteBuilder.MalCleanUrl(link.Attributes["href"].Value);
                int id;
                int.TryParse(url.Split('/')[4], out id);

                relatedShows.Add(new Related
                {
                    Id    = id,
                    Title = link.InnerText,
                    Url   = url
                });
            }

            return(relatedShows);
        }
Beispiel #4
0
        /// <summary>
        /// Populate Seiyuu information for a character
        /// </summary>
        /// <param name="character">Character to which the Seiyuu information should be added</param>
        /// <param name="seiyuuInfoNodes">HtmlNodes containing the Seiyuu information</param>
        /// <returns>Character instance</returns>
        private static CharacterInformation PopulateSeiyuu(this CharacterInformation character,
                                                           IEnumerable <HtmlNode> seiyuuInfoNodes)
        {
            foreach (var detail in seiyuuInfoNodes)
            {
                var picNode = detail.ChildNodes[3]
                              .ChildNodes["div"]
                              .ChildNodes["a"]
                              .ChildNodes["img"];

                var tmpSeiyuu = new SeiyuuInformation
                {
                    Language   = detail.ChildNodes["td"].ChildNodes["small"].InnerText,
                    Name       = detail.ChildNodes["td"].ChildNodes["a"].InnerText,
                    Url        = MalRouteBuilder.MalCleanUrl(detail.ChildNodes["td"].ChildNodes["a"].Attributes["href"].Value),
                    PictureUrl = (picNode.Attributes["data-src"] ?? picNode.Attributes["src"])?.Value
                };

                int id;
                if (int.TryParse(tmpSeiyuu.Url.Split('/')[4], out id))
                {
                    tmpSeiyuu.Id = id;
                }

                character.Seiyuu.Add(tmpSeiyuu);
            }
            return(character);
        }
Beispiel #5
0
        /// <summary>
        /// Retrieve character's seiyuu
        /// </summary>
        /// <param name="character">Character instance to populate</param>
        /// <param name="doc">Html document from which data should be pulled</param>
        /// <returns>Character instance</returns>
        public static Character RetrieveSeiyuu(this Character character, HtmlDocument doc)
        {
            var tables = doc.DocumentNode
                         .SelectNodes("//table")
                         .Skip(3);

            foreach (var table in tables)
            {
                var seiyuu = new SeiyuuInformation();
                var info   = table
                             .ChildNodes["tr"]
                             .ChildNodes
                             .Where(x => x.Name == "td")
                             .ToList();

                seiyuu.PictureUrl = info[0]
                                    .ChildNodes["div"]
                                    .ChildNodes["a"]
                                    .ChildNodes["img"]
                                    .Attributes["src"]
                                    .Value;

                seiyuu.Name = info[1]
                              .ChildNodes["a"]
                              .InnerText;

                seiyuu.Url = MalRouteBuilder.MalCleanUrl(info[1]
                                                         .ChildNodes["a"]
                                                         .Attributes["href"]
                                                         .Value);

                int id;
                if (int.TryParse(seiyuu.Url.Split('/')[4], out id))
                {
                    seiyuu.Id = id;
                }

                character.Seiyuu.Add(seiyuu);
            }

            return(character);
        }
Beispiel #6
0
        /// <summary>
        /// Create a new Character instance from HtmlNodes
        /// </summary>
        /// <param name="nodes">HtmlNodes containing the character information</param>
        /// <returns>Character instance</returns>
        private static CharacterInformation CreateCharacter(IList <HtmlNode> nodes)
        {
            var picLocation = nodes[0]
                              .ChildNodes["div"]
                              .ChildNodes["a"]
                              .ChildNodes["img"];

            var url = MalRouteBuilder.MalCleanUrl(nodes[1].ChildNodes["a"].Attributes["href"].Value);
            int id;

            int.TryParse(url.Split('/')[4], out id);

            return(new CharacterInformation
            {
                CharacterPicture = (picLocation.Attributes["data-src"] ?? picLocation.Attributes["src"])?.Value,
                CharacterName = nodes[1].ChildNodes["a"].InnerText,
                CharacterUrl = url,
                CharacterType = nodes[1].ChildNodes["div"].InnerText,
                Id = id
            });
        }
Beispiel #7
0
        /// <summary>
        /// Parse rows containing Ography
        /// </summary>
        /// <param name="ographyNodes">Nodes that should be parsed for ography details</param>
        /// <returns>List of ography items</returns>
        private static List <Ography> ParseOgraphy(IEnumerable <HtmlNode> ographyNodes)
        {
            var results = new List <Ography>();

            foreach (var row in ographyNodes)
            {
                var tmpEntry = new Ography();

                var cells = row.ChildNodes
                            .Where(x => x.Name == "td")
                            .ToList();

                tmpEntry.ImageUrl = cells
                                    .First(x => x.FirstChild.Name == "div")
                                    .FirstChild
                                    .ChildNodes["a"]
                                    .ChildNodes["img"]
                                    .Attributes["src"]
                                    .Value;

                var details = cells
                              .First(x => x.FirstChild.Name == "a")
                              .FirstChild;

                tmpEntry.Url  = MalRouteBuilder.MalCleanUrl(details.Attributes["href"].Value);
                tmpEntry.Name = details.InnerText;
                int id;
                if (int.TryParse(tmpEntry.Url.Split('/')[4], out id))
                {
                    tmpEntry.Id = id;
                }
                results.Add(tmpEntry);
            }

            return(results);
        }