예제 #1
0
        static public void Decode(object o)
        {
            string captchaFileName = (string)o;

            Console.WriteLine("Solving {0}", captchaFileName);

            // Put your CAPTCHA image file name, file object, stream or vector
            // of bytes here:
            Captcha captcha = ExampleFull.client.Upload(captchaFileName);

            if (null != captcha)
            {
                Console.WriteLine("CAPTCHA {0} uploaded: {1}",
                                  captchaFileName, captcha.Id);

                // Poll for the CAPTCHA status until it's solved.
                // Wait at least a few seconds between poll or you'll get
                // banned as abuser.
                int index    = 0;
                int interval = 0;

                while (captcha.Uploaded && !captcha.Solved)
                {
                    Client.GetPollInterval(index, out interval, out index);
                    System.Threading.Thread.Sleep(interval * 1000);
                    captcha = ExampleFull.client.GetCaptcha(captcha.Id);
                }

                if (captcha.Solved)
                {
                    Console.WriteLine("CAPTCHA {0} solved: {1}",
                                      captchaFileName, captcha.Text);

                    // Report an incorrectly solved CAPTCHA.  Make sure the
                    // CAPTCHA was in fact incorrectly solved, do not just
                    // report them all or at random, or you might be banned
                    // as abuser.
                    if (false /* put your CAPTCHA correctness check here */)
                    {
                        if (ExampleFull.client.Report(captcha))
                        {
                            Console.WriteLine("CAPTCHA {0} reported as incorrectly solved",
                                              captchaFileName);
                        }
                        else
                        {
                            Console.WriteLine("Failed reporting as incorrectly solved");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("CAPTCHA was not solved");
                }
            }
            else
            {
                Console.WriteLine("CAPTCHA was not uploaded");
            }
        }
예제 #2
0
        /**
         * <summary>Wait for a CAPTCHA to be solved.</summary>
         * <param name="captcha">Uploaded CAPTCHA.</param>
         * <param name="timeout">Solving timeout (in seconds).</param>
         * <returns>CAPTCHA if solved, null otherwise.</returns>
         */
        protected Captcha Poll(Captcha captcha, int timeout)
        {
            if (null != captcha)
            {
                DateTime deadline =
                    DateTime.Now.AddSeconds(0 < timeout
                        ? timeout
                        : Client.DefaultTimeout);
                int index    = 0;
                int interval = 0;

                while (deadline > DateTime.Now && !captcha.Solved)
                {
                    Client.GetPollInterval(index, out interval, out index);
                    Thread.Sleep(interval * 1000);

                    try {
                        captcha = this.GetCaptcha(captcha);
                    } catch (System.Exception e) {
                        if (this.Verbose)
                        {
                            Console.WriteLine(DateTime.Now.Ticks + " POLL " + e.Message);
                        }
                        return(null);
                    }
                }
                if (captcha.Solved && captcha.Correct)
                {
                    return(captcha);
                }
            }
            return(null);
        }