Esempio n. 1
0
        public async void Test()
        {
            Hitomi.HTag tag    = Hitomi.HTag.Parse("artist:2gou");
            InternetP   parser = new InternetP();

            byte[] data = await parser.LoadNozomiTag(tag.type.ToString(), tag.tag, false, 0, 9999);

            int[] ids;
            if (tag.type == Hitomi.HTag.TType.artists.Name)
            {
                ids = parser.ByteArrayToIntArrayBig(data);
            }
            else
            {
                ids = parser.ByteArrayToIntArrayBig(data);
            }
            Console.WriteLine(ids);
        }
Esempio n. 2
0
        public void HitomiSearch()
        {
            List <int> idlist    = new List <int>();
            int        compcount = 0;

            if (cache.Keys.Any(x => x.ItemsEqual(tags)))
            {
                string[] key = cache.Keys.Where(x => x.ItemsEqual(tags)).First();
                this.start(0);
                idlist    = cache[key].ToList();
                compcount = tags.Length;
            }
            else
            {
                List <Task> tasks = new List <Task>();
                this.start(tags.Length);
                Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
                foreach (string tag in tags)
                {
                    Hitomi.HTag tag2 = Hitomi.HTag.Parse(tag);
                    string      path = Path.Combine(Global.rootDir, "Cache", tag2.type, tag2.tag + ".json");
                    if (Global.config.cache_search.Get <bool>())
                    {
                        if (File.Exists(path))
                        {
                            JArray arr = JArray.Parse(File.ReadAllText(path));
                            int[]  ids = arr.Select(x => int.Parse(x.ToString())).ToArray();
                            idlist = idlist.Concat(ids).ToList();
                            compcount++;
                            continue;
                        }
                    }
                    Thread th = new Thread(new ThreadStart(async() =>
                    {
                        int[] ids;
                        InternetP parser = new InternetP();
                        parser.index     = index - 1;
                        parser.Count     = search_count;
                        if (HiyobiTags.Tags.Select(y => y.full).Contains(tag))
                        {
                            try
                            {
                                ids = parser.ByteArrayToIntArrayBig(await parser.LoadNozomiTag(tag2.type.ToString(), tag2.tag, range: !Global.config.cache_search.Get <bool>(), start: 0, end: 99));
                            }
                            catch
                            {
                                ids = new int[0];
                            }
                        }
                        else
                        {
                            ids = await parser.LoadQuery(tag);
                        }
                        if (Global.config.cache_search.Get <bool>() && !File.Exists(path))
                        {
                            if (!Directory.Exists(Path.GetDirectoryName(path)))
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(path));
                            }
                            File.WriteAllText(path, JArray.FromObject(ids).ToString());
                        }
                        dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
                                                                                idlist = idlist.Concat(ids).ToList()));
                        compcount++;
                        dispatcher.Invoke(() => update(compcount, tags.Length));
                    }));
                    th.Start();
                }
            }
            int start     = (index - 1) * itemCount;
            int PageCount = start + itemCount;

            Task.Factory.StartNew(() =>
            {
                while (compcount != tags.Length)
                {
                }
                if (!cache.Keys.Any(x => x.ItemsEqual(tags)))
                {
                    cache.Add(tags, idlist.ToArray());
                }
                List <int> new_idlist = new List <int>();
                for (int i = 0; i < idlist.Count; i++)
                {
                    int count = idlist.Count(y => y == idlist[i]);
                    if (count == tags.Length)
                    {
                        new_idlist.Add(idlist[i]);
                    }
                    if (new_idlist.Count >= PageCount)
                    {
                        break;
                    }
                }
                new_idlist = new_idlist.Skip(start).ToList();
                Global.dispatcher.Invoke(delegate
                {
                    HitomiLoader hitomi = new HitomiLoader();
                    hitomi.Default();
                    LoaderDefaults.Hitomis.Setup(hitomi);
                    hitomi.Parser(new_idlist.ToArray());
                });
            });
        }
Esempio n. 3
0
 public void TagCache()
 {
     if (HiyobiTags.Tags == null)
     {
         HiyobiTags.LoadTags();
     }
     try
     {
         List <Hitomi.HTag> tags        = HiyobiTags.Tags;
         Dispatcher         patcher     = Global.dispatcher;
         ProgressBox        progressBox = null;
         patcher.Invoke(() => {
             progressBox       = new ProgressBox();
             progressBox.Title = "태그 캐시 다운로드";
             progressBox.Show();
             progressBox.ProgressBar.Maximum = tags.Count;
         });
         for (int i = 0; i < tags.Count; i++)
         {
             Hitomi.HTag tag = tags[i];
             Thread      th  = new Thread(new ThreadStart(async() =>
             {
                 try
                 {
                     string dir  = Path.Combine(rootDir, tag.type.ToString());
                     string file = Path.Combine(dir, tag.tag + ".json");
                     if (!Directory.Exists(dir))
                     {
                         Directory.CreateDirectory(dir);
                     }
                     if (File.Exists(file))
                     {
                         //patcher.Invoke(() => progressBox.ProgressBar.Value++);
                         return;
                     }
                     InternetP parser = new InternetP();
                     int[] ids        = parser.ByteArrayToIntArrayBig(await parser.LoadNozomiTag(tag.type.ToString(), tag.tag, false, 0, 9999));
                     JArray arr       = JArray.FromObject(ids);
                     File.WriteAllText(file, arr.ToString());
                     Console.WriteLine("{0}/{1}: {2}", i, tags.Count, tag.full);
                 }
                 catch (IOException) { Console.WriteLine("Faild {0}/{1}: {2}", i, tags.Count, tag.full); }
                 catch (Exception ex) { Console.WriteLine("Error {0} : {1}", tag.full, ex.Message); }
                 finally
                 {
                     patcher.Invoke(() =>
                     {
                         progressBox.ProgressBar.Value++;
                         if (progressBox.ProgressBar.Value == progressBox.ProgressBar.Maximum)
                         {
                             progressBox.Close();
                             MessageBox.Show("캐시 다운로드가 끝났습니다.");
                         }
                     });
                 }
             }));
             th.Start();
         }
     }
     catch (Exception ex) { Console.WriteLine(ex.Message); }
 }