Example #1
0
  public void doFreeWebsite(
      final DownloadLink downloadLink, final boolean resumable, final int maxChunks)
      throws Exception, PluginException {
    checkErrorsWebsite(downloadLink, true);

    String dllink = null;
    long timeBefore = System.currentTimeMillis();
    boolean password = false;
    boolean skipWaittime = false;

    // only ReCaptcha
    Form dlForm = new Form();
    if (new Regex(brbefore, "(api\\.recaptcha\\.net|google\\.com/recaptcha/api/)").matches()) {
      dlForm = br.getForm(0);
      if (dlForm == null) {
        throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT, getPhrase("NO_RECAPTCHA_FORM"));
      }

      logger.info("Detected captcha method \"Re Captcha\" for this host");
      final Recaptcha rc = new Recaptcha(br, this);
      rc.setForm(dlForm);
      String id = br.getRegex("\\?k=([A-Za-z0-9%_\\+\\- ]+)\"").getMatch(0);
      rc.setId(id);
      for (int i = 0; i < 5; i++) {
        rc.load();
        File cf = rc.downloadCaptcha(getLocalCaptchaFile());
        String c = getCaptchaCode("recaptcha", cf, downloadLink);
        Form rcform = rc.getForm();
        rcform.put("recaptcha_challenge_field", rc.getChallenge());
        rcform.put("recaptcha_response_field", Encoding.urlEncode(c));
        logger.info(
            "Put captchacode "
                + c
                + " obtained by captcha metod \"Re Captcha\" in the form and submitted it.");
        dlForm = rc.getForm();
        // waittime is often skippable for reCaptcha handling
        // skipWaittime = true;
        submitForm(dlForm);
        logger.info("Submitted DLForm");
        if (br.containsHTML("(api\\.recaptcha\\.net|google\\.com/recaptcha/api/)")) {
          rc.reload();
          continue;
        }
        break;
      }

    } else {
      logger.warning("Unknown ReCaptcha method for: " + downloadLink.getDownloadURL());
      throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT, getPhrase("UNKNOWN_RECAPTCHA"));
    }

    /* Captcha END */
    // if (password) passCode = handlePassword(passCode, dlForm, downloadLink);
    if (br.containsHTML("(api\\.recaptcha\\.net|google\\.com/recaptcha/api/)")) {
      logger.info("5 reCaptcha tryouts for <" + downloadLink.getDownloadURL() + "> were incorrect");
      throw new PluginException(
          LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, getPhrase("RECAPTCHA_ERROR"), 1 * 60 * 1000l);
    }

    doSomething();
    checkErrorsWebsite(downloadLink, false);
    dllink = getDllinkWebsite();
    if (dllink == null) {
      logger.warning("Final downloadlink (String is \"dllink\") regex didn't match!");
      throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT, getPhrase("REGEX_ERROR"));
    }
    logger.info("Final downloadlink = " + dllink + " starting the download...");
    dl = jd.plugins.BrowserAdapter.openDownload(br, downloadLink, dllink, resumable, maxChunks);
    if (dl.getConnection().getContentType().contains("html")) {
      logger.warning("The final dllink seems not to be a file!");
      br.followConnection();
      doSomething();
      checkServerErrors();
      throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT, getPhrase("FINAL_LINK_ERROR"));
    }
    downloadLink.setProperty("freelink", dllink);
    dl.startDownload();
  }
Example #2
0
 @SuppressWarnings("deprecation")
 public void doFree(
     final DownloadLink link,
     final boolean resume,
     final int maxchunks,
     final String directlinkproperty)
     throws Exception, PluginException {
   boolean skipWaittime = false;
   String continue_link = null;
   boolean captcha = false;
   boolean success = false;
   final long timeBeforeDirectlinkCheck = System.currentTimeMillis();
   long timeBeforeCaptchaInput;
   continue_link = checkDirectLink(link, directlinkproperty);
   if (continue_link != null) {
     /*
      * Let the server 'calm down' (if it was slow before) otherwise it will thing that we tried to open two connections as we
      * checked the directlink before and return an error.
      */
     if ((System.currentTimeMillis() - timeBeforeDirectlinkCheck) > 1500) {
       sleep(directlinkfound_WAIT_SECONDS * 1000l, link);
     }
     dl = jd.plugins.BrowserAdapter.openDownload(br, link, continue_link, resume, maxchunks);
   } else {
     if (available_CHECK_OVER_INFO_PAGE) {
       br.getPage(link.getDownloadURL());
     }
     handleErrors();
     /* Passwords are usually before waittime. */
     handlePassword(link);
     /* Handle up to 3 pre-download pages before the (eventually existing) captcha */
     for (int i = 1; i <= 5; i++) {
       logger.info("Handling pre-download page #" + i);
       timeBeforeCaptchaInput = System.currentTimeMillis();
       continue_link = getContinueLink();
       if (i == 1 && continue_link == null) {
         logger.info("No continue_link available, plugin broken");
         throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
       } else if (continue_link == null) {
         logger.info("No continue_link available, stepping out of pre-download loop");
         break;
       } else {
         logger.info("Found continue_link, continuing...");
       }
       final String rcID = br.getRegex("recaptcha/api/noscript\\?k=([^<>\"]*?)\"").getMatch(0);
       if (isDownloadlink(continue_link)) {
         /*
          * If we already found a downloadlink let's try to download it because html can still contain captcha html --> We don't
          * need a captcha in this case for sure! E.g. host '3rbup.com'.
          */
         dl = jd.plugins.BrowserAdapter.openDownload(br, link, continue_link, resume, maxchunks);
       } else if (br.containsHTML("data\\-sitekey=")) {
         captcha = true;
         final String recaptchaV2Response =
             new CaptchaHelperHostPluginRecaptchaV2(this, br).getToken();
         success = true;
         if (!skipWaittime) {
           waitTime(link, timeBeforeCaptchaInput);
         }
         dl =
             jd.plugins.BrowserAdapter.openDownload(
                 br,
                 link,
                 continue_link,
                 "submit=Submit&submitted=1&d=1&capcode=false&g-recaptcha-response="
                     + recaptchaV2Response,
                 resume,
                 maxchunks);
       } else if (rcID != null) {
         captcha = true;
         success = false;
         final Recaptcha rc = new Recaptcha(this.br, this);
         rc.setId(rcID);
         rc.load();
         final File cf = rc.downloadCaptcha(getLocalCaptchaFile());
         final String c = getCaptchaCode("recaptcha", cf, link);
         if (!skipWaittime) {
           waitTime(link, timeBeforeCaptchaInput);
         }
         dl =
             jd.plugins.BrowserAdapter.openDownload(
                 br,
                 link,
                 continue_link,
                 "submit=continue&submitted=1&d=1&recaptcha_challenge_field="
                     + rc.getChallenge()
                     + "&recaptcha_response_field="
                     + c,
                 resume,
                 maxchunks);
       } else if (br.containsHTML("solvemedia\\.com/papi/")) {
         captcha = true;
         success = false;
         logger.info("Detected captcha method \"solvemedia\" for this host");
         final org.jdownloader.captcha.v2.challenge.solvemedia.SolveMedia sm =
             new org.jdownloader.captcha.v2.challenge.solvemedia.SolveMedia(br);
         if (br.containsHTML("api\\-secure\\.solvemedia\\.com/")) {
           sm.setSecure(true);
         }
         File cf = null;
         try {
           cf = sm.downloadCaptcha(getLocalCaptchaFile());
         } catch (final Exception e) {
           if (org.jdownloader.captcha.v2.challenge.solvemedia.SolveMedia.FAIL_CAUSE_CKEY_MISSING
               .equals(e.getMessage())) {
             throw new PluginException(
                 LinkStatus.ERROR_FATAL,
                 "Host side solvemedia.com captcha error - please contact the "
                     + this.getHost()
                     + " support");
           }
           throw e;
         }
         final String code = getCaptchaCode("solvemedia", cf, link);
         final String chid = sm.getChallenge(code);
         if (!skipWaittime) {
           waitTime(link, timeBeforeCaptchaInput);
         }
         dl =
             jd.plugins.BrowserAdapter.openDownload(
                 br,
                 link,
                 continue_link,
                 "submit=continue&submitted=1&d=1&adcopy_challenge="
                     + Encoding.urlEncode(chid)
                     + "&adcopy_response="
                     + Encoding.urlEncode(code),
                 resume,
                 maxchunks);
       } else {
         success = true;
         if (!skipWaittime) {
           waitTime(link, timeBeforeCaptchaInput);
         }
         dl = jd.plugins.BrowserAdapter.openDownload(br, link, continue_link, resume, maxchunks);
       }
       checkResponseCodeErrors(dl.getConnection());
       if (dl.getConnection().isContentDisposition()) {
         success = true;
         break;
       }
       br.followConnection();
       handleErrors();
       if (captcha && br.containsHTML("(api\\.recaptcha\\.net|google\\.com/recaptcha/api/)")) {
         logger.info("Wrong captcha");
         continue;
       }
     }
   }
   checkResponseCodeErrors(dl.getConnection());
   if (!dl.getConnection().isContentDisposition()) {
     br.followConnection();
     if (captcha && !success) {
       throw new PluginException(LinkStatus.ERROR_CAPTCHA);
     }
     handleErrors();
     throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
   }
   continue_link = dl.getConnection().getURL().toString();
   link.setProperty(directlinkproperty, continue_link);
   dl.startDownload();
 }
Example #3
0
  /** Handles Free, Free-Account and Premium-Account download via API */
  public void handleDownloadAPI(
      final DownloadLink downloadLink,
      final boolean resumable,
      final int maxChunks,
      final boolean premium,
      final String directlinkproperty)
      throws Exception, PluginException {
    String passCode = downloadLink.getDownloadPassword();
    String dllink = checkDirectLink(downloadLink, directlinkproperty);
    if (dllink == null) {
      String download_post_data =
          "linkid=" + getLinkid(downloadLink) + "&challenge=" + System.currentTimeMillis();
      /*
       * Premium users could skip this step but I left it in so in case a Premium Account just switches to Free or the admin wants
       * premium users to enter captchas/wait too --> Everything is possible ;)
       */
      postPageAPI(getAPIProtocol() + this.getHost() + "/download/json_wait", "");
      /* E.g. response for premium users: {"wait_time":0,"key":null} */

      long wait = 0;
      String wait_str = PluginJSonUtils.getJsonValue(br, "wait_time");
      if (wait_str != null) {
        wait = Long.parseLong(wait_str) * 1000;

        if (wait > System.currentTimeMillis()) {
          /* Change from timestamp of current time + wait TO Remaining wait */
          wait -= System.currentTimeMillis();
        }
        if (wait > 240000l) {
          /* Reconnect wait */
          throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, wait);
        }
      }
      /* 2016-05-19: json_challenge-call is not needed anymore as json_wait will return waittime AND reCaptcha key */
      // postPageAPI("/download/json_challenge", "");
      final String rcID = PluginJSonUtils.getJsonValue(br, "key");
      if (rcID != null && rcID.length() > 6) {
        /* Usually free users do have to enter captchas */
        final Recaptcha rc = new Recaptcha(br, this);
        rc.setId(rcID);
        rc.load();
        final File cf = rc.downloadCaptcha(getLocalCaptchaFile());
        final String c = getCaptchaCode("recaptcha", cf, downloadLink);
        download_post_data +=
            "&recaptcha_challenge_field="
                + Encoding.urlEncode(rc.getChallenge())
                + "&recaptcha_response_field="
                + Encoding.urlEncode(c);
      }
      if (wait > 0) {
        /* Usually free users do have to wait before they can start the download */
        logger.info(
            "We have the captcha answer of the user, waiting "
                + wait
                + " milliseconds until json_download request");
        this.sleep(wait, downloadLink);
      }
      postPageAPI("/download/json_download", download_post_data);

      dllink = PluginJSonUtils.getJsonValue(br, "downloadUrl");
      if (dllink == null || !dllink.startsWith("http")) {
        throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Unknown API issue");
      }
    }
    logger.info("Final downloadlink = " + dllink + " starting the download...");
    dl = jd.plugins.BrowserAdapter.openDownload(br, downloadLink, dllink, resumable, maxChunks);
    if (dl.getConnection().getContentType().contains("html")) {
      logger.warning("The final dllink seems not to be a file!");
      br.followConnection();
      handleErrorsAPI();
      checkServerErrors();
      throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Unknown server issue");
    }
    if (passCode != null) {
      downloadLink.setDownloadPassword(passCode);
    }
    downloadLink.setProperty(directlinkproperty, dllink);
    dl.startDownload();
  }
Example #4
0
  public void doFree(
      DownloadLink downloadLink, boolean resumable, int maxchunks, boolean getLinkWithoutLogin)
      throws Exception, PluginException {
    String passCode = null;
    String md5hash = new Regex(correctedBR, "<b>MD5.*?</b>.*?nowrap>(.*?)<").getMatch(0);
    if (md5hash != null) {
      md5hash = md5hash.trim();
      logger.info("Found md5hash: " + md5hash);
      downloadLink.setMD5Hash(md5hash);
    }

    String dllink = null;
    if (getLinkWithoutLogin) {
      dllink = downloadLink.getStringProperty("freelink");
    } else {
      dllink = downloadLink.getStringProperty("freelink2");
    }
    if (dllink != null) {
      try {
        Browser br2 = br.cloneBrowser();
        URLConnectionAdapter con = br2.openGetConnection(dllink);
        if (con.getContentType().contains("html") || con.getLongContentLength() == -1) {
          if (getLinkWithoutLogin) {
            downloadLink.setProperty("freelink", Property.NULL);
          } else {
            downloadLink.setProperty("freelink2", Property.NULL);
          }
          dllink = null;
        }
        con.disconnect();
      } catch (Exception e) {
        if (getLinkWithoutLogin) {
          downloadLink.setProperty("freelink", Property.NULL);
        } else {
          downloadLink.setProperty("freelink2", Property.NULL);
        }
        dllink = null;
      }
    }

    /**
     * Video links can already be found here, if a link is found here we can skip wait times and
     * captchas
     */
    if (dllink == null) {
      checkErrors(downloadLink, false, passCode);
      if (correctedBR.contains("\"download1\"")) {
        br.postPage(
            downloadLink.getDownloadURL(),
            "op=download1&usr_login=&id="
                + new Regex(
                        downloadLink.getDownloadURL(),
                        COOKIE_HOST.replaceAll("https?://", "") + "/" + "([A-Za-z0-9]{12})")
                    .getMatch(0)
                + "&fname="
                + downloadLink.getName()
                + "&referer=&method_free=Free+Download");
        doSomething();
        checkErrors(downloadLink, false, passCode);
      }
      dllink = getDllink();
    }
    if (dllink == null) {
      Form dlForm = br.getFormbyProperty("name", "F1");
      if (dlForm == null) {
        throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
      }
      final long timeBefore = System.currentTimeMillis();
      boolean password = false;
      boolean skipWaittime = false;
      if (new Regex(correctedBR, PASSWORDTEXT).matches()) {
        password = true;
        logger.info("The downloadlink seems to be password protected.");
      }

      /* Captcha START */
      if (correctedBR.contains(";background:#ccc;text-align")) {
        logger.info("Detected captcha method \"plaintext captchas\" for this host");
        /** Captcha method by ManiacMansion */
        String[][] letters =
            new Regex(
                    Encoding.htmlDecode(br.toString()),
                    "<span style=\\'position:absolute;padding\\-left:(\\d+)px;padding\\-top:\\d+px;\\'>(\\d)</span>")
                .getMatches();
        if (letters == null || letters.length == 0) {
          logger.warning("plaintext captchahandling broken!");
          throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
        }
        SortedMap<Integer, String> capMap = new TreeMap<Integer, String>();
        for (String[] letter : letters) {
          capMap.put(Integer.parseInt(letter[0]), letter[1]);
        }
        StringBuilder code = new StringBuilder();
        for (String value : capMap.values()) {
          code.append(value);
        }
        dlForm.put("code", code.toString());
        logger.info(
            "Put captchacode "
                + code.toString()
                + " obtained by captcha metod \"plaintext captchas\" in the form.");
      } else if (correctedBR.contains("/captchas/")) {
        logger.info("Detected captcha method \"Standard captcha\" for this host");
        String[] sitelinks = HTMLParser.getHttpLinks(br.toString(), null);
        String captchaurl = null;
        if (sitelinks == null || sitelinks.length == 0) {
          logger.warning("Standard captcha captchahandling broken!");
          throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
        }
        for (String link : sitelinks) {
          if (link.contains("/captchas/")) {
            captchaurl = link;
            break;
          }
        }
        if (captchaurl == null) {
          logger.warning("Standard captcha captchahandling broken!");
          throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
        }
        String code = getCaptchaCode("xfilesharingprobasic", captchaurl, downloadLink);
        dlForm.put("code", code);
        logger.info(
            "Put captchacode "
                + code
                + " obtained by captcha metod \"Standard captcha\" in the form.");
      } else if (new Regex(correctedBR, "(api\\.recaptcha\\.net|google\\.com/recaptcha/api/)")
          .matches()) {
        logger.info("Detected captcha method \"Re Captcha\" for this host");
        final Recaptcha rc = new Recaptcha(br, this);
        rc.setForm(dlForm);
        String id = this.br.getRegex("\\?k=([A-Za-z0-9%_\\+\\- ]+)\"").getMatch(0);
        rc.setId(id);
        rc.load();
        File cf = rc.downloadCaptcha(getLocalCaptchaFile());
        String c = getCaptchaCode("recaptcha", cf, downloadLink);
        Form rcform = rc.getForm();
        rcform.put("recaptcha_challenge_field", rc.getChallenge());
        rcform.put("recaptcha_response_field", Encoding.urlEncode(c));
        logger.info(
            "Put captchacode "
                + c
                + " obtained by captcha metod \"Re Captcha\" in the form and submitted it.");
        dlForm = rc.getForm();
        /** wait time is often skippable for reCaptcha handling */
        // skipWaittime = true;
      }
      /* Captcha END */
      if (password) {
        passCode = handlePassword(passCode, dlForm, downloadLink);
      }
      if (!skipWaittime) {
        waitTime(timeBefore, downloadLink);
      }
      br.submitForm(dlForm);
      logger.info("Submitted DLForm");
      doSomething();
      checkErrors(downloadLink, true, passCode);
      dllink = getDllink();
      if (dllink == null) {
        logger.warning("Final downloadlink (String is \"dllink\") regex didn't match!");
        throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
      }
    }
    logger.info("Final downloadlink = " + dllink + " starting the download...");
    dl = jd.plugins.BrowserAdapter.openDownload(br, downloadLink, dllink, resumable, maxchunks);
    if (dl.getConnection().getContentType().contains("html")) {
      logger.warning("The final dllink seems not to be a file!");
      br.followConnection();
      doSomething();
      checkServerErrors();
      throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
    }
    if (getLinkWithoutLogin) {
      downloadLink.setProperty("freelink", dllink);
    } else {
      downloadLink.setProperty("freelink2", dllink);
    }
    if (passCode != null) {
      downloadLink.setProperty("pass", passCode);
    }
    dl.startDownload();
  }
Example #5
0
  @SuppressWarnings("unused")
  public void doFree(
      final DownloadLink downloadLink,
      final boolean resumable,
      final int maxchunks,
      final String directlinkproperty)
      throws Exception, PluginException {
    br.setFollowRedirects(false);
    passCode = downloadLink.getStringProperty("pass");
    /* First, bring up saved final links */
    String dllink = checkDirectLink(downloadLink, directlinkproperty);
    /* Second, check for streaming/direct links on the first page */
    if (dllink == null) {
      dllink = getDllink();
    }
    /* Third, do they provide video hosting? */
    if (dllink == null && VIDEOHOSTER) {
      try {
        logger.info("Trying to get link via vidembed");
        final Browser brv = br.cloneBrowser();
        brv.getPage("/vidembed-" + fuid);
        dllink = brv.getRedirectLocation();
        if (dllink == null) {
          logger.info("Failed to get link via vidembed");
        } else {
          logger.info("Successfully found link via vidembed");
        }
      } catch (final Throwable e) {
        logger.info("Failed to get link via vidembed");
      }
    }
    if (dllink == null && VIDEOHOSTER_2) {
      try {
        logger.info("Trying to get link via embed");
        final String embed_access =
            "http://" + COOKIE_HOST.replace("http://", "") + "/embed-" + fuid + ".html";
        getPage(embed_access);
        dllink = getDllink();
        if (dllink == null) {
          logger.info("Failed to get link via embed");
        } else {
          logger.info("Successfully found link via embed");
        }
      } catch (final Throwable e) {
        logger.info("Failed to get link via embed");
      }
      if (dllink == null) {
        getPage(downloadLink.getDownloadURL());
      }
    }
    /* Fourth, continue like normal */
    if (dllink == null) {
      checkErrors(downloadLink, false);
      final Form download1 = getFormByKey("op", "download1");
      if (download1 != null) {
        download1.remove("method_premium");
        download1.remove("imhuman");
        /*
         * stable is lame, issue finding input data fields correctly. eg. closes at ' quotation mark - remove when jd2 goes stable!
         */
        if (downloadLink.getName().contains("'")) {
          String fname =
              new Regex(br, "<input type=\"hidden\" name=\"fname\" value=\"([^\"]+)\">")
                  .getMatch(0);
          if (fname != null) {
            download1.put("fname", Encoding.urlEncode(fname));
          } else {
            logger.warning("Could not find 'fname'");
            throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
          }
        }
        /* end of backward compatibility */
        waitTime(System.currentTimeMillis(), downloadLink);
        submitForm(download1);
        checkErrors(downloadLink, false);
        dllink = getDllink();
      }
    }
    if (dllink == null) {
      Form dlForm = br.getFormbyProperty("name", "F1");
      if (dlForm == null) {
        handlePluginBroken(downloadLink, "dlform_f1_null", 3);
      }
      /* how many forms deep do you want to try? */
      int repeat = 2;
      for (int i = 0; i <= repeat; i++) {
        dlForm.remove(null);
        final long timeBefore = System.currentTimeMillis();
        boolean password = false;
        boolean skipWaittime = false;
        if (new Regex(correctedBR, PASSWORDTEXT).matches()) {
          password = true;
          logger.info("The downloadlink seems to be password protected.");
        }
        /* md5 can be on the subsequent pages - it is to be found very rare in current XFS versions */
        if (downloadLink.getMD5Hash() == null) {
          String md5hash = new Regex(correctedBR, "<b>MD5.*?</b>.*?nowrap>(.*?)<").getMatch(0);
          if (md5hash != null) {
            downloadLink.setMD5Hash(md5hash.trim());
          }
        }
        /* Captcha START */
        if (correctedBR.contains(";background:#ccc;text-align")) {
          logger.info("Detected captcha method \"plaintext captchas\" for this host");
          /* Captcha method by ManiacMansion */
          final String[][] letters =
              new Regex(
                      br,
                      "<span style='position:absolute;padding\\-left:(\\d+)px;padding\\-top:\\d+px;'>(&#\\d+;)</span>")
                  .getMatches();
          if (letters == null || letters.length == 0) {
            logger.warning("plaintext captchahandling broken!");
            throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
          }
          final SortedMap<Integer, String> capMap = new TreeMap<Integer, String>();
          for (String[] letter : letters) {
            capMap.put(Integer.parseInt(letter[0]), Encoding.htmlDecode(letter[1]));
          }
          final StringBuilder code = new StringBuilder();
          for (String value : capMap.values()) {
            code.append(value);
          }
          dlForm.put("code", code.toString());
          logger.info(
              "Put captchacode "
                  + code.toString()
                  + " obtained by captcha metod \"plaintext captchas\" in the form.");
        } else if (correctedBR.contains("/captchas/")) {
          logger.info("Detected captcha method \"Standard captcha\" for this host");
          final String[] sitelinks = HTMLParser.getHttpLinks(br.toString(), null);
          String captchaurl = null;
          if (sitelinks == null || sitelinks.length == 0) {
            logger.warning("Standard captcha captchahandling broken!");
            throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
          }
          for (String link : sitelinks) {
            if (link.contains("/captchas/")) {
              captchaurl = link;
              break;
            }
          }
          if (captchaurl == null) {
            logger.warning("Standard captcha captchahandling broken!");
            throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
          }
          String code = getCaptchaCode("xfilesharingprobasic", captchaurl, downloadLink);
          dlForm.put("code", code);
          logger.info(
              "Put captchacode "
                  + code
                  + " obtained by captcha metod \"Standard captcha\" in the form.");
        } else if (new Regex(correctedBR, "(api\\.recaptcha\\.net|google\\.com/recaptcha/api/)")
            .matches()) {
          logger.info("Detected captcha method \"Re Captcha\" for this host");
          final Recaptcha rc = new Recaptcha(br, this);
          rc.findID();
          rc.load();
          final File cf = rc.downloadCaptcha(getLocalCaptchaFile());
          final String c = getCaptchaCode("recaptcha", cf, downloadLink);
          dlForm.put("recaptcha_challenge_field", rc.getChallenge());
          dlForm.put("recaptcha_response_field", Encoding.urlEncode(c));
          logger.info(
              "Put captchacode "
                  + c
                  + " obtained by captcha metod \"Re Captcha\" in the form and submitted it.");
          /* wait time is usually skippable for reCaptcha handling */
          skipWaittime = true;
        } else if (br.containsHTML("solvemedia\\.com/papi/")) {
          logger.info("Detected captcha method \"solvemedia\" for this host");

          final org.jdownloader.captcha.v2.challenge.solvemedia.SolveMedia sm =
              new org.jdownloader.captcha.v2.challenge.solvemedia.SolveMedia(br);
          File cf = null;
          try {
            cf = sm.downloadCaptcha(getLocalCaptchaFile());
          } catch (final Exception e) {
            if (org.jdownloader.captcha.v2.challenge.solvemedia.SolveMedia.FAIL_CAUSE_CKEY_MISSING
                .equals(e.getMessage())) {
              throw new PluginException(
                  LinkStatus.ERROR_FATAL,
                  "Host side solvemedia.com captcha error - please contact the "
                      + this.getHost()
                      + " support");
            }
            throw e;
          }
          final String code = getCaptchaCode("solvemedia", cf, downloadLink);
          final String chid = sm.getChallenge(code);
          dlForm.put("adcopy_challenge", chid);
          dlForm.put("adcopy_response", "manual_challenge");
        } else if (br.containsHTML("id=\"capcode\" name= \"capcode\"")) {
          logger.info("Detected captcha method \"keycaptca\"");
          String result =
              handleCaptchaChallenge(
                  getDownloadLink(),
                  new KeyCaptcha(this, br, getDownloadLink()).createChallenge(this));
          if (result == null) {
            throw new PluginException(LinkStatus.ERROR_CAPTCHA);
          }
          if ("CANCEL".equals(result)) {
            throw new PluginException(LinkStatus.ERROR_FATAL);
          }
          dlForm.put("capcode", result);
          skipWaittime = false;
        }
        /* Captcha END */
        if (password) {
          passCode = handlePassword(dlForm, downloadLink);
        }
        if (!skipWaittime) {
          waitTime(timeBefore, downloadLink);
        }
        submitForm(dlForm);
        logger.info("Submitted DLForm");
        checkErrors(downloadLink, true);
        dllink = getDllink();
        if (dllink == null
            && (!br.containsHTML("<Form name=\"F1\" method=\"POST\" action=\"\"") || i == repeat)) {
          logger.warning("Final downloadlink (String is \"dllink\") regex didn't match!");
          throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
        } else if (dllink == null
            && br.containsHTML("<Form name=\"F1\" method=\"POST\" action=\"\"")) {
          dlForm = br.getFormbyProperty("name", "F1");
          try {
            invalidateLastChallengeResponse();
          } catch (final Throwable e) {
          }
          continue;
        } else {
          try {
            validateLastChallengeResponse();
          } catch (final Throwable e) {
          }
          break;
        }
      }
    }
    logger.info("Final downloadlink = " + dllink + " starting the download...");
    if (dllink.startsWith("http")) {
      dl = jd.plugins.BrowserAdapter.openDownload(br, downloadLink, dllink, resumable, maxchunks);
      if (dl.getConnection().getContentType().contains("html")) {
        if (dl.getConnection().getResponseCode() == 503) {
          throw new PluginException(
              LinkStatus.ERROR_HOSTER_TEMPORARILY_UNAVAILABLE,
              "Connection limit reached, please contact our support!",
              5 * 60 * 1000l);
        }
        logger.warning("The final dllink seems not to be a file!");
        br.followConnection();
        correctBR();
        checkServerErrors();
        handlePluginBroken(downloadLink, "dllinknofile", 3);
      }
      downloadLink.setProperty(directlinkproperty, dllink);
      fixFilename(downloadLink);
      try {
        /* add a download slot */
        controlFree(+1);
        /* start the dl */
        dl.startDownload();
      } finally {
        /* remove download slot */
        controlFree(-1);
      }
    } else {
      try {
        rtmpDownload(downloadLink, dllink);
      } catch (final Throwable e) {
        logger.info(getHost() + ": timesfailed_unknown_rtmp_error");
        int timesFailed =
            downloadLink.getIntegerProperty(
                NICE_HOSTproperty + "timesfailed_unknown_rtmp_error", 0);
        downloadLink.getLinkStatus().setRetryCount(0);
        if (timesFailed <= 5) {
          timesFailed++;
          downloadLink.setProperty(
              NICE_HOSTproperty + "timesfailed_unknown_rtmp_error", timesFailed);
          logger.info(getHost() + ": timesfailed_unknown_rtmp_error -> Retrying");
          throw new PluginException(LinkStatus.ERROR_RETRY, "timesfailed_unknown_rtmp_error");
        } else {
          downloadLink.setProperty(
              NICE_HOSTproperty + "timesfailed_unknown_rtmp_error", Property.NULL);
          logger.info(getHost() + ": timesfailed_unknown_rtmp_error - disabling current host!");
          throw new PluginException(
              LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE,
              "Unknown fatal server error",
              5 * 60 * 1000l);
        }
      }
    }
  }
Example #6
0
 public void doFree(final DownloadLink downloadLink, final boolean resume, final int maxchunks)
     throws Exception, PluginException {
   boolean captcha = false;
   if (br.getURL().contains(SIMULTANDLSLIMIT) || br.getURL().contains(SIMULTANDLSLIMIT_2)) {
     throw new PluginException(
         LinkStatus.ERROR_HOSTER_TEMPORARILY_UNAVAILABLE,
         SIMULTANDLSLIMITUSERTEXT,
         1 * 60 * 1000l);
   } else if (br.getURL().contains(SERVERERROR)) {
     throw new PluginException(
         LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, SERVERERRORUSERTEXT, 5 * 60 * 1000l);
   }
   String free_link =
       br.getRegex("\\'(https?://depofile\\.info/[^<>\"]+\\?pt=[^<>\"]*?)\\'").getMatch(0);
   if (free_link == null) {
     throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
   }
   final String waittime =
       br.getRegex("\\$\\(\\'\\.download\\-timer\\-seconds\\'\\)\\.html\\((\\d+)\\);").getMatch(0);
   if (waittime != null) {
     sleep(Integer.parseInt(waittime) * 1001l, downloadLink);
   }
   dl = jd.plugins.BrowserAdapter.openDownload(br, downloadLink, free_link, RESUME, MAXCHUNKS);
   if (!dl.getConnection().isContentDisposition()) {
     br.followConnection();
     if (br.getURL().contains(SERVERERROR)) {
       throw new PluginException(
           LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, SERVERERRORUSERTEXT, 5 * 60 * 1000l);
     }
     final String captchaAction =
         br.getRegex(
                 "<div class=\"captchaPageTable\">[\t\n\r ]+<form method=\"POST\" action=\"(http://[^<>\"]*?)\"")
             .getMatch(0);
     final String rcID = br.getRegex("recaptcha/api/noscript\\?k=([^<>\"]*?)\"").getMatch(0);
     if (rcID == null || captchaAction == null) {
       logger.warning("reCaptcha_ID or captchaAction NULL - plugin seems to be broken!");
       throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
     }
     final Recaptcha rc = new Recaptcha(br, this);
     rc.setId(rcID);
     rc.load();
     for (int i = 0; i <= 5; i++) {
       File cf = rc.downloadCaptcha(getLocalCaptchaFile());
       String c = getCaptchaCode("recaptcha", cf, downloadLink);
       dl =
           jd.plugins.BrowserAdapter.openDownload(
               br,
               downloadLink,
               captchaAction,
               "submit=continue&submitted=1&d=1&recaptcha_challenge_field="
                   + rc.getChallenge()
                   + "&recaptcha_response_field="
                   + c,
               RESUME,
               MAXCHUNKS);
       if (!dl.getConnection().isContentDisposition()) {
         br.followConnection();
         rc.reload();
         continue;
       }
       break;
     }
     captcha = true;
   }
   if (!dl.getConnection().isContentDisposition()) {
     br.followConnection();
     if (captcha && br.containsHTML("(api\\.recaptcha\\.net|google\\.com/recaptcha/api/)")) {
       throw new PluginException(LinkStatus.ERROR_CAPTCHA);
     }
     throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
   }
   dl.startDownload();
 }
Example #7
0
  public ArrayList<DownloadLink> decryptIt(CryptedLink param, ProgressController progress)
      throws Exception {
    ArrayList<DownloadLink> decryptedLinks = new ArrayList<DownloadLink>();
    String parameter = param.toString().replaceAll("linkidwoc|mylink", "linkcheck");
    br.getPage(parameter);
    Browser obr = br.cloneBrowser();
    String fpName = null;
    boolean noCaptcha = true;
    for (int i = 0; i != 4; i++) {
      Form f1 = br.getFormbyProperty("name", "linkprotect");
      if (f1 == null) {
        logger.warning("Plugin Defect: " + parameter);
        return null;
      }
      final Recaptcha rc = new Recaptcha(br, this);
      rc.parse();
      rc.load();
      f1.put("recaptcha_challenge_field", rc.getChallenge());
      // try without captcha
      if (noCaptcha) {
        f1.put("recaptcha_response_field", "");
      } else {
        final File cf = rc.downloadCaptcha(getLocalCaptchaFile());
        final String c = getCaptchaCode("recaptcha", cf, param);
        f1.put("recaptcha_response_field", Encoding.urlEncode(c));
      }
      br.submitForm(f1);
      if (br.containsHTML(
          "(The security code is <font color=\\'red\\'>incorrect</font>|The CAPTCHA wasn\\'t entered correctly)")) {
        if (i == 3) {
          throw new DecrypterException(DecrypterException.CAPTCHA);
        } else if (noCaptcha && i == 1) {
          noCaptcha = false;
        }
        br = obr.cloneBrowser();
        continue;
      }
      Form f2 = br.getFormbyProperty("name", "linkprotect");
      if (f2 == null) {
        logger.warning("Plugin Defect: " + parameter);
        return null;
      }
      br.submitForm(f2);

      if (br.containsHTML("<a href= target=_blank></a>")) {
        logger.info("Link offline: " + parameter);
        return decryptedLinks;
      }
      fpName = br.getRegex("Titre:.*?</td>.*?<td[^>]+>(.*?)</td>").getMatch(0);
      String[] links = br.getRegex("target=_blank>(.*?)</a>").getColumn(0);
      if (links == null || links.length == 0) {
        logger.warning("Decrypter broken for link: " + parameter);
        return null;
      }
      for (String dl : links) {
        decryptedLinks.add(createDownloadlink(dl));
      }
      if (!decryptedLinks.isEmpty()) {
        break;
      } else if (i == 3) {
        return null;
      }
    }
    if (fpName != null) {
      FilePackage fp = FilePackage.getInstance();
      fp.setName(fpName.trim());
      fp.addLinks(decryptedLinks);
    }
    return decryptedLinks;
  }