Ejemplo n.º 1
0
        /// <summary>
        /// 갤러리 블록을 파싱합니다.
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        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", "").Split('/')[2].Split('.')[0];
            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);
        }
Ejemplo n.º 2
0
        public static void AllocateTags(List <Artist> artists)
        {
            if (artists.Count == 0 || artists[0].tags != null)
            {
                return;
            }
            for (int i = 0; i < artists.Count; i++)
            {
                var dict = new Dictionary <string, int>();
                foreach (var article in artists[i].articles)
                {
                    var md = HitomiLegalize.GetMetadataFromMagic(article.ToString()).Value;
                    if (md.Tags == null)
                    {
                        continue;
                    }

                    foreach (var tag in md.Tags)
                    {
                        //if (!dict.ContainsKey(tag))
                        //    dict.Add(tag, 0);
                        //dict[tag]++;
                    }
                }
                artists[i].tags = dict;
            }
        }
Ejemplo n.º 3
0
 public void LoadHiddendataJson()
 {
     thumbnail_collection = new Dictionary <string, string>();
     if (CheckHiddendataExist())
     {
         List <HitomiArticle> articles = JsonConvert.DeserializeObject <List <HitomiArticle> >(File.ReadAllText(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "hiddendata.json")));
         HashSet <string>     overlap  = new HashSet <string>();
         if (metadata_collection == null)
         {
             metadata_collection = new List <HitomiMetadata>();
         }
         metadata_collection.ForEach(x => overlap.Add(x.ID.ToString()));
         foreach (var article in articles)
         {
             if (overlap.Contains(article.Magic))
             {
                 continue;
             }
             metadata_collection.Add(HitomiLegalize.ArticleToMetadata(article));
             if (!thumbnail_collection.ContainsKey(article.Magic))
             {
                 thumbnail_collection.Add(article.Magic, article.Thumbnail);
             }
         }
         SortMetadata();
     }
 }
Ejemplo n.º 4
0
        public async Task DownloadHiddendata()
        {
            Monitor.Instance.Push("Download Hiddendata...");
            thumbnail_collection = new Dictionary <string, string>();
            HttpClient client = new HttpClient();

            client.Timeout = new TimeSpan(0, 0, 0, 0, Timeout.Infinite);
            var zip = await client.GetByteArrayAsync(hidden_data_url);

            var data = zip.Unzip();

            List <HitomiArticle> articles   = JsonConvert.DeserializeObject <List <HitomiArticle> >(data);
            JsonSerializer       serializer = new JsonSerializer();

            serializer.Converters.Add(new JavaScriptDateTimeConverter());
            serializer.NullValueHandling = NullValueHandling.Ignore;

            if (!Settings.Instance.Hitomi.AutoSync)
            {
                Monitor.Instance.Push("Write file: hiddendata.json");
                using (StreamWriter sw = new StreamWriter(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "hiddendata.json")))
                    using (JsonWriter writer = new JsonTextWriter(sw))
                    {
                        serializer.Serialize(writer, articles);
                    }
            }

            HashSet <string> overlap = new HashSet <string>();

            metadata_collection.ForEach(x => overlap.Add(x.ID.ToString()));
            foreach (var article in articles)
            {
                if (overlap.Contains(article.Magic))
                {
                    continue;
                }
                metadata_collection.Add(HitomiLegalize.ArticleToMetadata(article));
                if (!thumbnail_collection.ContainsKey(article.Magic))
                {
                    thumbnail_collection.Add(article.Magic, article.Thumbnail);
                }
            }
            SortMetadata();
            return;
        }
Ejemplo n.º 5
0
        public static void AllocateTypes(List <Artist> artists)
        {
            if (artists.Count == 0 || artists[0].types != null)
            {
                return;
            }
            for (int i = 0; i < artists.Count; i++)
            {
                var dict = new Dictionary <string, int>();
                foreach (var article in artists[i].articles)
                {
                    var md = HitomiLegalize.GetMetadataFromMagic(article.ToString()).Value;

                    var type = md.Type;
                    //if (md.Language == null) type = "n/a";

                    //if (!dict.ContainsKey(type))
                    //    dict.Add(type, 0);
                    //dict[type]++;
                }
                artists[i].types = dict;
            }
        }