예제 #1
0
 protected <ReturnType> ReturnType handleCaptchaChallenge(Challenge<ReturnType> c)
     throws CaptchaException, InterruptedException, DecrypterException {
   if (c instanceof ImageCaptchaChallenge) {
     final File captchaFile = ((ImageCaptchaChallenge) c).getImageFile();
     cleanUpCaptchaFiles.add(captchaFile);
   }
   if (Thread.currentThread() instanceof SingleDownloadController) {
     logger.severe("PluginForDecrypt.getCaptchaCode inside SingleDownloadController!?");
   }
   c.setTimeout(getCaptchaTimeout());
   invalidateLastChallengeResponse();
   final BlacklistEntry blackListEntry = CaptchaBlackList.getInstance().matches(c);
   if (blackListEntry != null) {
     logger.warning("Cancel. Blacklist Matching");
     throw new CaptchaException(blackListEntry);
   }
   try {
     ChallengeResponseController.getInstance().handle(c);
   } catch (InterruptedException e) {
     LogSource.exception(logger, e);
     throw e;
   } catch (SkipException e) {
     LogSource.exception(logger, e);
     switch (e.getSkipRequest()) {
       case BLOCK_ALL_CAPTCHAS:
         CaptchaBlackList.getInstance().add(new BlockAllCrawlerCaptchasEntry(getCrawler()));
         break;
       case BLOCK_HOSTER:
         CaptchaBlackList.getInstance()
             .add(new BlockCrawlerCaptchasByHost(getCrawler(), getHost()));
         break;
       case BLOCK_PACKAGE:
         CaptchaBlackList.getInstance()
             .add(new BlockCrawlerCaptchasByPackage(getCrawler(), getCurrentLink()));
         break;
       case REFRESH:
         // refresh is not supported from the pluginsystem right now.
         return c.getRefreshTrigger();
       case STOP_CURRENT_ACTION:
         if (Thread.currentThread() instanceof LinkCrawlerThread) {
           LinkCollector.getInstance().abort();
           // Just to be sure
           CaptchaBlackList.getInstance().add(new BlockAllCrawlerCaptchasEntry(getCrawler()));
         }
         break;
       default:
         break;
     }
     throw new CaptchaException(e.getSkipRequest());
   }
   if (!c.isSolved()) {
     throw new DecrypterException(DecrypterException.CAPTCHA);
   }
   return c.getResult().getValue();
 }
 @Override
 public boolean matches(Challenge c) {
   final LinkCrawler lcrawler = getCrawler();
   if (lcrawler != null && lcrawler.isRunning()) {
     final Plugin plugin = c.getPlugin();
     if (plugin instanceof PluginForDecrypt) {
       final PluginForDecrypt decrypt = (PluginForDecrypt) plugin;
       return decrypt.getCrawler() == lcrawler && decrypt.getHost().equalsIgnoreCase(getHost());
     }
   }
   return false;
 }