private async Task <string> GetThumbnailAddress(string id)
        {
            try
            {
                var url = $"{HitomiCommon.HitomiGalleryBlock}{id}.html";
                lock (Koromo_Copy.Monitor.Instance) Koromo_Copy.Monitor.Instance.Push($"Download string: {url}");
                using (var wc = Koromo_Copy.Net.NetCommon.GetDefaultClient())
                {
                    wc.Encoding = Encoding.UTF8;
                    wc.Headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
                    wc.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36");
                    var html = await wc.DownloadStringTaskAsync(url);

                    return(HitomiCommon.HitomiThumbnail + HitomiParser.ParseGalleryBlock(html).Thumbnail);
                }
            }
            catch
            {
                var har = HCommander.GetArticleData(Convert.ToInt32(id));
                if (!har.HasValue)
                {
                    return("");
                }
                return(har.Value.Thumbnail);
            }
        }
        private async Task <string> GetThumbnailAddress(int id)
        {
            try
            {
                var url = $"{HitomiCommon.HitomiGalleryBlock}{id}.html";
                lock (Monitor.Instance) Monitor.Instance.Push($"Download string: {url}");
                using (var wc = Koromo_Copy.Net.NetCommon.GetDefaultClient())
                {
                    wc.Encoding = Encoding.UTF8;
                    wc.Headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
                    wc.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36");
                    var html = await wc.DownloadStringTaskAsync(url);

                    return(HitomiCommon.HitomiThumbnail + HitomiParser.ParseGalleryBlock(html).Thumbnail);
                }
            }
            catch
            {
                var har = HCommander.GetArticleData(id);
                if (!har.HasValue)
                {
                    await Application.Current.Dispatcher.BeginInvoke(new Action(
                                                                         delegate
                    {
                        MessageBox.Show($"{id}를 로딩하지 못했습니다 ㅠㅠ", Title, MessageBoxButton.OK, MessageBoxImage.Error);
                    }));

                    return("");
                }
                return(har.Value.Thumbnail);
            }
        }
Ejemplo n.º 3
0
        private void process(int i)
        {
            try
            {
                WebClient wc = new WebClient();
                wc.Encoding = Encoding.UTF8;
                string x;
                x = wc.DownloadString("https://hitomi.la/galleries/" + magics[i] + ".html");
                var list = HitomiParser.ParseArticles(x);
                foreach (var data in list)
                {
                    if (!magic_set.Contains(Convert.ToInt32(data.Magic)))
                    {
                        magic_set.Add(Convert.ToInt32(data.Magic));
                        new_article.Add(data);
                        LogEssential.Instance.PushLog(() => $"New! {data.Magic}");
                    }
                }
            }
            catch (Exception ex)
            {
                LogEssential.Instance.PushLog(() => $"{i} error {ex.Message}");
            }

            this.Post(() => progressBar1.Value++);
            this.Post(() => label3.Text = $"{progressBar1.Value}/{magics.Count} 분석완료");
            this.Post(() => label5.Text = $"{(new DateTime((DateTime.Now - start).Ticks * magics.Count / progressBar1.Value)).ToString("HH시간 mm분 ss초")}");

            lock (int_lock) mtx--;
            lock (notify_lock) Notify();
        }
Ejemplo n.º 4
0
        private void process(int i)
        {
            try
            {
                if (exists.Contains(i))
                {
                    goto FINISH;
                }
                WebClient wc = new WebClient();
                wc.Encoding = Encoding.UTF8;
                string x;
                x = wc.DownloadString("https://ltn.hitomi.la/galleryblock/" + i + ".html");
                result.Add(HitomiParser.ParseArticles(x)[0]);
                PushString($"New! {i}");
            }
            catch (Exception ex)
            {
            }

FINISH:

            this.Post(() => progressBar1.Value++);
            this.Post(() => label3.Text = $"{progressBar1.Value}/{maximum - minimum + 1} 분석완료");
            this.Post(() => label5.Text = $"{(new DateTime((DateTime.Now - start).Ticks * (maximum - minimum + 1 - progressBar1.Value) / progressBar1.Value)).ToString("HH시간 mm분 ss초")}");

            lock (int_lock) mtx--;
            lock (notify_lock) Notify();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 이미지 링크를 다운로드하고 정보를 출력합니다.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="dl">다운로드 가능한 이미지 링크를 출력할지의 여부를 설정합니다.</param>
        static void ProcessImage(string[] args)
        {
            string json_source = NetCommon.DownloadString(HiyobiCommon.GetDownloadImageAddress(args[0]));
            var    image_link  = HitomiParser.GetImageLink(json_source);

            Console.Instance.WriteLine(image_link);
        }
        private void RecommendArtistElements_Loaded(object sender, RoutedEventArgs e)
        {
            if (IsDataLoaded)
            {
                return;
            }
            IsDataLoaded = true;
            Task.Run(() =>
            {
                List <string> titles = new List <string>();
                List <string> magics = new List <string>();

                for (int i = 0, j = 0; i < 5 && j < HitomiIndex.Instance.metadata_collection.Count; j++)
                {
                    if (HitomiIndex.Instance.metadata_collection[j].Artists != null &&
                        ((HitomiIndex.Instance.metadata_collection[j].Language >= 0 ? Settings.Instance.Hitomi.Language == HitomiIndex.Instance.index.Languages[HitomiIndex.Instance.metadata_collection[j].Language] : Settings.Instance.Hitomi.Language == "n/a") || Settings.Instance.Hitomi.Language == "all") &&
                        HitomiIndex.Instance.metadata_collection[j].Artists.Select(x => HitomiIndex.Instance.index.Artists[x]).Contains(Artist))
                    {
                        string ttitle = HitomiIndex.Instance.metadata_collection[j].Name.Split('|')[0];
                        if (titles.Count > 0 && !titles.TrueForAll((title) => Strings.ComputeLevenshteinDistance(ttitle, title) > Settings.Instance.Hitomi.TextMatchingAccuracy))
                        {
                            continue;
                        }

                        titles.Add(ttitle);
                        magics.Add(HitomiIndex.Instance.metadata_collection[j].ID.ToString());
                        i++;
                    }
                }
                require_count  = magics.Count;
                loaded_count   = 0;
                Image[] images = { Image1, Image2, Image3, Image4, Image5 };
                for (int i = 0; i < magics.Count; i++)
                {
                    var thumbnail = HitomiCommon.HitomiThumbnail + HitomiParser.ParseGalleryBlock(Koromo_Copy.Net.NetCommon.DownloadString(
                                                                                                      $"{HitomiCommon.HitomiGalleryBlock}{magics[i]}.html")).Thumbnail;

                    int j = i;
                    Application.Current.Dispatcher.BeginInvoke(new Action(
                                                                   delegate
                    {
                        BitmapImage[j] = new BitmapImage();
                        BitmapImage[j].BeginInit();
                        BitmapImage[j].UriSource = new Uri(thumbnail);
                        if (Settings.Instance.Model.LowQualityImage)
                        {
                            BitmapImage[j].DecodePixelWidth = 100;
                        }
                        BitmapImage[j].EndInit();
                        BitmapImage[j].DownloadCompleted += BitmapImage_DownloadCompleted;
                    }));
                }
            });
        }
Ejemplo n.º 7
0
        static private void wc_dasil(object sender, DownloadStringCompletedEventArgs e)
        {
            Tuple <PicElement, CallBack> tuple = (Tuple <PicElement, CallBack>)e.UserState;

            tuple.Item1.Article.ImagesLink = HitomiParser.ParsePage(e.Result);

            lock (tuple.Item2)
            {
                tuple.Item2(tuple.Item1);
            }
        }
Ejemplo n.º 8
0
        private void download_image()
        {
            string localFilename = Path.GetTempFileName();

            using (WebClient client = new WebClient())
            {
                string set = client.DownloadString(new Uri(HitomiDef.HitomiGalleryAddress + metadata.ID + ".html"));
                client.DownloadFile(HitomiDef.HitomiThumbnail + HitomiParser.ParseGallery(set).Thumbnail, localFilename);
                load_image(localFilename);
            }
        }
Ejemplo n.º 9
0
        private void download_image()
        {
            string localFilename = Path.GetTempFileName();

            using (WebClient client = new WebClient())
            {
                string set = client.DownloadString(new Uri(HitomiDef.HitomiGalleryAddress + metadata.ID + ".html"));
                client.DownloadFile(HitomiDef.HitomiThumbnail + HitomiParser.ParseGallery(set).Thumbnail, localFilename);
                load_image(localFilename);
                LogEssential.Instance.PushLog(() => $"Download image successful! {HitomiDef.HitomiThumbnail + HitomiParser.ParseGallery(set).Thumbnail} {localFilename}");
            }
        }
Ejemplo n.º 10
0
 private string GetThumbnailAddress(string id)
 {
     try
     {
         WebClient wc = new WebClient
         {
             Encoding = Encoding.UTF8
         };
         return(HitomiParser.ParseGallery(wc.DownloadString(
                                              new Uri($"https://hitomi.la/galleries/{id}.html"))).Thumbnail);
     }
     catch { }
     return("");
 }
        private void process(int i)
        {
            try
            {
                if (exists.Contains(i))
                {
                    goto FINISH;
                }
                WebClient wc = new WebClient();
                wc.Encoding = Encoding.UTF8;
                string x;
                x = wc.DownloadString("https://ltn.hitomi.la/galleryblock/" + i + ".html");
                var aa = HitomiParser.ParseGalleryBlock(x);
                try
                {
                    if (aa.Magic.Contains("-"))
                    {
                        x = wc.DownloadString("https://hitomi.la/" + aa.Magic);
                    }
                    else
                    {
                        x = wc.DownloadString("https://hitomi.la/galleries/" + i + ".html");
                    }
                    var a2 = HitomiParser.ParseGallery(x);
                    aa.Groups     = a2.Groups;
                    aa.Characters = a2.Characters;
                }
                catch { }
                result.Add(aa);
                PushString($"New! {i}");
            }
            catch (Exception ex)
            {
                Koromo_Copy.Console.Console.Instance.WriteLine(ex.Message + " " + i);
            }

FINISH:

            this.Post(() => progressBar1.Value++);
            this.Post(() => label3.Text = $"{progressBar1.Value}/{maximum - minimum + 1} 분석완료");
            this.Post(() => label5.Text = $"{(new DateTime((DateTime.Now - start).Ticks * (maximum - minimum + 1 - progressBar1.Value) / progressBar1.Value)).ToString("HH시간 mm분 ss초")}");

            lock (int_lock) mtx--;
            lock (notify_lock) Notify();
        }
Ejemplo n.º 12
0
 static public string GetThumbnailAddress(string id)
 {
     try
     {
         if (HitomiData.Instance.thumbnail_collection.ContainsKey(id))
         {
             return(HitomiData.Instance.thumbnail_collection[id]);
         }
         WebClient wc = new WebClient
         {
             Encoding = Encoding.UTF8
         };
         return(HitomiParser.ParseGallery2(wc.DownloadString(
                                               new Uri($"{HitomiDef.HitomiGalleryBlock}{id}.html"))).Thumbnail);
     }
     catch { }
     return("");
 }
Ejemplo n.º 13
0
        private void CallbackSearch(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                return;
            }

            foreach (HitomiArticle ha in HitomiParser.ParseArticles(e.Result))
            {
                string    temp = Path.GetTempFileName();
                WebClient wc   = new WebClient();
                wc.Headers["Accept-Encoding"] = "application/x-gzip";
                wc.Encoding = Encoding.UTF8;
                wc.DownloadFileCompleted += CallbackThumbnail;
                wc.DownloadFileAsync(new Uri(HitomiDef.HitomiThumbnail + ha.Thumbnail), temp,
                                     new Tuple <string, HitomiArticle>(temp, ha));
            }
        }
Ejemplo n.º 14
0
        private void download_image()
        {
            string localFilename = Path.GetTempFileName();

            using (WebClient client = new WebClient())
            {
                string url;
                if (HitomiData.Instance.thumbnail_collection.ContainsKey(id))
                {
                    url = HitomiDef.HitomiThumbnail + HitomiData.Instance.thumbnail_collection[id];
                }
                else
                {
                    url = HitomiDef.HitomiThumbnail + HitomiParser.ParseGallery2(client.DownloadString(
                                                                                     new Uri($"{HitomiDef.HitomiGalleryBlock}{metadata.ID}.html"))).Thumbnail;
                }
                client.DownloadFile(url, localFilename);
                load_image(localFilename);
                LogEssential.Instance.PushLog(() => $"Download image successful! {url} {localFilename}");
            }
        }
Ejemplo n.º 15
0
        private void CallbackSearch2(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                return;
            }

            HitomiArticle ha = HitomiParser.ParseGallery(e.Result);

            ha.Magic   = (e.UserState as string[])[0];
            ha.Title   = (e.UserState as string[])[1];
            ha.Artists = (e.UserState as string[])[2];
            ha.Tags    = new List <string>((e.UserState as string[])[3].Split(','));
            string    temp = Path.GetTempFileName();
            WebClient wc   = new WebClient();

            wc.Headers["Accept-Encoding"] = "application/x-gzip";
            wc.Encoding = Encoding.UTF8;
            wc.DownloadFileCompleted += CallbackThumbnail;
            wc.DownloadFileAsync(new Uri(HitomiDef.HitomiThumbnail + ha.Thumbnail), temp,
                                 new Tuple <string, HitomiArticle>(temp, ha));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 이미지 링크를 다운로드하고 정보를 출력합니다.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="dl">다운로드 가능한 이미지 링크를 출력할지의 여부를 설정합니다.</param>
        static void ProcessImage(string[] args, string type)
        {
            string html_source = NetCommon.DownloadString($"{HitomiCommon.HitomiGalleryAddress}{args[0]}.js");
            var    image_link  = HitomiParser.GetImageLink(html_source);

            if (type == null)
            {
                Console.Instance.WriteLine(image_link.Select(x => HitomiCommon.GetDownloadImageAddress(args[0], x, false, "")));
            }
            else if (type == "small")
            {
                Console.Instance.WriteLine(image_link.Select(x => $"{HitomiCommon.HitomiThumbnailSmall}{args[0]}/{x}.jpg"));
            }
            else if (type == "big")
            {
                Console.Instance.WriteLine(image_link.Select(x => $"{HitomiCommon.HitomiThumbnailBig}{args[0]}/{x}.jpg"));
            }
            else
            {
                Console.Instance.WriteErrorLine($"'{type}' is not correct type. Please input 'small' or 'big'.");
            }
        }
        private void SearchMaterialElements_Loaded(object sender, RoutedEventArgs e)
        {
            if (init)
            {
                return;
            }
            init = true;
            Task.Run(() =>
            {
                HitomiArticle ha = Article as HitomiArticle;
                try
                {
                    ha.Thumbnail = HitomiCommon.HitomiThumbnail + HitomiParser.ParseGalleryBlock(Koromo_Copy.Net.NetCommon.DownloadString(
                                                                                                     $"{HitomiCommon.HitomiGalleryBlock}{ha.Magic}.html")).Thumbnail;
                    ha.ImagesLink = HitomiParser.GetImageLink(Koromo_Copy.Net.NetCommon.DownloadString(HitomiCommon.GetImagesLinkAddress(ha.Magic)));
                }
                catch
                {
                    ha.IsUnstable = true;
                    var har       = HCommander.GetArticleData(Convert.ToInt32(ha.Magic));
                    if (!har.HasValue)
                    {
                        MessageBox.Show($"{ha.Magic}를 찾을 수 없습니다. 이 항목은 히요비, 이헨, 익헨 어디에도 없었습니다. 프로그램 제작자에게 문의하세요.", "Koromo copy", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                    ha.UnstableModel = har.Value;
                    ha.Thumbnail     = ha.UnstableModel.Thumbnail;
                    ha.ImagesLink    = new List <string>();
                }
                Application.Current.Dispatcher.BeginInvoke(new Action(
                                                               delegate
                {
                    try
                    {
                        if (ha.IsUnstable && ha.UnstableModel.ArticleType == HArticleType.EXHentai)
                        {
                            var image = NetCommon.GetExHentaiClient().DownloadData(new Uri(ha.UnstableModel.Thumbnail));
                            using (var ms = new System.IO.MemoryStream(image))
                            {
                                BitmapImage.BeginInit();
                                if (Settings.Instance.Model.LowQualityImage)
                                {
                                    BitmapImage.DecodePixelWidth = 100;
                                }
                                BitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
                                BitmapImage.StreamSource = ms;
                                BitmapImage.EndInit();
                            }
                        }
                        else
                        {
                            BitmapImage.BeginInit();
                            BitmapImage.UriSource = new Uri(ha.Thumbnail);
                            if (Settings.Instance.Model.LowQualityImage)
                            {
                                BitmapImage.DecodePixelWidth = 100;
                            }
                            BitmapImage.EndInit();
                            BitmapImage.DownloadCompleted += B_DownloadCompleted;
                        }
                    }
                    catch (Exception ex)
                    {
                        Monitor.Instance.Push("[SME Error] " + ex.Message + "\r\n" + ex.StackTrace);
                    }

                    ImageCount.Text = ha.ImagesLink.Count + " Pages";
                    Image.Source    = BitmapImage;

                    if (ha.Artists != null && ha.Artists[0].ToUpper() != "N/A")
                    {
                        var stack = new StackPanel {
                            Orientation = Orientation.Horizontal
                        };
                        stack.Children.Add(new PackIcon {
                            Kind = PackIconKind.Artist, Opacity = .56
                        });
                        stack.Children.Add(new TextBlock {
                            Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center, Text = "작가 목록"
                        });
                        var menu_item = new MenuItem {
                            Header = stack
                        };
                        foreach (var artist in ha.Artists)
                        {
                            var item = new MenuItem {
                                Header = new TextBlock {
                                    Text = artist
                                }, Tag = $"artist:{artist.Replace(' ', '_')}"
                            };
                            item.Click += MenuItem_Click;
                            menu_item.Items.Add(item);
                        }
                        Menu.Items.Add(menu_item);
                    }
                    if (ha.Groups != null && ha.Groups[0].ToUpper() != "N/A")
                    {
                        var stack = new StackPanel {
                            Orientation = Orientation.Horizontal
                        };
                        stack.Children.Add(new PackIcon {
                            Kind = PackIconKind.UserGroup, Opacity = .56
                        });
                        stack.Children.Add(new TextBlock {
                            Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center, Text = "그룹 목록"
                        });
                        var menu_item = new MenuItem {
                            Header = stack
                        };
                        foreach (var group in ha.Groups)
                        {
                            var item = new MenuItem {
                                Header = new TextBlock {
                                    Text = group
                                }, Tag = $"group:{group.Replace(' ', '_')}"
                            };
                            item.Click += MenuItem_Click;
                            menu_item.Items.Add(item);
                        }
                        Menu.Items.Add(menu_item);
                    }
                    if (ha.Series != null)
                    {
                        var stack = new StackPanel {
                            Orientation = Orientation.Horizontal
                        };
                        stack.Children.Add(new PackIcon {
                            Kind = PackIconKind.Book, Opacity = .56
                        });
                        stack.Children.Add(new TextBlock {
                            Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center, Text = "시리즈 목록"
                        });
                        var menu_item = new MenuItem {
                            Header = stack
                        };
                        foreach (var series in ha.Series)
                        {
                            MenuItem item = null;
                            if (KoreanSeries.SeriesMap(series) == series)
                            {
                                item = new MenuItem {
                                    Header = new TextBlock {
                                        Text = series
                                    }, Tag = $"series:{series.Replace(' ', '_')}"
                                }
                            }
                            ;
                            else
                            {
                                item = new MenuItem {
                                    Header = new TextBlock {
                                        Text = $"{series} ({KoreanSeries.SeriesMap(series)})"
                                    }, Tag = $"series:{series.Replace(' ', '_')}"
                                }
                            };
                            item.Click += MenuItem_Click;
                            menu_item.Items.Add(item);
                        }
                        Menu.Items.Add(menu_item);
                    }
                    if (ha.Tags != null)
                    {
                        var stack = new StackPanel {
                            Orientation = Orientation.Horizontal
                        };
                        stack.Children.Add(new PackIcon {
                            Kind = PackIconKind.Tag, Opacity = .56
                        });
                        stack.Children.Add(new TextBlock {
                            Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center, Text = "태그 목록"
                        });
                        var menu_item = new MenuItem {
                            Header = stack
                        };
                        foreach (var tag in ha.Tags)
                        {
                            MenuItem item = null;
                            if (KoreanTag.TagMap(tag) == tag)
                            {
                                item = new MenuItem {
                                    Header = new TextBlock {
                                        Text = tag
                                    }, Tag = $"{(tag.StartsWith("female:") || tag.StartsWith("male:") ? tag.Replace(' ', '_') : $"tag:{tag.Replace(' ', '_')}")}"
                                }
                            }
                            ;
                            else if (KoreanTag.TagMap(tag).Contains(':'))
                            {
                                item = new MenuItem {
                                    Header = new TextBlock {
                                        Text = $"{tag} ({KoreanTag.TagMap(tag).Split(':')[1]})"
                                    }, Tag = $"{(tag.StartsWith("female:") || tag.StartsWith("male:") ? tag.Replace(' ', '_') : $"tag:{tag.Replace(' ', '_')}")}"
                                }
                            }
                            ;
                            else
                            {
                                item = new MenuItem {
                                    Header = new TextBlock {
                                        Text = $"{tag} ({KoreanTag.TagMap(tag)})"
                                    }, Tag = $"{(tag.StartsWith("female:") || tag.StartsWith("male:") ? tag.Replace(' ', '_') : $"tag:{tag.Replace(' ', '_')}")}"
                                }
                            };
                            item.Click += MenuItem_Click;
                            menu_item.Items.Add(item);
                        }
                        Menu.Items.Add(menu_item);
                    }
                }));
            });
Ejemplo n.º 18
0
        public List <string> ParseImages(string html, IArticle article)
        {
            var article_to = article as HiyobiArticle;

            return(HitomiParser.GetImageLink(html).Select(x => x.StartsWith("http://") || x.StartsWith("https://") ? $"https://aa.hiyobi.me/data_m/{article_to.Magic}/{Uri.EscapeDataString(x.Split('/').Last())}" : $"https://aa.hiyobi.me/data_m/{article_to.Magic}/{x}").ToList());
        }
Ejemplo n.º 19
0
        static void ProcessStart()
        {
            Console.Clear();
            Console.Title = "hsync";

            Console.WriteLine($"hsync - DB Synchronization Manager");
            Console.WriteLine($"Copyright (C) 2020. project violet-server.");
            Console.WriteLine($"Version: {Version.Text} (Build: {Internals.GetBuildDate().ToLongDateString()})");
            Console.WriteLine("");

            if (!File.Exists("hiddendata.json"))
            {
                Logs.Instance.Push("Welcome to hsync!\r\n\tDownload the necessary data before running the program!");
                download_data("https://github.com/project-violet/database/releases/download/rd2020.06.07/hiddendata.json", "hiddendata.json");
            }
            if (!File.Exists("metadata.json"))
            {
                download_data("https://github.com/project-violet/database/releases/download/rd2020.06.07/metadata.json", "metadata.json");
            }
            if (!File.Exists("ex-hentai-archive.json"))
            {
                download_data("https://github.com/project-violet/database/releases/download/rd2020.06.07/ex-hentai-archive.json", "ex-hentai-archive.json");
            }

            HitomiData.Instance.Load();

            var latest = HitomiData.Instance.metadata_collection.First().ID;

//#if true
            // Sync Hitomi
            {
                var range  = 2000;
                var exists = new HashSet <int>();
                foreach (var metadata in HitomiData.Instance.metadata_collection)
                {
                    exists.Add(metadata.ID);
                }

                var gburls = Enumerable.Range(latest - range, range * 2).Where(x => !exists.Contains(x)).Select(x => $"https://ltn.hitomi.la/galleryblock/{x}.html").ToList();
                var dcnt   = 0;
                var ecnt   = 0;
                Console.Write("Running galleryblock tester... ");
                List <string> htmls;
                using (var pb = new ProgressBar())
                {
                    htmls = NetTools.DownloadStrings(gburls, "",
                                                     () => {
                        pb.Report(gburls.Count, Interlocked.Increment(ref dcnt), ecnt);
                    },
                                                     () => {
                        pb.Report(gburls.Count, dcnt, Interlocked.Increment(ref ecnt));
                    });
                }
                Console.WriteLine("Complete");

                var gurls = new List <string>(gburls.Count);
                for (int i = 0; i < gburls.Count; i++)
                {
                    if (htmls[i] == null)
                    {
                        continue;
                    }
                    var aa = HitomiParser.ParseGalleryBlock(htmls[i]);
                    if (aa.Magic.Contains("-"))
                    {
                        gurls.Add("https://hitomi.la/" + aa.Magic);
                    }
                    else
                    {
                        gurls.Add("https://hitomi.la/galleries/" + i + ".html");
                    }
                }

                dcnt = 0;
                ecnt = 0;
                Console.Write("Running gallery tester... ");
                List <string> htmls2 = null;
                if (gurls.Count != 0)
                {
                    using (var pb = new ProgressBar())
                    {
                        htmls2 = NetTools.DownloadStrings(gurls, "",
                                                          () => {
                            pb.Report(gburls.Count, Interlocked.Increment(ref dcnt), ecnt);
                        },
                                                          () => {
                            pb.Report(gburls.Count, dcnt, Interlocked.Increment(ref ecnt));
                        });
                    }
                }
                Console.WriteLine("Complete");

                Console.Write("Check redirect gallery html... ");
                var last_change = true;
                while (last_change)
                {
                    last_change = false;
                    for (int i = 0; i < htmls2.Count; i++)
                    {
                        if (htmls2[i] == null)
                        {
                            continue;
                        }
                        var node  = htmls2[i].ToHtmlNode();
                        var title = node.SelectSingleNode("//title");
                        if (title != null && title.InnerText == "Redirect")
                        {
                            htmls2[i]   = NetTools.DownloadString(node.SelectSingleNode("//a").GetAttributeValue("href", ""));
                            last_change = true;
                        }
                    }
                }
                Console.WriteLine("Complete");

                var result = new List <HitomiArticle>();
                for (int i = 0, j = 0; i < gburls.Count; i++)
                {
                    if (htmls[i] == null)
                    {
                        continue;
                    }
                    var aa = HitomiParser.ParseGalleryBlock(htmls[i]);
                    if (htmls2[j] != null)
                    {
                        var ab = HitomiParser.ParseGallery(htmls2[j]);
                        aa.Groups     = ab.Groups;
                        aa.Characters = ab.Characters;
                    }
                    result.Add(aa);
                    j++;
                }

                Console.Write("Save to hiddendata.json... ");
                HitomiData.Instance.SaveWithNewData(result);
                Console.WriteLine("Complete");

//#if true
//                Console.Write("Save to index-metadata.json... ");
//                HitomiIndex.MakeIndex();
//                Console.WriteLine("Complete");
//#endif
            }

//#if false
            // Sync EH
            {
                var result = new List <EHentaiResultArticle>();

                for (int i = 0; i < 9999999; i++)
                {
                    try
                    {
                        //var task = NetTask.MakeDefault($"https://exhentai.org/?page={i}&f_doujinshi=on&f_manga=on&f_artistcg=on&f_gamecg=on&&f_cats=0&f_sname=on&f_stags=on&f_sh=on&advsearch=1&f_srdd=2&f_sname=on&f_stags=on&f_sdesc=on&f_sh=on");
                        //task.Cookie = "igneous=30e0c0a66;ipb_member_id=2742770;ipb_pass_hash=6042be35e994fed920ee7dd11180b65f;sl=dm_2";
                        //var html = NetTools.DownloadString(task);
                        var url = $"https://exhentai.org/?page={i}&f_doujinshi=on&f_manga=on&f_artistcg=on&f_gamecg=on&&f_cats=0&f_sname=on&f_stags=on&f_sh=on&advsearch=1&f_srdd=2&f_sname=on&f_stags=on&f_sdesc=on&f_sh=on";
                        var wc  = new WebClient();
                        wc.Encoding = Encoding.UTF8;
                        wc.Headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
                        wc.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36");
                        wc.Headers.Add(HttpRequestHeader.Cookie, "igneous=30e0c0a66;ipb_member_id=2742770;ipb_pass_hash=6042be35e994fed920ee7dd11180b65f;sl=dm_2");
                        var html = wc.DownloadString(url);

                        try
                        {
                            var exh = ExHentaiParser.ParseResultPageExtendedListView(html);
                            result.AddRange(exh);
                            if (exh.Count != 25)
                            {
                                Logs.Instance.PushWarning("[Miss] " + url);
                            }
                            if (i > 500 && exh.Min(x => x.URL.Split('/')[4].ToInt()) < latest)
                            {
                                break;
                            }
                            Logs.Instance.Push("Parse exh page - " + i);
                        }
                        catch (Exception e)
                        {
                            Logs.Instance.PushError("[Fail] " + url);
                        }
                    }
                    catch (Exception e)
                    {
                        Logs.Instance.PushError($"{i} {e.Message}");
                    }
                    Thread.Sleep(100);

                    if (i % 1000 == 999)
                    {
                        Thread.Sleep(60000);
                    }
                }

                var xxx = JsonConvert.DeserializeObject <List <EHentaiResultArticle> >(File.ReadAllText("ex-hentai-archive.json"));
                File.Move("ex-hentai-archive.json", $"ex-hentai-archive-{DateTime.Now.Ticks}.json");

                var exists = new HashSet <int>();
                xxx.ForEach(x => exists.Add(x.URL.Split('/')[4].ToInt()));

                foreach (var z in result)
                {
                    var nn = z.URL.Split('/')[4].ToInt();

                    if (!exists.Contains(nn))
                    {
                        xxx.Add(z);
                    }
                }

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

                Logs.Instance.Push("Write file: ex-hentai-archive.json");
                using (StreamWriter sw = new StreamWriter("ex-hentai-archive.json"))
                    using (JsonWriter writer = new JsonTextWriter(sw))
                    {
                        serializer.Serialize(writer, xxx);
                    }
            }
//#endif
//#endif

//#if false
            // Make DataBase
            {
                HitomiData.Instance.metadata_collection.Clear();
                HitomiData.Instance.Load();
                var xxx = JsonConvert.DeserializeObject <List <EHentaiResultArticle> >(File.ReadAllText("ex-hentai-archive.json"));

                Console.Write("Make database... ");
                var dict = new Dictionary <string, int>();

                for (int i = 0; i < xxx.Count; i++)
                {
                    if (!dict.ContainsKey(xxx[i].URL.Split('/')[4]))
                    {
                        dict.Add(xxx[i].URL.Split('/')[4], i);
                    }
                }

                {
                    var db   = new SQLiteConnection("hitomidata.db");
                    var info = db.GetTableInfo(typeof(HitomiColumnModel).Name);
                    if (!info.Any())
                    {
                        db.CreateTable <HitomiColumnModel>();
                    }
                    db.InsertAll(HitomiData.Instance.metadata_collection.Select(md =>
                    {
                        var dd = new HitomiColumnModel
                        {
                            Id         = md.ID,
                            Artists    = (md.Artists != null && md.Artists.Length > 0 && md.Artists[0] != "" ? "|" + string.Join("|", md.Artists) + "|" : "N/A|"),
                            Characters = (md.Characters != null && md.Characters.Length > 0 && md.Characters[0] != "" ? "|" + string.Join("|", md.Characters) + "|" : null),
                            Groups     = (md.Groups != null && md.Groups.Length > 0 && md.Groups[0] != "" ? "|" + string.Join("|", md.Groups) + "|" : null),
                            Series     = (md.Parodies != null && md.Parodies.Length > 0 && md.Parodies[0] != "" ? "|" + string.Join("|", md.Parodies) + "|" : null),
                            Title      = md.Name,
                            Tags       = (md.Tags != null && md.Tags.Length > 0 && md.Tags[0] != "" ? "|" + string.Join("|", md.Tags) + "|" : null),
                            Type       = md.Type,
                            Language   = md.Language,
                        };

                        if (dict.ContainsKey(md.ID.ToString()))
                        {
                            var ii       = xxx[dict[md.ID.ToString()]];
                            dd.Uploader  = ii.Uploader;
                            dd.Published = DateTime.Parse(ii.Published);
                            dd.EHash     = ii.URL.Split('/')[5];
                            dd.Files     = ii.Files.Split(' ')[0].ToInt();
                            if (ii.Title.StartsWith("("))
                            {
                                dd.Class = ii.Title.Split("(")[1].Split(")")[0];
                            }
                        }

                        return(dd);
                    }));
                    db.Close();
                }

                Console.WriteLine("Complete-All");

                {
                    var db   = new SQLiteConnection("hitomidata-korean.db");
                    var info = db.GetTableInfo(typeof(HitomiColumnModel).Name);
                    if (!info.Any())
                    {
                        db.CreateTable <HitomiColumnModel>();
                    }
                    db.InsertAll(HitomiData.Instance.metadata_collection.Where(md => md.Language == null || md.Language == "" || md.Language == "korean").Select(md =>
                    {
                        var dd = new HitomiColumnModel
                        {
                            Id         = md.ID,
                            Artists    = (md.Artists != null && md.Artists.Length > 0 && md.Artists[0] != "" ? "|" + string.Join("|", md.Artists) + "|" : "N/A|"),
                            Characters = (md.Characters != null && md.Characters.Length > 0 && md.Characters[0] != "" ? "|" + string.Join("|", md.Characters) + "|" : null),
                            Groups     = (md.Groups != null && md.Groups.Length > 0 && md.Groups[0] != "" ? "|" + string.Join("|", md.Groups) + "|" : null),
                            Series     = (md.Parodies != null && md.Parodies.Length > 0 && md.Parodies[0] != "" ? "|" + string.Join("|", md.Parodies) + "|" : null),
                            Title      = md.Name,
                            Tags       = (md.Tags != null && md.Tags.Length > 0 && md.Tags[0] != "" ? "|" + string.Join("|", md.Tags) + "|" : null),
                            Type       = md.Type,
                            Language   = md.Language,
                        };

                        if (dict.ContainsKey(md.ID.ToString()))
                        {
                            var ii       = xxx[dict[md.ID.ToString()]];
                            dd.Uploader  = ii.Uploader;
                            dd.Published = DateTime.Parse(ii.Published);
                            dd.EHash     = ii.URL.Split('/')[5];
                            dd.Files     = ii.Files.Split(' ')[0].ToInt();
                            if (ii.Title.StartsWith("("))
                            {
                                dd.Class = ii.Title.Split("(")[1].Split(")")[0];
                            }
                        }

                        return(dd);
                    }));
                    db.Close();
                }

                Console.WriteLine("Complete-Korean");

                {
                    var db   = new SQLiteConnection("hitomidata-japanese.db");
                    var info = db.GetTableInfo(typeof(HitomiColumnModel).Name);
                    if (!info.Any())
                    {
                        db.CreateTable <HitomiColumnModel>();
                    }
                    db.InsertAll(HitomiData.Instance.metadata_collection.Where(md => md.Language == null || md.Language == "" || md.Language == "japanese").Select(md =>
                    {
                        var dd = new HitomiColumnModel
                        {
                            Id         = md.ID,
                            Artists    = (md.Artists != null && md.Artists.Length > 0 && md.Artists[0] != "" ? "|" + string.Join("|", md.Artists) + "|" : "N/A|"),
                            Characters = (md.Characters != null && md.Characters.Length > 0 && md.Characters[0] != "" ? "|" + string.Join("|", md.Characters) + "|" : null),
                            Groups     = (md.Groups != null && md.Groups.Length > 0 && md.Groups[0] != "" ? "|" + string.Join("|", md.Groups) + "|" : null),
                            Series     = (md.Parodies != null && md.Parodies.Length > 0 && md.Parodies[0] != "" ? "|" + string.Join("|", md.Parodies) + "|" : null),
                            Title      = md.Name,
                            Tags       = (md.Tags != null && md.Tags.Length > 0 && md.Tags[0] != "" ? "|" + string.Join("|", md.Tags) + "|" : null),
                            Type       = md.Type,
                            Language   = md.Language,
                        };

                        if (dict.ContainsKey(md.ID.ToString()))
                        {
                            var ii       = xxx[dict[md.ID.ToString()]];
                            dd.Uploader  = ii.Uploader;
                            dd.Published = DateTime.Parse(ii.Published);
                            dd.EHash     = ii.URL.Split('/')[5];
                            dd.Files     = ii.Files.Split(' ')[0].ToInt();
                            if (ii.Title.StartsWith("("))
                            {
                                dd.Class = ii.Title.Split("(")[1].Split(")")[0];
                            }
                        }

                        return(dd);
                    }));
                    db.Close();
                }

                Console.WriteLine("Complete-Japanese");

                {
                    var db   = new SQLiteConnection("hitomidata-english.db");
                    var info = db.GetTableInfo(typeof(HitomiColumnModel).Name);
                    if (!info.Any())
                    {
                        db.CreateTable <HitomiColumnModel>();
                    }
                    db.InsertAll(HitomiData.Instance.metadata_collection.Where(md => md.Language == null || md.Language == "" || md.Language == "english").Select(md =>
                    {
                        var dd = new HitomiColumnModel
                        {
                            Id         = md.ID,
                            Artists    = (md.Artists != null && md.Artists.Length > 0 && md.Artists[0] != "" ? "|" + string.Join("|", md.Artists) + "|" : "N/A|"),
                            Characters = (md.Characters != null && md.Characters.Length > 0 && md.Characters[0] != "" ? "|" + string.Join("|", md.Characters) + "|" : null),
                            Groups     = (md.Groups != null && md.Groups.Length > 0 && md.Groups[0] != "" ? "|" + string.Join("|", md.Groups) + "|" : null),
                            Series     = (md.Parodies != null && md.Parodies.Length > 0 && md.Parodies[0] != "" ? "|" + string.Join("|", md.Parodies) + "|" : null),
                            Title      = md.Name,
                            Tags       = (md.Tags != null && md.Tags.Length > 0 && md.Tags[0] != "" ? "|" + string.Join("|", md.Tags) + "|" : null),
                            Type       = md.Type,
                            Language   = md.Language,
                        };

                        if (dict.ContainsKey(md.ID.ToString()))
                        {
                            var ii       = xxx[dict[md.ID.ToString()]];
                            dd.Uploader  = ii.Uploader;
                            dd.Published = DateTime.Parse(ii.Published);
                            dd.EHash     = ii.URL.Split('/')[5];
                            dd.Files     = ii.Files.Split(' ')[0].ToInt();
                            if (ii.Title.StartsWith("("))
                            {
                                dd.Class = ii.Title.Split("(")[1].Split(")")[0];
                            }
                        }

                        return(dd);
                    }));
                    db.Close();
                }

                Console.WriteLine("Complete-English");

                {
                    var db   = new SQLiteConnection("hitomidata-chinese.db");
                    var info = db.GetTableInfo(typeof(HitomiColumnModel).Name);
                    if (!info.Any())
                    {
                        db.CreateTable <HitomiColumnModel>();
                    }
                    db.InsertAll(HitomiData.Instance.metadata_collection.Where(md => md.Language == null || md.Language == "" || md.Language == "chinese").Select(md =>
                    {
                        var dd = new HitomiColumnModel
                        {
                            Id         = md.ID,
                            Artists    = (md.Artists != null && md.Artists.Length > 0 && md.Artists[0] != "" ? "|" + string.Join("|", md.Artists) + "|" : "N/A|"),
                            Characters = (md.Characters != null && md.Characters.Length > 0 && md.Characters[0] != "" ? "|" + string.Join("|", md.Characters) + "|" : null),
                            Groups     = (md.Groups != null && md.Groups.Length > 0 && md.Groups[0] != "" ? "|" + string.Join("|", md.Groups) + "|" : null),
                            Series     = (md.Parodies != null && md.Parodies.Length > 0 && md.Parodies[0] != "" ? "|" + string.Join("|", md.Parodies) + "|" : null),
                            Title      = md.Name,
                            Tags       = (md.Tags != null && md.Tags.Length > 0 && md.Tags[0] != "" ? "|" + string.Join("|", md.Tags) + "|" : null),
                            Type       = md.Type,
                            Language   = md.Language,
                        };

                        if (dict.ContainsKey(md.ID.ToString()))
                        {
                            var ii       = xxx[dict[md.ID.ToString()]];
                            dd.Uploader  = ii.Uploader;
                            dd.Published = DateTime.Parse(ii.Published);
                            dd.EHash     = ii.URL.Split('/')[5];
                            dd.Files     = ii.Files.Split(' ')[0].ToInt();
                            if (ii.Title.StartsWith("("))
                            {
                                dd.Class = ii.Title.Split("(")[1].Split(")")[0];
                            }
                        }

                        return(dd);
                    }));
                    db.Close();
                }

                Console.WriteLine("Complete-Chinese");
            }
//#endif
        }
Ejemplo n.º 20
0
        public void SyncHitomi()
        {
            var gburls = Enumerable.Range(useManualRange ? starts : latestId - hitomiSyncRange, useManualRange ? ends - starts + 1 : hitomiSyncRange * 2)
                         .Where(x => !existsHitomi.Contains(x)).Select(x => $"https://ltn.hitomi.la/galleryblock/{x}.html").ToList();
            var dcnt = 0;
            var ecnt = 0;

            Console.Write("Running galleryblock tester... ");
            List <string> htmls;

            using (var pb = new ProgressBar())
            {
                htmls = NetTools.DownloadStrings(gburls, "",
                                                 () =>
                {
                    pb.Report(gburls.Count, Interlocked.Increment(ref dcnt), ecnt);
                },
                                                 () =>
                {
                    pb.Report(gburls.Count, dcnt, Interlocked.Increment(ref ecnt));
                }).Result;
            }
            Console.WriteLine("Complete");

            var gurls = new List <string>(gburls.Count);

            for (int i = 0; i < gburls.Count; i++)
            {
                if (htmls[i] == null)
                {
                    continue;
                }
                var aa = HitomiParser.ParseGalleryBlock(htmls[i]);
                if (aa.Magic.Contains("-"))
                {
                    gurls.Add("https://hitomi.la/" + aa.Magic);
                }
                else
                {
                    gurls.Add("https://hitomi.la/galleries/" + i + ".html");
                }
            }

            dcnt = 0;
            ecnt = 0;
            Console.Write("Running gallery tester... ");
            List <string> htmls2 = null;

            if (gurls.Count != 0)
            {
                using (var pb = new ProgressBar())
                {
                    htmls2 = NetTools.DownloadStrings(gurls, "",
                                                      () =>
                    {
                        pb.Report(gburls.Count, Interlocked.Increment(ref dcnt), ecnt);
                    },
                                                      () =>
                    {
                        pb.Report(gburls.Count, dcnt, Interlocked.Increment(ref ecnt));
                    }).Result;
                }
            }
            Console.WriteLine("Complete");

            hitomiArticles = new List <HitomiArticle>();
            for (int i = 0, j = 0; i < gburls.Count; i++)
            {
                if (htmls[i] == null)
                {
                    continue;
                }
                var aa = HitomiParser.ParseGalleryBlock(htmls[i]);
                if (htmls2[j] != null)
                {
                    var node  = htmls2[j].ToHtmlNode();
                    var title = node.SelectSingleNode("//title");
                    if (!(title != null && title.InnerText == "Redirect"))
                    {
                        var ab = HitomiParser.ParseGallery(htmls2[j]);
                        aa.Groups     = ab.Groups;
                        aa.Characters = ab.Characters;
                    }
                }
                try
                {
                    if (aa.Magic.Contains("-"))
                    {
                        newedDataHitomi.Add(Convert.ToInt32(aa.Magic.Split('-').Last().Split('.')[0]));
                    }
                    else if (aa.Magic.Contains("galleries"))
                    {
                        newedDataHitomi.Add(Convert.ToInt32(aa.Magic.Split('/').Last().Split('.')[0]));
                    }
                    else
                    {
                        newedDataHitomi.Add(Convert.ToInt32(aa.Magic));
                    }
                }
                catch
                {
                    ;
                }
                hitomiArticles.Add(aa);
                j++;
            }
        }
Ejemplo n.º 21
0
        public static void ProcessHiyobi(string url, bool unstable = false)
        {
            Task.Run(() =>
            {
                if (url.StartsWith("https://hiyobi.me/manga/info/"))
                {
                    MainWindow.Instance.Fade_MiddlePopup(true, "접속중...");
                    var html     = NetCommon.DownloadString(url);
                    var articles = HiyobiParser.ParseNonHArticles(html);
                    var title    = HiyobiParser.ParseNonHTitle(html);

                    MainWindow.Instance.ModifyText_MiddlePopup($"가져오는중...[0/{articles.Count}]");
                    for (int i = 0; i < articles.Count; i++)
                    {
                        articles[i].ImagesLink = HitomiParser.GetImageLink(NetCommon.DownloadString(HiyobiCommon.GetDownloadMangaImageAddress(articles[i].Magic)));
                        MainWindow.Instance.ModifyText_MiddlePopup($"가져오는중...[{i + 1}/{articles.Count}]");
                    }

                    int count = 0;
                    foreach (var article in articles)
                    {
                        string dir = Path.Combine(Path.Combine(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "hiyobi"), DeleteInvalid(title)), DeleteInvalid(article.Title));
                        Directory.CreateDirectory(dir);

                        var se     = Koromo_Copy.Interface.SemaphoreExtends.MakeDefault();
                        se.Referer = url;

                        count += article.ImagesLink.Count;
                        DownloadSpace.Instance.RequestDownload($"hiyobi-nonh: {article.Title}",
                                                               article.ImagesLink.Select(x => x.StartsWith("http://") || x.StartsWith("https://") ? x : $"https://aa.hiyobi.me/data_m/{article.Magic}/{x}").ToArray(),
                                                               article.ImagesLink.Select(x => Path.Combine(dir, !x.StartsWith("http://images-blogger-opensocial.googleusercontent.com/") ?
                                                                                                           HttpUtility.UrlDecode(HttpUtility.UrlDecode(x.Split('/').Last())) :
                                                                                                           HttpUtility.UrlDecode(HttpUtility.UrlDecode(HttpUtility.ParseQueryString(new Uri(x).Query).Get("url").Split('/').Last())))).ToArray(),
                                                               se,
                                                               dir + '\\',
                                                               null
                                                               );
                    }

                    MainWindow.Instance.FadeOut_MiddlePopup($"{count}개({articles.Count} 작품) 항목 다운로드 시작...");
                }
                else if (url.StartsWith("https://hiyobi.me/info/"))
                {
                    if (unstable)
                    {
                        MainWindow.Instance.Fade_MiddlePopup(true, $"불안정한 작업 진행중...[{unstable_request}개]");
                    }
                    else
                    {
                        MainWindow.Instance.Fade_MiddlePopup(true, "접속중...");
                    }
                    var imagelink      = HitomiParser.GetImageLink(NetCommon.DownloadString(HiyobiCommon.GetDownloadImageAddress(url.Split('/').Last())));
                    var article        = HiyobiParser.ParseGalleryConents(NetCommon.DownloadString(url));
                    string dir         = HitomiCommon.MakeDownloadDirectory(article);
                    article.ImagesLink = imagelink;
                    Directory.CreateDirectory(dir);
                    DownloadSpace.Instance.RequestDownload(article.Title,
                                                           imagelink.Select(y => HitomiCommon.GetDownloadImageAddress(article.Magic, y)).ToArray(),
                                                           imagelink.Select(y => Path.Combine(dir, y)).ToArray(),
                                                           Koromo_Copy.Interface.SemaphoreExtends.Default, dir, article);
                    Directory.CreateDirectory(dir);
                    if (unstable)
                    {
                        Interlocked.Decrement(ref unstable_request);
                    }
                    if (unstable && unstable_request != 0)
                    {
                        MainWindow.Instance.Fade_MiddlePopup(true, $"불안정한 작업 진행중...[{unstable_request}개]");
                    }
                    else
                    {
                        MainWindow.Instance.FadeOut_MiddlePopup($"{imagelink.Count}개 이미지 다운로드 시작...");
                    }
                }
            });
        }
Ejemplo n.º 22
0
 private void SearchElements_Loaded(object sender, EventArgs ex)
 {
     if (init)
     {
         return;
     }
     init = true;
     Task.Run(() =>
     {
         HitomiArticle ha = Article as HitomiArticle;
         try
         {
             ha.Thumbnail = HitomiCommon.HitomiThumbnail + HitomiParser.ParseGalleryBlock(Koromo_Copy.Net.NetCommon.DownloadString(
                                                                                              $"{HitomiCommon.HitomiGalleryBlock}{ha.Magic}.html")).Thumbnail;
             var info      = Koromo_Copy.Net.NetCommon.DownloadString(HitomiCommon.GetImagesLinkAddress(ha.Magic));
             ha.ImagesLink = HitomiParser.GetImageLink(info);
             ha.HasWebp    = HitomiParser.CheckHasWebp(info);
             ha.Hashs      = HitomiParser.GetHash(info);
         }
         catch
         {
             ha.IsUnstable = true;
             var har       = HCommander.GetArticleData(Convert.ToInt32(ha.Magic));
             if (!har.HasValue)
             {
                 Koromo_Copy.Console.Console.Instance.WriteErrorLine($"Cannot find '{ha.Magic}'! This item was not found in Hiyobi, Ex-Hentai, and Hitomi. Contact to the developer.\r\n" +
                                                                     "Run program as an administrator, or use a DPI program or VPN.");
                 return;
             }
             ha.UnstableModel = har.Value;
             ha.Thumbnail     = ha.UnstableModel.Thumbnail;
             ha.ImagesLink    = new List <string>();
         }
         Application.Current.Dispatcher.BeginInvoke(new Action(
                                                        delegate
         {
             try
             {
                 if (ha.IsUnstable && ha.UnstableModel.ArticleType == HArticleType.EXHentai)
                 {
                     var image = NetCommon.GetExHentaiClient().DownloadData(new Uri(ha.UnstableModel.Thumbnail));
                     using (var ms = new System.IO.MemoryStream(image))
                     {
                         BitmapImage.BeginInit();
                         if (Settings.Instance.Model.LowQualityImage)
                         {
                             BitmapImage.DecodePixelWidth = 100;
                         }
                         BitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
                         BitmapImage.StreamSource = ms;
                         BitmapImage.EndInit();
                     }
                 }
                 else
                 {
                     BitmapImage.BeginInit();
                     BitmapImage.UriSource = new Uri(ha.Thumbnail);
                     if (Settings.Instance.Model.LowQualityImage)
                     {
                         BitmapImage.DecodePixelWidth = 100;
                     }
                     BitmapImage.EndInit();
                     BitmapImage.DownloadCompleted += B_DownloadCompleted;
                 }
                 if (!ha.IsUnstable)
                 {
                     Page.Text = ha.ImagesLink.Count + " Pages";
                 }
                 else
                 {
                     Page.Text = ha.UnstableModel.Length + " Pages";
                 }
                 Image.Source  = BitmapImage;
                 Image.Stretch = Stretch.Uniform;
                 Image.Width   = BitmapImage.Width * 200 / BitmapImage.Height;
             }
             catch (Exception e)
             {
                 Monitor.Instance.Push($"[Search Elements] isunstable={ha.IsUnstable} article_type={ha.UnstableModel}" +
                                       $" thumbnail={(ha.UnstableModel.Thumbnail ?? ha.Thumbnail)}" +
                                       $"\r\n{e.Message}\r\n{e.StackTrace}");
             }
         }));
     });
 }
Ejemplo n.º 23
0
        private void ZipViewerElements_Loaded(object sender, RoutedEventArgs e)
        {
            if (loaded)
            {
                return;
            }
            loaded = true;
            if (offline_mode == false && !File.Exists(zip_file_name))
            {
                Title.Text  = $"파일을 찾을 수 없음";
                Artist.Text = zip_file_name;
                return;
            }
            set_rateeffect();
            Task.Run(() =>
            {
                try
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(
                                                                   delegate
                    {
                        Title.Text      = model.Title;
                        Artist.Text     = model.Artists != null ? model.Artists[0] : "";
                        ImageCount.Text = $"{model.Pages} Pages";

                        bool seperator = false;
                        if (model.Artists != null)
                        {
                            var stack = new StackPanel {
                                Orientation = Orientation.Horizontal
                            };
                            stack.Children.Add(new PackIcon {
                                Kind = PackIconKind.Artist, Opacity = .56
                            });
                            stack.Children.Add(new TextBlock {
                                Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center, Text = "작가 목록"
                            });
                            var menu_item = new MenuItem {
                                Header = stack
                            };
                            foreach (var artist in model.Artists)
                            {
                                var item = new MenuItem {
                                    Header = new TextBlock {
                                        Text = artist
                                    }, Tag = $"artist:{artist.Replace(' ', '_')}"
                                };
                                item.Click += subitem_click;
                                menu_item.Items.Add(item);
                            }
                            seperator = true;
                            Menu.Items.Add(new Separator {
                                Margin = new Thickness(4, 0, 4, 0), Background = Brushes.Gray
                            });
                            Menu.Items.Add(menu_item);
                        }
                        if (model.Groups != null)
                        {
                            var stack = new StackPanel {
                                Orientation = Orientation.Horizontal
                            };
                            stack.Children.Add(new PackIcon {
                                Kind = PackIconKind.UserGroup, Opacity = .56
                            });
                            stack.Children.Add(new TextBlock {
                                Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center, Text = "그룹 목록"
                            });
                            var menu_item = new MenuItem {
                                Header = stack
                            };
                            foreach (var group in model.Groups)
                            {
                                var item = new MenuItem {
                                    Header = new TextBlock {
                                        Text = group
                                    }, Tag = $"group:{group.Replace(' ', '_')}"
                                };
                                item.Click += subitem_click;
                                menu_item.Items.Add(item);
                            }
                            if (!seperator)
                            {
                                seperator = true;
                                Menu.Items.Add(new Separator {
                                    Margin = new Thickness(8, 0, 8, 0), Background = Brushes.Gray
                                });
                            }
                            Menu.Items.Add(menu_item);
                        }
                        if (model.Series != null)
                        {
                            var stack = new StackPanel {
                                Orientation = Orientation.Horizontal
                            };
                            stack.Children.Add(new PackIcon {
                                Kind = PackIconKind.Book, Opacity = .56
                            });
                            stack.Children.Add(new TextBlock {
                                Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center, Text = "시리즈 목록"
                            });
                            var menu_item = new MenuItem {
                                Header = stack
                            };
                            foreach (var series in model.Series)
                            {
                                MenuItem item = null;
                                if (KoreanSeries.SeriesMap(series) == series)
                                {
                                    item = new MenuItem {
                                        Header = new TextBlock {
                                            Text = series
                                        }, Tag = $"series:{series.Replace(' ', '_')}"
                                    }
                                }
                                ;
                                else
                                {
                                    item = new MenuItem {
                                        Header = new TextBlock {
                                            Text = $"{series} ({KoreanSeries.SeriesMap(series)})"
                                        }, Tag = $"series:{series.Replace(' ', '_')}"
                                    }
                                };
                                item.Click += subitem_click;
                                menu_item.Items.Add(item);
                            }
                            if (!seperator)
                            {
                                seperator = true;
                                Menu.Items.Add(new Separator {
                                    Margin = new Thickness(8, 0, 8, 0), Background = Brushes.Gray
                                });
                            }
                            Menu.Items.Add(menu_item);
                        }
                        if (model.Tags != null)
                        {
                            var stack = new StackPanel {
                                Orientation = Orientation.Horizontal
                            };
                            stack.Children.Add(new PackIcon {
                                Kind = PackIconKind.Tag, Opacity = .56
                            });
                            stack.Children.Add(new TextBlock {
                                Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center, Text = "태그 목록"
                            });
                            var menu_item = new MenuItem {
                                Header = stack
                            };
                            foreach (var tag in model.Tags)
                            {
                                MenuItem item = null;
                                if (KoreanTag.TagMap(tag) == tag)
                                {
                                    item = new MenuItem {
                                        Header = new TextBlock {
                                            Text = tag
                                        }, Tag = $"{(tag.StartsWith("female:") || tag.StartsWith("male:") ? tag.Replace(' ', '_') : $"tag:{tag.Replace(' ', '_')}")}"
                                    }
                                }
                                ;
                                else if (KoreanTag.TagMap(tag).Contains(':'))
                                {
                                    item = new MenuItem {
                                        Header = new TextBlock {
                                            Text = $"{tag} ({KoreanTag.TagMap(tag).Split(':')[1]})"
                                        }, Tag = $"{(tag.StartsWith("female:") || tag.StartsWith("male:") ? tag.Replace(' ', '_') : $"tag:{tag.Replace(' ', '_')}")}"
                                    }
                                }
                                ;
                                else
                                {
                                    item = new MenuItem {
                                        Header = new TextBlock {
                                            Text = $"{tag} ({KoreanTag.TagMap(tag)})"
                                        }, Tag = $"{(tag.StartsWith("female:") || tag.StartsWith("male:") ? tag.Replace(' ', '_') : $"tag:{tag.Replace(' ', '_')}")}"
                                    }
                                };
                                item.Click += subitem_click;
                                menu_item.Items.Add(item);
                            }
                            if (!seperator)
                            {
                                seperator = true;
                                Menu.Items.Add(new Separator {
                                    Margin = new Thickness(8, 0, 8, 0), Background = Brushes.Gray
                                });
                            }
                            Menu.Items.Add(menu_item);
                        }
                    }));

                    if (offline_mode == false)
                    {
                        zipFile      = ZipFile.Open(zip_file_name, ZipArchiveMode.Read);
                        var zipEntry = !zipFile.Entries[0].Name.EndsWith(".json") ? zipFile.Entries[0] : zipFile.Entries[1];
                        zipStream    = zipEntry.Open();

                        Application.Current.Dispatcher.BeginInvoke(new Action(
                                                                       delegate
                        {
                            var bitmap = new BitmapImage();
                            bitmap.BeginInit();
                            bitmap.DecodePixelWidth = 250;
                            bitmap.CacheOption      = BitmapCacheOption.OnLoad;
                            bitmap.StreamSource     = zipStream;
                            bitmap.EndInit();
                            bitmap.DownloadCompleted += Bitmap_DownloadCompleted;

                            Image.Source = bitmap;
                        }));
                    }
                    else if (download_thumbnail)
                    {
                        var thumbnail = HitomiCommon.HitomiThumbnail + HitomiParser.ParseGalleryBlock(Koromo_Copy.Net.NetCommon.DownloadString(
                                                                                                          $"{HitomiCommon.HitomiGalleryBlock}{model.Id}.html")).Thumbnail;
                        Application.Current.Dispatcher.BeginInvoke(new Action(
                                                                       delegate
                        {
                            var bitmap = new BitmapImage();
                            bitmap.BeginInit();
                            bitmap.UriSource        = new Uri(thumbnail);
                            bitmap.DecodePixelWidth = 240;
                            bitmap.CacheOption      = BitmapCacheOption.OnLoad;
                            bitmap.EndInit();
                            //bitmap.DownloadCompleted += Bitmap_DownloadCompleted;
                            Image.Source = bitmap;
                        }));
                    }
                }
                catch (Exception ex)
                {
                    Monitor.Instance.Push(ex.Message);
                    Monitor.Instance.Push(ex.StackTrace);
                }
            });
Ejemplo n.º 24
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (!Addr.Text.EndsWith(".txt"))
            {
                PB.IsIndeterminate = true;
                FileIndexor fi = new FileIndexor();
                await fi.ListingDirectoryAsync(Addr.Text);

                PB.IsIndeterminate = false;

                file_list = new List <string>();
                fi.Enumerate((string path, List <FileInfo> files) =>
                {
                    foreach (var iz in files)
                    {
                        if (Path.GetExtension(iz.Name) == ".zip")
                        {
                            file_list.Add(iz.FullName);
                        }
                    }
                });

                append(file_list.Count.ToString("#,#") + "개의 Zip 파일이 검색됨");
            }
            else
            {
                var lls = File.ReadAllLines(Addr.Text);

                var pp = new List <Tuple <string, string> >();

                var rx = new Regex(@"^\[(\d+)\]");
                foreach (var article in lls)
                {
                    var f = Path.GetFileNameWithoutExtension(article);
                    if (rx.Match(Path.GetFileNameWithoutExtension(article)).Success)
                    {
                        var id     = rx.Match(System.IO.Path.GetFileNameWithoutExtension(article)).Groups[1].Value;
                        var artist = Path.GetFileName(Path.GetDirectoryName(article));

                        pp.Add(new Tuple <string, string>(id, artist));
                    }
                    else
                    {
                        append("[NO MATCH] " + article);
                    }
                }

                var articles = new List <HitomiArticle>();

                foreach (var p in pp)
                {
                    var aaa = HitomiLegalize.GetMetadataFromMagic(p.Item1);

                    if (!aaa.HasValue)
                    {
                        append("[NOT FOUND] " + p.Item1);
                        continue;
                    }

                    var xxx = HitomiLegalize.MetadataToArticle(aaa.Value);
                    xxx.Artists = new string[] { p.Item2 };
                    articles.Add(xxx);
                }

                await Task.Run(() =>
                {
                    int cnt = 0;
                    foreach (var at in articles)
                    {
                        try
                        {
                            var url       = HitomiCommon.GetImagesLinkAddress(at.Magic);
                            var imgs      = HitomiParser.GetImageLink(NetCommon.DownloadString(url));
                            at.ImagesLink = imgs;
                        }
                        catch
                        {
                            append("[FAIL DOWNLOAD] " + at.Magic);
                        }

                        cnt++;

                        Application.Current.Dispatcher.BeginInvoke(new Action(
                                                                       delegate
                        {
                            PB.Value = cnt / (double)articles.Count * 100;
                        }));
                    }

                    int count = 0;

                    foreach (var ha in articles)
                    {
                        if (ha.ImagesLink == null)
                        {
                            continue;
                        }
                        var prefix = HitomiCommon.MakeDownloadDirectory(ha);
                        Directory.CreateDirectory(prefix);
                        DownloadSpace.Instance.RequestDownload(ha.Title,
                                                               ha.ImagesLink.Select(y => HitomiCommon.GetDownloadImageAddress(ha.Magic, y, ha.HasWebp[y], ha.HasWebp[y] || ha.Hashs[y].Length > 3 ? ha.Hashs[y] : "")).ToArray(),
                                                               ha.ImagesLink.Select(y => Path.Combine(prefix, y)).ToArray(),
                                                               Koromo_Copy.Interface.SemaphoreExtends.Default, prefix, ha);
                        count++;
                    }

                    Application.Current.Dispatcher.BeginInvoke(new Action(
                                                                   delegate
                    {
                        if (count > 0)
                        {
                            MainWindow.Instance.FadeOut_MiddlePopup($"{count}{FindResource("msg_download_start")}");
                        }
                        MainWindow.Instance.Activate();
                        MainWindow.Instance.FocusDownload();
                    }));
                });
            }
        }
Ejemplo n.º 25
0
 private void SearchElements_Loaded(object sender, EventArgs ex)
 {
     if (init)
     {
         return;
     }
     init = true;
     Task.Run(() =>
     {
         HitomiArticle ha = Article as HitomiArticle;
         try
         {
             ha.Thumbnail = HitomiCommon.HitomiThumbnail + HitomiParser.ParseGalleryBlock(Koromo_Copy.Net.NetCommon.DownloadString(
                                                                                              $"{HitomiCommon.HitomiGalleryBlock}{ha.Magic}.html")).Thumbnail;
             ha.ImagesLink = HitomiParser.GetImageLink(Koromo_Copy.Net.NetCommon.DownloadString(HitomiCommon.GetImagesLinkAddress(ha.Magic)));
         }
         catch
         {
             ha.IsUnstable = true;
             var har       = HCommander.GetArticleData(Convert.ToInt32(ha.Magic));
             if (!har.HasValue)
             {
                 MessageBox.Show($"{ha.Magic}를 찾을 수 없습니다. 이 항목은 히요비, 이헨, 익헨 어디에도 없었습니다. 프로그램 제작자에게 문의하세요.", "Koromo copy", MessageBoxButton.OK, MessageBoxImage.Error);
                 return;
             }
             ha.UnstableModel = har.Value;
             ha.Thumbnail     = ha.UnstableModel.Thumbnail;
             ha.ImagesLink    = new List <string>();
         }
         Application.Current.Dispatcher.BeginInvoke(new Action(
                                                        delegate
         {
             if (ha.IsUnstable && ha.UnstableModel.ArticleType == HArticleType.EXHentai)
             {
                 var image = NetCommon.GetExHentaiClient().DownloadData(new Uri(ha.UnstableModel.Thumbnail));
                 using (var ms = new System.IO.MemoryStream(image))
                 {
                     BitmapImage.BeginInit();
                     if (Settings.Instance.Model.LowQualityImage)
                     {
                         BitmapImage.DecodePixelWidth = 100;
                     }
                     BitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
                     BitmapImage.StreamSource = ms;
                     BitmapImage.EndInit();
                 }
             }
             else
             {
                 BitmapImage.BeginInit();
                 BitmapImage.UriSource = new Uri(ha.Thumbnail);
                 if (Settings.Instance.Model.LowQualityImage)
                 {
                     BitmapImage.DecodePixelWidth = 100;
                 }
                 BitmapImage.EndInit();
                 BitmapImage.DownloadCompleted += B_DownloadCompleted;
             }
             Page.Text     = ha.ImagesLink.Count + " Pages";
             Image.Source  = BitmapImage;
             Image.Stretch = Stretch.Uniform;
             Image.Width   = BitmapImage.Width * 200 / BitmapImage.Height;
         }));
     });
 }
Ejemplo n.º 26
0
        /// <summary>
        /// E Hentai Magic Number를 이용해 작품 정보를 가져옵니다.
        /// </summary>
        /// <param name="magic_number"></param>
        /// <returns></returns>
        public static HArticleModel?GetArticleData(int magic_number)
        {
            string magic = magic_number.ToString();

            Monitor.Instance.Push($"[HCommander] [1] {magic}");

            //
            // 1. 히토미 데이터로 찾기
            //
            var search_hitomi = HitomiLegalize.GetMetadataFromMagic(magic);

            if (search_hitomi.HasValue)
            {
                // 히토미 데이터가 존재한다면 데이터의 유효 여부를 판단한다.
                try
                {
                    var url     = $"https://hitomi.la/galleries/{magic}.html";
                    var request = WebRequest.Create(url);
                    using (var response = request.GetResponse())
                    {
                        using (var responseStream = response.GetResponseStream())
                        {
                            // 최종 승인
                            return(ConvertTo(search_hitomi.Value, url, magic));
                        }
                    }
                }
                catch
                {
                }
            }

            Monitor.Instance.Push($"[HCommander] [2] {magic}");

            //
            // 2. Hiyobi를 이용해 탐색한다
            //
            if (search_hitomi.HasValue && search_hitomi.Value.Language == "korean")
            {
                try
                {
                    var html    = NetCommon.DownloadString(HiyobiCommon.GetInfoAddress(magic));
                    var article = HiyobiParser.ParseGalleryConents(html);
                    return(ConvertTo(article, HiyobiCommon.GetInfoAddress(magic), magic));
                }
                catch
                {
                }
            }

            Monitor.Instance.Push($"[HCommander] [3] {magic}");

            //
            // 9.3/4 샰쮘뽣?뛤3쇼뵀?gVA덲탭k융뷠킢쪳1SPS?XF퍵8C샜쁬
            //
            var f = ExHentaiData.data.AsParallel().Where(x => (x >> 40) == magic_number).ToList();

            if (f.Count > 0)
            {
                try
                {
                    //var url = $"https://e-hentai.org/g/{magic}/{f[0] ^ 1L * magic_number << 40:x}/";
                    //var html2 = NetCommon.DownloadExHentaiString(url);
                    //var article = EHentaiParser.ParseArticleData(html2);
                    //return ConvertTo(article, url, magic);
                    throw new Exception();
                }
                catch
                {
                    var url     = $"https://exhentai.org/g/{magic}/{f[0] ^ 1L * magic_number << 40:x}/";
                    var html2   = NetCommon.DownloadExHentaiString(url);
                    var article = ExHentaiParser.ParseArticleData(html2);
                    return(ConvertTo(article, url, magic));
                }
            }

            //
            // 3. GalleryBlock을 이용해 제목을 가져온다.
            //
            string title = "";

            try
            {
                var html    = NetCommon.DownloadString($"{HitomiCommon.HitomiGalleryBlock}{magic}.html");
                var article = HitomiParser.ParseGalleryBlock(html);
                title = article.Title;
            }
            catch
            {
                Monitor.Instance.Push($"[HCommander] [0] {magic}");
                return(null);
            }

            //
            // 4. 'Show Expunged Galleries' 옵션을 이용해 Ex-Hentai에서 검색한 후 정보를 가져온다.
            //
            try
            {
                var html = NetCommon.DownloadExHentaiString($"https://exhentai.org/?f_doujinshi=1&f_manga=1&f_artistcg=1&f_gamecg=1&f_western=1&f_non-h=1&f_imageset=1&f_cosplay=1&f_asianporn=1&f_misc=1&f_search={title}&page=0&f_apply=Apply+Filter&advsearch=1&f_sname=on&f_stags=on&f_sh=on&f_srdd=2");

                if (html.Contains($"/{magic}/"))
                {
                    var url     = Regex.Match(html, $"(https://exhentai.org/g/{magic}/\\w+/)").Value;
                    var html2   = NetCommon.DownloadExHentaiString(url);
                    var article = ExHentaiParser.ParseArticleData(html2);
                    return(ConvertTo(article, url, magic));
                }
            }
            catch
            { }

            Monitor.Instance.Push($"[HCommander] [0] {magic}");
            return(null);
        }