コード例 #1
0
        private void ScreenClicked(object sender, EventArgs e)
        {
            var  ClickPos = ScreenBox.PointToClient(Cursor.Position);
            bool Verify   = VerifyRect.Contains(ClickPos);

            ClickPos = new Point(ClickPos.X + FrameRect.X, ClickPos.Y + FrameRect.Y);
            BrowserHost.ExecuteClick(ClickPos);

            if (Verify)
            {
                LoadingMode(true);
                ThreadTools.Wait(3000, true);
                if (IsCaptchaSolved())
                {
                    Close();
                }
                else
                {
                    UpdateRects();
                    LoadingMode(false);
                }
            }
            else
            {
                StatusCheck.Enabled = false;
                StatusCheck.Enabled = true;
                Clicks++;
            }
        }
コード例 #2
0
ファイル: InfoTools.cs プロジェクト: marcussacana/MangaUnhost
 public static void WaitInitialize(this CefSharp.WinForms.ChromiumWebBrowser Browser)
 {
     while (!Browser.IsBrowserInitialized)
     {
         ThreadTools.Wait(5, true);
     }
 }
コード例 #3
0
        void Initialize()
        {
            Application.DoEvents();
            LoadingMode(true);
            Refresh.Enabled = true;

            if (!v3 || hCaptcha)
            {
                var Thread = new System.Threading.Thread(() =>
                {
                    ResetCaptcha();
                    ThreadTools.Wait(1500);
                    ClickImNotRobot();
                });

                Thread.Start();

                while (Thread.IsRunning())
                {
                    ThreadTools.Wait(5, true);
                }

                UpdateRects();
            }
            else
            {
                Submit();
                UpdateRects();
            }

            LoadingMode(false);
            System.Media.SystemSounds.Beep.Play();
            StatusCheck.Enabled = true;
        }
コード例 #4
0
ファイル: NHentai.cs プロジェクト: marcussacana/MangaUnhost
        public ComicInfo LoadUri(Uri Uri)
        {
            if (Browser == null)
            {
                Browser      = new ChromiumWebBrowser();
                Browser.Size = new System.Drawing.Size(500, 600);
                Browser.ReCaptchaHook();

                while (!Browser.IsBrowserInitialized)
                {
                    ThreadTools.Wait(100, true);
                }

                Login();
                SkipSlowDown();
                SolveCaptcha();
            }

            CurrentUrl = Uri.AbsoluteUri;

            var       Document = DownloadDocument(Uri);
            ComicInfo Info     = new ComicInfo();

            Info.Title = HttpUtility.HtmlDecode(Document.Descendants("title").First().InnerText);
            Info.Title = DataTools.GetRawName(Info.Title).Split('»').First();

            Info.Cover = TryDownload(new Uri(HttpUtility.HtmlDecode(Document
                                                                    .SelectSingleNode("//div[@id=\"cover\"]/a/img")
                                                                    .GetAttributeValue("data-src", ""))));

            Info.ContentType = ContentType.Comic;

            return(Info);
        }
コード例 #5
0
        private void StatusCheckTick(object sender, EventArgs e)
        {
            if (IsCaptchaSolved())
            {
                Close();
                return;
            }
            if (IsCaptchaFailed())
            {
                ResetCaptcha();
                ThreadTools.Wait(500);
                if (Submit != null)
                {
                    Submit();
                    ThreadTools.Wait(500, true);
                }
                Close();
                return;
            }


            if (Clicks > 0)
            {
                Clicks--;

                UpdateRects();
                RefreshTick(null, null);
            }
        }
コード例 #6
0
ファイル: InfoTools.cs プロジェクト: marcussacana/MangaUnhost
 public static void WaitForLoad(this IBrowser Browser)
 {
     ThreadTools.Wait(100);
     while (Browser.IsLoading())
     {
         ThreadTools.Wait(5, true);
     }
 }
コード例 #7
0
 public static void ExecuteMove(this IBrowserHost Browser, List <MimicStep> Steps)
 {
     foreach (var Step in Steps)
     {
         Browser.SendMouseMoveEvent(new MouseEvent(Step.Location.X, Step.Location.Y, CefEventFlags.None), false);
         ThreadTools.Wait(Step.Delay);
     }
 }
コード例 #8
0
ファイル: InfoTools.cs プロジェクト: marcussacana/MangaUnhost
 public static void WaitForLoad(this IFrame Frame)
 {
     ThreadTools.Wait(100);
     while (Frame.IsLoading())
     {
         ThreadTools.Wait(5, true);
     }
 }
コード例 #9
0
ファイル: JSTools.cs プロジェクト: marcussacana/MangaUnhost
        public static CloudflareData BypassCloudflare(this string Url)
        {
            var Status = Main.Status;

            Main.Status = Main.Language.BypassingCloudFlare;

            var Browser = DefaultBrowser.GetBrowser();

            DefaultBrowser.JsDialogHandler = new JsDialogHandler();
            DefaultBrowser.Load(Url);
            Browser.WaitForLoad();

            while (Browser.IsCloudflareTriggered())
            {
                ThreadTools.Wait(100, true);
                Browser.WaitForLoad();
            }

            if (Browser.GetHTML().Contains("why_captcha_headline"))
            {
                while (Browser.IsCloudflareTriggered() || Browser.IsCloudflareAskingCaptcha())
                {
                    if (!DefaultBrowser.ReCaptchaIsSolved())
                    {
                        DefaultBrowser.ReCaptchaTrySolve(Main.Solver);
                        EvaluateScript(Properties.Resources.CloudFlareSubmitCaptcha);
                    }
                    if (!DefaultBrowser.hCaptchaIsSolved())
                    {
                        DefaultBrowser.hCaptchaSolve();
                        ThreadTools.Wait(1000, true);
                    }
                    ThreadTools.Wait(1000, true);
                    Browser.WaitForLoad();
                }
            }

            Browser.WaitForLoad();
            var HTML    = Browser.GetHTML();
            var Cookies = Browser.GetCookies().ToContainer();

            DefaultBrowser.Load("about:blank");

            Main.Status = Status;

            if (Program.Debug)
            {
                Program.Writer?.WriteLine("CF Bypass Result: {0}\r\nHTML: {1}", Browser.MainFrame.Url, HTML);
            }

            return(new CloudflareData()
            {
                Cookies = Cookies,
                UserAgent = Browser.GetUserAgent(),
                HTML = HTML
            });
        }
コード例 #10
0
        public static void ReCaptchaSolveSound(this ChromiumWebBrowser ChromiumBrowser, string Response, Point CursorPos, out Point NewCursorPos)
        {
            var BHost   = ChromiumBrowser.GetBrowserHost();
            var Browser = ChromiumBrowser.GetBrowser();
            var BFrame  = Browser.ReCaptchaGetBFrame();

            NewCursorPos = CursorPos;

            //Get Sound Reponse Textbox Position
            var Result = (string)BFrame.EvaluateScriptAsync(Properties.Resources.reCaptchaGetSoundResponsePosition).GetAwaiter().GetResult().Result;

            if (Result == null)
            {
                return;
            }

            Random Random = new Random();

            int X = int.Parse(DataTools.ReadJson(Result, "x").Split('.', ',')[0]);
            int Y = int.Parse(DataTools.ReadJson(Result, "y").Split('.', ',')[0]);
            //Parse the relative position of the iframe to Window
            Point BFramePos  = Browser.ReCaptchaGetBFramePosition();
            Point RespBoxPos = new Point(X + BFramePos.X + Random.Next(5, 100), Y + BFramePos.Y + Random.Next(5, 15));

            //Create Macro
            var Move = CursorTools.CreateMove(CursorPos, RespBoxPos, 6);

            //Execute Macro
            BHost.ExecuteMove(Move);
            ThreadTools.Wait(Random.Next(999, 1999), true);
            BHost.ExecuteClick(RespBoxPos);

            ThreadTools.Wait(Random.Next(511, 999), true);

            foreach (char Char in Response)
            {
                BHost.SendChar(Char);
            }

            //Get Verify Button Position
            var VerifyBntRect = Browser.ReCaptchaGetVerifyButtonRectangle();

            //Parse the relative position of the iframe to Window
            Point VerifyBntPos = new Point(VerifyBntRect.X + BFramePos.X + Random.Next(5, 40), VerifyBntRect.Y + BFramePos.Y + Random.Next(5, 15));

            //Create and Execute Macro
            Move = CursorTools.CreateMove(RespBoxPos, VerifyBntPos, 6);
            BHost.ExecuteMove(Move);
            ThreadTools.Wait(Random.Next(999, 1999), true);
            BHost.ExecuteClick(VerifyBntPos);

            NewCursorPos = VerifyBntPos;

            ThreadTools.Wait(Random.Next(3599, 4599), true);
        }
コード例 #11
0
ファイル: Tsumino.cs プロジェクト: marcussacana/MangaUnhost
        public IEnumerable <byte[]> DownloadPages(int ID)
        {
            CurrentUrl = LinkMap[ID];
            string Link    = GetNextPage();
            int    Reaming = GetChapterPageCount(ID);

            Browser.Load(Link);
            Browser.WaitForLoad();

            string Last = null;

            do
            {
                Uri PLink = null;
                while (PLink == null)
                {
                    ThreadTools.Wait(100, true);

                    if (!Browser.ReCaptchaIsSolved())
                    {
                        Browser.ReCaptchaTrySolve(Main.Solver);
                        Browser.EvaluateScript("document.getElementsByClassName(\"auth-page\")[0].getElementsByTagName(\"form\")[0].submit();");
                        Browser.WaitForLoad();
                        Cookies = Browser.GetCookies().ToContainer();
                    }

                    if (Browser.Address.Split('#').First() != Link && !Browser.Address.Contains("Read/Auth"))
                    {
                        Browser.Load(Link);
                        Browser.WaitForLoad();
                    }

                    var Document = Browser.GetDocument();
                    var Node     = Document.SelectSingleNode("//img[@class=\"img-responsive reader-img\"]");
                    if (Node == null)
                    {
                        continue;
                    }
                    var HREF = Node.GetAttributeValue("src", null);
                    if (HREF == null || HREF == Last)
                    {
                        continue;
                    }


                    Last  = HREF;
                    PLink = HREF.EnsureAbsoluteUri(Domain);
                }

                Link = GetNextPage(Link);
                Browser.EvaluateScript("gotoNextPage();");
                yield return(TryDownload(PLink));
            } while (--Reaming > 0);
        }
コード例 #12
0
 public static void SendChar(this IBrowserHost Browser, char Char)
 {
     Browser.SendKeyEvent(new KeyEvent()
     {
         FocusOnEditableField = true,
         IsSystemKey          = false,
         Modifiers            = CefEventFlags.None,
         WindowsKeyCode       = Char,
         Type = KeyEventType.Char
     });
     ThreadTools.Wait(random.Next(40, 100));
 }
コード例 #13
0
ファイル: hCaptcha.cs プロジェクト: marcussacana/MangaUnhost
        public static void hCaptchaClickImHuman(this IBrowser Browser, out Point Cursor)
        {
            var Rnd    = new Random();
            var Begin  = new Point(Rnd.Next(5, 25), Rnd.Next(5, 25));
            var Target = Browser.GethCaptchaImHumanButtonPosition();
            var Move   = CursorTools.CreateMove(Begin, Target, MouseSpeed: 10);

            Browser.ExecuteMove(Move);
            ThreadTools.Wait(Rnd.Next(100, 150), true);
            Browser.ExecuteClick(Target);
            ThreadTools.Wait(Rnd.Next(500, 650), true);
            Cursor = Target;
        }
コード例 #14
0
        public static bool ReCaptchaClickImNotRobot(this ChromiumWebBrowser ChromiumBrowser, out Point NewCursorPos)
        {
            var BHost   = ChromiumBrowser.GetBrowserHost();
            var Browser = ChromiumBrowser.GetBrowser();

            Random Random = new Random();

            ThreadTools.Wait(Random.Next(999, 1999), true);

            //Get Recaptcha Position in the page
            var Result = (string)Browser.MainFrame.EvaluateScriptAsync(Properties.Resources.reCaptchaIframeSearch + "\r\n" + Properties.Resources.reCaptchaGetAnchorPosition).GetAwaiter().GetResult().Result;
            int X      = int.Parse(DataTools.ReadJson(Result, "x").Split('.', ',')[0]);
            int Y      = int.Parse(DataTools.ReadJson(Result, "y").Split('.', ',')[0]);
            int Width  = int.Parse(DataTools.ReadJson(Result, "width").Split('.', ',')[0]);
            int Height = int.Parse(DataTools.ReadJson(Result, "height").Split('.', ',')[0]);

            //Create Positions
            Point InitialPos    = new Point(Random.Next(15, 20), Random.Next(25, 30));
            Point CaptchaClick  = new Point(X + Random.Next(15, 20), Y + Random.Next(15, 20));
            var   CaptchaRegion = new Rectangle(X, Y, Width, Height);
            Point PostClick     = new Point(CaptchaRegion.Right + Random.Next(-10, 10), Y + Random.Next(-10, 10));

            //Ensure the fake click don't will click in the "i'm not a robot"
            Point?FakeClick = null;

            while (FakeClick == null || CaptchaRegion.Contains(FakeClick.Value))
            {
                FakeClick = new Point(Random.Next(10, 500), Random.Next(20, 500));
            }

            //Create Macros
            var MoveA = CursorTools.CreateMove(InitialPos, FakeClick.Value);
            var MoveB = CursorTools.CreateMove(FakeClick.Value, CaptchaClick);
            var MoveC = CursorTools.CreateMove(CaptchaClick, PostClick);

            //Execute Macros
            BHost.ExecuteMove(MoveA);
            ThreadTools.Wait(Random.Next(999, 1999), true);
            BHost.ExecuteClick(FakeClick.Value);

            BHost.ExecuteMove(MoveB);
            ThreadTools.Wait(Random.Next(999, 1999), true);
            BHost.ExecuteClick(CaptchaClick);

            BHost.ExecuteMove(MoveC);
            NewCursorPos = PostClick;

            ThreadTools.Wait(Random.Next(3599, 4599), true);

            return(Browser.ReCaptchaIsSolved());
        }
コード例 #15
0
ファイル: NHentai.cs プロジェクト: marcussacana/MangaUnhost
        private void SkipSlowDown()
        {
            Browser.Load(CurrentUrl);
            Browser.GetBrowser().WaitForLoad();

            bool SlowDown = Browser.GetBrowser().GetHTML().Contains("You're loading pages way too quickly");

            if (SlowDown)
            {
                Browser.GetBrowser().EvaluateScript("document.getElementsByClassName(\"button button-wide\")[0].click();");
                ThreadTools.Wait(1000, true);
                Browser.GetBrowser().WaitForLoad();
            }
        }
コード例 #16
0
        private static bool Retry(Action Operation, int Times = 3)
        {
            try
            {
                Operation.Invoke();
                return(true);
            }
            catch
            {
                ThreadTools.Wait(1000, true);
                if (Times >= 0)
                {
                    return(Retry(Operation, Times - 1));
                }

                return(false);
            }
        }
コード例 #17
0
        public static void ReCaptchaClickAudioChallenge(this ChromiumWebBrowser ChromiumBrowser, Point CursorPos, out Point NewCursorPos)
        {
            var BHost   = ChromiumBrowser.GetBrowserHost();
            var Browser = ChromiumBrowser.GetBrowser();
            var BFrame  = Browser.ReCaptchaGetBFrame();

            NewCursorPos = CursorPos;

            if (Browser.ReCaptchaIsFailed())
            {
                return;
            }

            Random Random = new Random();

            //Get Audio Challenge Button Pos
            var Result = (string)BFrame.EvaluateScriptAsync(Properties.Resources.reCaptchaGetSpeakPosition).GetAwaiter().GetResult().Result;
            int X      = int.Parse(DataTools.ReadJson(Result, "x").Split('.', ',')[0]);
            int Y      = int.Parse(DataTools.ReadJson(Result, "y").Split('.', ',')[0]);
            int Width  = int.Parse(DataTools.ReadJson(Result, "width").Split('.', ',')[0]);
            int Height = int.Parse(DataTools.ReadJson(Result, "height").Split('.', ',')[0]);

            Point AudioBntPos = new Point(X + Random.Next(5, Width - 5), Y + Random.Next(5, Height - 5));

            //Parse the relative position of the iframe to Window
            Point BFramePos = Browser.ReCaptchaGetBFramePosition();

            AudioBntPos = new Point(AudioBntPos.X + BFramePos.X, AudioBntPos.Y + BFramePos.Y);

            //Create and Execute the Macro
            var Move = CursorTools.CreateMove(CursorPos, AudioBntPos, 7);

            BHost.ExecuteMove(Move);
            ThreadTools.Wait(Random.Next(999, 1999), true);
            BHost.ExecuteClick(AudioBntPos);

            ThreadTools.Wait(Random.Next(2111, 3599), true);

            NewCursorPos = AudioBntPos;
        }
コード例 #18
0
ファイル: NHentai.cs プロジェクト: marcussacana/MangaUnhost
        private bool SolveCaptcha()
        {
            Browser.Load(CurrentUrl);
            Browser.GetBrowser().WaitForLoad();

            if (!Browser.GetBrowser().GetHTML().Contains("<h1>Really, slow down</h1>"))
            {
                return(false);
            }

            if (Browser.GetBrowser().ReCaptchaIsSolved())
            {
                return(false);
            }

            Browser.ReCaptchaTrySolve(Main.Solver);

            Browser.GetBrowser().EvaluateScript("document.forms[0].submit();");
            ThreadTools.Wait(1000, true);
            Browser.GetBrowser().WaitForLoad();

            return(true);
        }
コード例 #19
0
        /// <summary>
        /// Try Solve the Recaptcha v3
        /// </summary>
        /// <param name="OBrowser">The Browser with the recaptcha</param>
        /// <param name="Submit">A Event that can trigger the recaptcha</param>
        /// <param name="Validate">A Event that can confirm if the captcha is solved</param>
        public static void ReCaptchaTrySolveV3(this ChromiumWebBrowser OBrowser, Action Submit, Func <bool> Validate = null, CaptchaSolverType SolverType = CaptchaSolverType.SemiAuto)
        {
            var Browser = OBrowser.GetBrowser();

            Browser.WaitForLoad();
            Submit();
            ThreadTools.Wait(100, true);
            if (SolverType != CaptchaSolverType.Manual)
            {
                if (!Validate?.Invoke() ?? !Browser.ReCaptchaIsSolved(true))
                {
                    Point Cursor = new Point(0, 0);

                    for (int i = 0; i < 3 && !(Validate?.Invoke() ?? Browser.ReCaptchaIsSolved(true)); i++)
                    {
                        try
                        {
                            OBrowser.ReCaptchaClickAudioChallenge(Cursor, out Cursor);
                            if (Browser.ReCaptchaIsFailed())
                            {
                                Browser.ReCaptchaReset();
                                ThreadTools.Wait(500, true);
                                Submit();
                                if (!Validate?.Invoke() ?? !Browser.ReCaptchaIsSolved(true))
                                {
                                    break;
                                }
                            }
                            var Response = Browser.DecodeAudioChallenge();
                            if (Response == null)
                            {
                                continue;
                            }
                            OBrowser.ReCaptchaSolveSound(Response, Cursor, out Cursor);
                        }
                        catch (Exception ex)
                        {
                            if (!Validate?.Invoke() ?? !Browser.ReCaptchaIsSolved(true))
                            {
                                throw ex;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }

            if (Validate?.Invoke() ?? Browser.ReCaptchaIsSolved(true))
            {
                return;
            }

            do
            {
                using (var Solver = new SolveCaptcha(OBrowser, true, Submit: Submit))
                    Solver.ShowDialog();
            } while (!Validate?.Invoke() ?? !Browser.ReCaptchaIsSolved(true));
        }
コード例 #20
0
 public static void ExecuteClick(this IBrowserHost Browser, Point Position)
 {
     Browser.SendMouseClickEvent(new MouseEvent(Position.X, Position.Y, CefEventFlags.LeftMouseButton), MouseButtonType.Left, false, 1);
     ThreadTools.Wait(random.Next(49, 101));
     Browser.SendMouseClickEvent(new MouseEvent(Position.X, Position.Y, CefEventFlags.LeftMouseButton), MouseButtonType.Left, true, 1);
 }
コード例 #21
0
        private void DownloadChapter(Dictionary <int, string> Chapters, int ID, IHost Host, ComicInfo Info)
        {
            string Name = DataTools.GetRawName(Chapters[ID], FileNameMode: true);

            StatusBar.SecondLabelText = $"{Info.Title} - {string.Format(CurrentLanguage.ChapterName, Name)}";
            Status = CurrentLanguage.Loading;

            int KIndex = Chapters.IndexOfKey(ID);

            string LName          = null;
            string LastChapterPah = null;

            if (KIndex + 1 < Chapters.Keys.Count)
            {
                LName = DataTools.GetRawName(Chapters.Values.ElementAt(KIndex + 1), FileNameMode: true);
            }

            string NName           = null;
            string NextChapterPath = null;

            if (KIndex > 0)
            {
                NName = DataTools.GetRawName(Chapters.Values.ElementAt(KIndex - 1), FileNameMode: true);
            }

            string Title = DataTools.GetRawName(Info.Title.Trim(), FileNameMode: true);

            ChapterTools.MatchLibraryPath(ref Title, Settings.LibraryPath, CurrentInfo.Url, (ReplaceMode)Settings.ReplaceMode, CurrentLanguage);
            RefreshCoverLink(Title);

            string TitleDir = Path.Combine(Settings.LibraryPath, Title);

            if (!Directory.Exists(TitleDir))
            {
                Directory.CreateDirectory(TitleDir);
                RefreshLibrary();
            }

            if (LName != null)
            {
                ChapterTools.GetChapterPath(Languages, CurrentLanguage, TitleDir, LName, out LastChapterPah, false);
            }

            ChapterTools.GetChapterPath(Languages, CurrentLanguage, TitleDir, Name, out string ChapterPath, false);

            if (NName != null)
            {
                ChapterTools.GetChapterPath(Languages, CurrentLanguage, TitleDir, NName, out NextChapterPath, false);
            }

            string AbsoluteChapterPath = Path.Combine(TitleDir, ChapterPath);

            if (Settings.SkipDownloaded && File.Exists(AbsoluteChapterPath.TrimEnd('\\', '/') + ".html"))
            {
                return;
            }

            int PageCount = 1;

            if (Info.ContentType == ContentType.Comic)
            {
                PageCount = Host.GetChapterPageCount(ID);

                if (Directory.Exists(AbsoluteChapterPath) && Directory.GetFiles(AbsoluteChapterPath, "*").Length < PageCount)
                {
                    Directory.Delete(AbsoluteChapterPath, true);
                }

                if (Settings.SkipDownloaded && Directory.Exists(AbsoluteChapterPath))
                {
                    var Pages = (from x in Directory.GetFiles(AbsoluteChapterPath) select Path.GetFileName(x)).ToArray();
                    ChapterTools.GenerateComicReader(CurrentLanguage, Pages, LastChapterPah, NextChapterPath, TitleDir, ChapterPath, Name);
                    string OnlineData = string.Format(Properties.Resources.UrlFile, Info.Url.AbsoluteUri);
                    File.WriteAllText(Path.Combine(TitleDir, "Online.url"), OnlineData);
                    return;
                }
            }

            if (Info.ContentType == ContentType.Novel)
            {
                ChapterPath = Path.Combine(AbsoluteChapterPath, string.Format(CurrentLanguage.ChapterName, Name) + ".epub");
                if (Settings.SkipDownloaded && File.Exists(ChapterPath))
                {
                    return;
                }
            }


            if (!Directory.Exists(AbsoluteChapterPath))
            {
                Directory.CreateDirectory(AbsoluteChapterPath);
            }

            string UrlData = string.Format(Properties.Resources.UrlFile, Info.Url.AbsoluteUri);

            File.WriteAllText(Path.Combine(TitleDir, "Online.url"), UrlData);


            switch (Info.ContentType)
            {
            case ContentType.Comic:
                var           Decoder = Host.GetDecoder();
                List <string> Pages   = new List <string>();
                foreach (var Data in Host.DownloadPages(ID).CatchExceptions())
                {
                    Status = string.Format(CurrentLanguage.Downloading, Pages.Count + 1, PageCount);
                    Application.DoEvents();

                    bool IsWebP = Data.Length > 12 && BitConverter.ToUInt32(Data, 8) == 0x50424557;

                    try
                    {
#if NOASYNCSAVE
                        string PageName = $"{Pages.Count:D3}.png";
                        string PagePath = Path.Combine(TitleDir, ChapterPath, PageName);

                        Page OutPage = new Page();
                        OutPage.Data = Data;

                        if ((SaveAs)Settings.SaveAs != SaveAs.RAW)
                        {
                            using (Bitmap Result = Decoder.Decode(Data))
                            {
                                PageName = $"{Pages.Count:D3}.{GetExtension(Result, out ImageFormat Format)}";
                                PagePath = OutPage.Path = Path.Combine(TitleDir, ChapterPath, PageName);

                                if (Result.GetImageExtension() == "png" && Settings.APNGBypass)
                                {
                                    var OutData = BypassAPNG(Data);
                                    OutPage.Data = OutData;
                                }
                                else
                                {
                                    using (MemoryStream tmp = new MemoryStream())
                                    {
                                        Result.Save(tmp, Format);
                                        OutPage.Data = tmp.ToArray();
                                    }
                                }
                            }
                        }

                        if (Settings.ImageClipping)
                        {
                            PostProcessQueue.Enqueue(OutPage);
                        }
                        else
                        {
                            File.WriteAllBytes(OutPage.Path, OutPage.Data);
                        }

                        while (PostProcessQueue.Count > 0)
                        {
                            ThreadTools.Wait(1000, true);
                        }
#else
                        string PageName = $"{Pages.Count:D3}.{(IsWebP ? "webp" : "png")}";
                        string PagePath = Path.Combine(TitleDir, ChapterPath, PageName);

                        Page OutPage = new Page();
                        OutPage.Data = Data;

                        if ((SaveAs)Settings.SaveAs != SaveAs.RAW)
                        {
                            byte[] ModData = null;

                            if (IsWebP)
                            {
                                ModData = DecodeWebP(Data);
                            }

                            using (MemoryStream Buffer = new MemoryStream())
                                using (Bitmap Result = Decoder.Decode(ModData ?? Data))
                                {
                                    PageName = $"{Pages.Count:D3}.{GetExtension(Result, out ImageFormat Format)}";
                                    PagePath = Path.Combine(TitleDir, ChapterPath, PageName);
                                    if (Result.GetImageExtension() == "png" && Settings.APNGBypass)
                                    {
                                        using (MemoryStream OutBuffer = new MemoryStream(BypassAPNG(ModData ?? Data)))
                                            using (Bitmap Img = new Bitmap(OutBuffer)) {
                                                Img.Save(Buffer, Format);
                                                OutPage.Data = Buffer.ToArray();
                                            }
                                    }
                                    else
                                    {
                                        Result.Save(Buffer, Format);
                                        OutPage.Data = Buffer.ToArray();
                                    }
                                }
                        }

                        OutPage.Path = PagePath;

                        if (PostProcessQueue.Count > 5)
                        {
                            const ulong MinMemory = 400000000;
                            while (AvailablePhysicalMemory < MinMemory && PostProcessQueue.Count > 0 || (Settings.MaxPagesBuffer != 0 && PostProcessQueue.Count >= Settings.MaxPagesBuffer))
                            {
                                ThreadTools.Wait(1000, true);
                            }
                        }

                        PostProcessQueue.Enqueue(OutPage);
#endif
                        Pages.Add(PageName);
                    }
                    catch (Exception ex)
                    {
                        if (Program.Debug)
                        {
                            throw;
                        }
                        Console.Error.WriteLine(ex.ToString());
                    }
                }

                if (Settings.ReaderGenerator)
                {
                    ChapterTools.GenerateComicReader(CurrentLanguage, Pages.ToArray(), LastChapterPah, NextChapterPath, TitleDir, ChapterPath, Name);
                    ChapterTools.GenerateReaderIndex(Languages, CurrentLanguage, Info, TitleDir, Name);
                }

                break;

            case ContentType.Novel:
                var Chapter = Host.DownloadChapter(ID);
                AsyncContext.Run(async() =>
                {
                    using (var Epub = await EPubWriter.CreateWriterAsync(File.Create(ChapterPath), Info.Title ?? "Untitled", Chapter.Author ?? "Anon", Chapter.URL ?? "None"))
                    {
                        Chapter.HTML.RemoveNodes("//script");
                        Chapter.HTML.RemoveNodes("//iframe");

                        foreach (var Node in Chapter.HTML.DocumentNode.DescendantsAndSelf())
                        {
                            if (Node.Name == "img" && Node.GetAttributeValue("src", string.Empty) != string.Empty)
                            {
                                string Src   = Node.GetAttributeValue("src", string.Empty);
                                string RName = Path.GetFileName(Src.Substring(null, "?", IgnoreMissmatch: true));
                                string Mime  = ResourceHandler.GetMimeType(Path.GetExtension(RName));

                                if (Node.GetAttributeValue("type", string.Empty) != string.Empty)
                                {
                                    Mime = Node.GetAttributeValue("type", string.Empty);
                                }

                                Uri Link = new Uri(Info.Url, Src);

                                if (string.IsNullOrWhiteSpace(RName))
                                {
                                    continue;
                                }

                                byte[] Buffer = await Link.TryDownloadAsync();

                                if (Buffer == null)
                                {
                                    continue;
                                }

                                await Epub.AddResourceAsync(RName, Mime, Buffer);
                                Node.SetAttributeValue("src", RName);
                            }

                            if (Node.Name == "link" && Node.GetAttributeValue("rel", string.Empty) == "stylesheet" && Node.GetAttributeValue("href", string.Empty) != string.Empty)
                            {
                                string Src   = Node.GetAttributeValue("href", string.Empty);
                                string RName = Path.GetFileName(Src.Substring(null, "?", IgnoreMissmatch: true));
                                string Mime  = ResourceHandler.GetMimeType(Path.GetExtension(RName));

                                if (Node.GetAttributeValue("type", string.Empty) != string.Empty)
                                {
                                    Mime = Node.GetAttributeValue("type", string.Empty);
                                }

                                Uri Link = new Uri(Info.Url, Src);

                                if (string.IsNullOrWhiteSpace(RName))
                                {
                                    continue;
                                }

                                byte[] Buffer = await Link.TryDownloadAsync();

                                if (Buffer == null)
                                {
                                    continue;
                                }

                                await Epub.AddResourceAsync(RName, Mime, Buffer);
                                Node.SetAttributeValue("href", RName);
                            }
                        }

                        Epub.Publisher = lblTitle.Text;

                        await Epub.AddChapterAsync("chapter.xhtml", Chapter.Title, Chapter.HTML.ToHTML());


                        await Epub.WriteEndOfPackageAsync();
                    }
                });
                break;

            default:
                throw new Exception("Invalid Content Type");
            }
        }
コード例 #22
0
        /// <summary>
        /// Try Solve the Captcha, And request the user help if needed.
        /// </summary>
        /// <param name="OBrowser">The Browser Instance With the Captcha</param>
        public static void ReCaptchaTrySolve(this ChromiumWebBrowser OBrowser, CaptchaSolverType SolverType = CaptchaSolverType.SemiAuto)
        {
            var Browser = OBrowser.GetBrowser();

            Browser.WaitForLoad();
            ThreadTools.Wait(1500, true);
            if (SolverType != CaptchaSolverType.Manual)
            {
                if (!Browser.ReCaptchaIsSolved())
                {
                    Point Cursor = new Point(0, 0);

                    do
                    {
                        OBrowser.ReCaptchaClickImNotRobot(out Cursor);
                        if (Browser.ReCaptchaIsSolved())
                        {
                            return;
                        }
                    } while (Browser.ReCaptchaGetBFramePosition().Y == BFrameHidden);


                    for (int i = 0; i < 3 && !Browser.ReCaptchaIsSolved(); i++)
                    {
                        try
                        {
                            if (Browser.ReCaptchaIsFailed())
                            {
                                Browser.ReCaptchaReset();
                                if (Browser.ReCaptchaIsSolved())
                                {
                                    break;
                                }
                            }
                        }
                        catch { }
                        try
                        {
                            OBrowser.ReCaptchaClickAudioChallenge(Cursor, out Cursor);
                            if (Browser.ReCaptchaIsFailed())
                            {
                                continue;
                            }
                            var Response = Browser.DecodeAudioChallenge();
                            if (Response == null)
                            {
                                continue;
                            }
                            OBrowser.ReCaptchaSolveSound(Response, Cursor, out Cursor);
                        }
                        catch (Exception ex)
                        {
                            if (!Browser.ReCaptchaIsSolved())
                            {
                                throw ex;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }

            if (Browser.ReCaptchaIsSolved())
            {
                return;
            }

            do
            {
                using (var Solver = new SolveCaptcha(OBrowser))
                    Solver.ShowDialog();
            } while (!Browser.ReCaptchaIsSolved());
        }