Пример #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();
  }
Пример #2
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();
  }