示例#1
0
        /// <summary>
        /// 갤러리 블록으로 썸네일 파싱
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        static public HitomiArticle ParseGallery(string source)
        {
            HitomiArticle article = new HitomiArticle();

            HtmlDocument document = new HtmlDocument();

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

            article.Thumbnail = nodes.SelectSingleNode(".//a//div//img").GetAttributeValue("src", "").Substring("//tn.hitomi.la/".Length);

            return(article);
        }
示例#2
0
        public static HitomiMetadata ArticleToMetadata(HitomiArticle article)
        {
            HitomiMetadata metadata = new HitomiMetadata();

            metadata.Artists    = article.Artists;
            metadata.Characters = article.Characters;
            metadata.Groups     = article.Groups;
            metadata.ID         = Convert.ToInt32(article.Magic);
            metadata.Language   = LegalizeLanguage(article.Language);
            metadata.Name       = article.Title;
            metadata.Parodies   = article.Series;
            metadata.Tags       = article.Tags.Select(x => LegalizeTag(x)).ToArray();
            metadata.Type       = article.Types;
            return(metadata);
        }
示例#3
0
        public static HitomiArticle MetadataToArticle(HitomiMetadata metadata)
        {
            HitomiArticle article = new HitomiArticle();

            article.Artists       = metadata.Artists;
            article.Characters    = metadata.Characters;
            article.Groups        = metadata.Groups;
            article.Language      = metadata.Language;
            article.Magic         = metadata.ID.ToString();
            article.OriginalTitle = metadata.Name;
            article.Series        = metadata.Parodies;
            article.Tags          = metadata.Tags;
            article.Title         = metadata.Name;
            article.Types         = metadata.Type;
            return(article);
        }
示例#4
0
        static public List <HitomiArticle> ParseArticles(string source)
        {
            List <HitomiArticle> result = new List <HitomiArticle>();
            // Get total blocks
            Regex regex = new Regex(article_block, RegexOptions.Multiline);
            Match match = regex.Match(source);

            while (match.Success)
            {
                HitomiArticle article = new HitomiArticle();

                string block1 = match.Groups[1].Value;
                article.Magic     = getMatch1(block1_magic, block1);
                article.Thumbnail = getMatch1(block1_thumbnail, block1);

                string block2 = match.Groups[2].Value;
                article.Title         = replaceEntity(getMatch1(block2_title, block2));
                article.OriginalTitle = article.Title;
                article.Artists       = new string[] { artist_legalize(getMatch1(block2_artist, block2)) }; // get only first artist

                string block3 = match.Groups[3].Value;
                article.Series   = new string[] { series_legalize(getMatch1(block3_series, block3)) };
                article.Types    = getMatch1(block3_type, block3);
                article.Language = getMatch1(block3_language, block3);
                article.DateTime = DateTime.Parse(getMatch1(block3_type, block3));

                Regex         regex_tags = new Regex(block3_tags, RegexOptions.Multiline);
                Match         match_tags = regex_tags.Match(block3);
                List <string> tags       = new List <string>();
                while (match_tags.Success)
                {
                    tags.Add(match_tags.Groups[1].Value);
                    match_tags = match_tags.NextMatch();
                }
                article.Tags = tags.ToArray();

                result.Add(article);
                match = match.NextMatch();
            }

            return(result);
        }