Exemplo n.º 1
0
        static public HitomiArticle ParseGalleryBlock(string source)
        {
            HitomiArticle article = new HitomiArticle();

            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(source);
            HtmlNode nodes = document.DocumentNode.SelectNodes("/div")[0];

            article.Magic = nodes.SelectSingleNode("./a").GetAttributeValue("href", "");
            try { article.Thumbnail = nodes.SelectSingleNode("./a//img").GetAttributeValue("data-src", "").Substring("//tn.hitomi.la/".Length).Replace("smallbig", "big"); }
            catch
            { article.Thumbnail = nodes.SelectSingleNode("./a//img").GetAttributeValue("src", "").Substring("//tn.hitomi.la/".Length); }
            article.Title = nodes.SelectSingleNode("./h1").InnerText;

            try { article.Artists = nodes.SelectNodes(".//div[@class='artist-list']//li").Select(node => node.SelectSingleNode("./a").InnerText).ToArray(); }
            catch { article.Artists = new[] { "N/A" }; }

            var contents = nodes.SelectSingleNode("./div[2]/table");

            try { article.Series = contents.SelectNodes("./tr[1]/td[2]/ul/li").Select(node => node.SelectSingleNode(".//a").InnerText).ToArray(); } catch { }
            article.Type = contents.SelectSingleNode("./tr[2]/td[2]/a").InnerText;
            try { article.Language = HitomiLegalize.LegalizeLanguage(contents.SelectSingleNode("./tr[3]/td[2]/a").InnerText); } catch { }
            try { article.Tags = contents.SelectNodes("./tr[4]/td[2]/ul/li").Select(node => HitomiLegalize.LegalizeTag(node.SelectSingleNode(".//a").InnerText)).ToArray(); } catch { }

            article.DateTime = nodes.SelectSingleNode("./div[2]/p").InnerText;

            return(article);
        }
Exemplo n.º 2
0
        public static HitomiMetadata ArticleToMetadata(HitomiArticle article)
        {
            HitomiMetadata metadata = new HitomiMetadata();

            if (article.Artists != null)
            {
                metadata.Artists = article.Artists;
            }
            if (article.Characters != null)
            {
                metadata.Characters = article.Characters;
            }
            if (article.Groups != null)
            {
                metadata.Groups = article.Groups;
            }
            try
            {
                if (article.Magic.Contains("-"))
                {
                    metadata.ID = Convert.ToInt32(article.Magic.Split('-').Last().Split('.')[0]);
                }
                else if (article.Magic.Contains("galleries"))
                {
                    metadata.ID = Convert.ToInt32(article.Magic.Split('/').Last().Split('.')[0]);
                }
                else
                {
                    metadata.ID = Convert.ToInt32(article.Magic);
                }
            }
            catch
            {
                ;
            }
            metadata.Language = LegalizeLanguage(article.Language);
            metadata.Name     = article.Title;
            if (article.Series != null)
            {
                metadata.Parodies = article.Series;
            }
            if (article.Tags != null)
            {
                metadata.Tags = article.Tags.Select(x => LegalizeTag(x)).ToArray();
            }
            metadata.Type = article.Type;
            if (article.DateTime != null)
            {
                metadata.DateTime = DateTime.Parse(article.DateTime);
            }
            return(metadata);
        }
Exemplo n.º 3
0
        static public void FillGallery(string source, HitomiArticle article)
        {
            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(source);
            HtmlNode nodes = document.DocumentNode.SelectSingleNode("/div[@class='gallery-info']/table/tbody");

            foreach (var tr in nodes.SelectNodes("./tr").ToList())
            {
                var tt = tr.SelectSingleNode("./td").InnerText.ToLower().Trim();
                if (tt == "group")
                {
                    article.Groups = tr.SelectNodes(".//a").Select(x => x.InnerText.Trim()).ToArray();
                }
                else if (tt == "characters")
                {
                    article.Characters = tr.SelectNodes(".//a").Select(x => x.InnerText.Trim()).ToArray();
                }
            }
        }
Exemplo n.º 4
0
        static public HitomiArticle ParseGallery(string source)
        {
            HitomiArticle article = new HitomiArticle();

            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(source);
            HtmlNode nodes = document.DocumentNode.SelectSingleNode("//div[@class='content']");

            try
            {
                article.Magic = nodes.SelectSingleNode("./div[3]/h1/a").GetAttributeValue("href", "").Split('/')[2].Split('.')[0];
            }
            catch
            {
                ;
            }
            //article.Title = nodes.SelectSingleNode("./div[3]/h1").InnerText.Trim();
            //article.Thumbnail = nodes.SelectSingleNode("./div[2]/div/a/img").GetAttributeValue("src", "");
            //article.Artists = nodes.SelectSingleNode(".")

            foreach (var tr in document.DocumentNode.SelectNodes("//div[@class='gallery-info']/table/tr").ToList())
            {
                var tt = tr.SelectSingleNode("./td").InnerText.ToLower().Trim();
                if (tt == "group")
                {
                    article.Groups = tr.SelectNodes(".//a")?.Select(x => x.InnerText.Trim()).ToArray();
                }
                else if (tt == "characters")
                {
                    article.Characters = tr.SelectNodes(".//a")?.Select(x => x.InnerText.Trim()).ToArray();
                }
            }

            return(article);
        }