Example #1
0
  public ArrayList<DownloadLink> decryptIt(CryptedLink param, ProgressController progress)
      throws Exception {
    synchronized (LOCK) {
      ArrayList<DownloadLink> decryptedLinks = new ArrayList<DownloadLink>();
      String parameter = param.toString();
      br.getPage(parameter);
      String waittime = br.getRegex("<p>Du musst noch (\\d+) Sekunden warten bis du").getMatch(0);
      if (waittime != null) {
        int wait = Integer.parseInt(waittime);
        if (wait > 80) {
          logger.warning(wait + " Sekunden Wartezeit: Limit erreicht!");
          logger.warning(br.toString());
          return null;
        }
        sleep(wait * 1001l, param);
      }
      for (int i = 0; i <= 5; i++) {
        PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
        jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br);
        rc.parse();
        rc.load();
        File cf = rc.downloadCaptcha(getLocalCaptchaFile());
        String c = getCaptchaCode(cf, param);
        rc.setCode(c);
        if (br.containsHTML("(api.recaptcha.net|Das war leider Falsch)")) continue;
        if (br.containsHTML("das Falsche Captcha eingegeben")) {
          sleep(60 * 1001l, param);
          br.getHeaders().put("User-Agent", RandomUserAgent.generate());
          br.getPage(parameter);
          continue;
        }
        break;
      }
      if (br.containsHTML(
          "(api.recaptcha.net|Das war leider Falsch|das Falsche Captcha eingegeben)"))
        throw new DecrypterException(DecrypterException.CAPTCHA);
      String links[] = br.getRegex("<a href=\"(http.*?)\" target=\"_blank\" onclick=").getColumn(0);
      if (links == null || links.length == 0) {
        logger.warning("First LdTTemp regex failed, trying the second one...");
        links = HTMLParser.getHttpLinks(br.toString(), "");
      }
      if (links.length == 0) return null;
      for (String finallink : links) {
        if (!finallink.contains("iload.to")
            && !finallink.contains("lof.cc")
            && !finallink.endsWith(".gif")
            && !finallink.endsWith(".swf")) decryptedLinks.add(createDownloadlink(finallink));
      }

      return decryptedLinks;
    }
  }
  public void doFree(final DownloadLink downloadLink, final Account account) throws Exception {
    logger.info("Free mode");
    checkShowFreeDialog();
    String currentIP = getIP();
    try {
      workAroundTimeOut(br);
      String id = getID(downloadLink);
      br.setFollowRedirects(false);
      br.setCookie("http://cloudzer.net/", "lang", "de");
      br.getPage("http://cloudzer.net/language/de");
      if (br.containsHTML("<title>[^<].*?\\- Wartungsarbeiten</title>"))
        throw new PluginException(
            LinkStatus.ERROR_HOSTER_TEMPORARILY_UNAVAILABLE, "ServerMaintenance", 10 * 60 * 1000);

      /**
       * Reconnect handling to prevent having to enter a captcha just to see that a limit has been
       * reached
       */
      logger.info("New Download: currentIP = " + currentIP);
      if (hasDled.get() && ipChanged(currentIP, downloadLink) == false) {
        long result = System.currentTimeMillis() - timeBefore.get();
        if (result < RECONNECTWAIT && result > 0)
          throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, RECONNECTWAIT - result);
      }

      br.getPage("http://cloudzer.net/file/" + id);
      if (br.getRedirectLocation() != null && br.getRedirectLocation().contains("/404")) {
        throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
      }
      if (br.getRedirectLocation() != null) br.getPage(br.getRedirectLocation());
      if (br.containsHTML(
          ">Sie haben die max\\. Anzahl an Free\\-Downloads f\\&#252;r diese Stunde erreicht"))
        throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, 60 * 60 * 1001l);
      String passCode = null;
      if (br.containsHTML("<h2>Authentifizierung</h2>")) {
        passCode = getPassword(downloadLink);
        Form form = br.getForm(0);
        form.put("pw", Encoding.urlEncode(passCode));
        br.submitForm(form);
        if (br.containsHTML("<h2>Authentifizierung</h2>")) {
          downloadLink.setProperty("pass", null);
          throw new PluginException(LinkStatus.ERROR_RETRY, "Password wrong!");
        }
        downloadLink.setProperty("pass", passCode);
      }
      final Browser brc = br.cloneBrowser();
      brc.getPage("http://cloudzer.net/js/download.js");
      final String rcID = brc.getRegex("Recaptcha\\.create\\(\"([^<>\"]*?)\"").getMatch(0);
      String wait =
          br.getRegex("Aktuelle Wartezeit: <span>(\\d+)</span> Sekunden</span>").getMatch(0);
      if (rcID == null) throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
      if (wait == null) {
        wait = "30";
      }
      br.getHeaders().put("X-Requested-With", "XMLHttpRequest");
      br.postPage("http://cloudzer.net/io/ticket/slot/" + getID(downloadLink), "");
      if (!br.containsHTML("\"succ\":true"))
        throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
      final long timebefore = System.currentTimeMillis();
      final PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
      jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br);
      rc.setId(rcID);
      rc.load();
      for (int i = 0; i <= 5; i++) {
        File cf = rc.downloadCaptcha(getLocalCaptchaFile());
        String c = getCaptchaCode(cf, downloadLink);
        int passedTime = (int) ((System.currentTimeMillis() - timebefore) / 1000) - 1;
        if (i == 0 && passedTime < Integer.parseInt(wait)) {
          sleep((Integer.parseInt(wait) - passedTime) * 1001l, downloadLink);
        }
        br.postPage(
            "http://cloudzer.net/io/ticket/captcha/" + getID(downloadLink),
            "recaptcha_challenge_field=" + rc.getChallenge() + "&recaptcha_response_field=" + c);
        if (br.containsHTML("\"err\":\"captcha\"")) {
          try {
            invalidateLastChallengeResponse();
          } catch (final Throwable e) {
          }
          rc.reload();
          continue;
        } else {
          try {
            validateLastChallengeResponse();
          } catch (final Throwable e) {
          }
        }
        break;
      }
      generalFreeErrorhandling(account);
      if (br.containsHTML("err\":\"Ticket kann nicht"))
        throw new PluginException(
            LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "ServerError", 30 * 60 * 1000l);
      if (br.containsHTML("err\":\"Leider sind derzeit all unsere"))
        throw new PluginException(
            LinkStatus.ERROR_HOSTER_TEMPORARILY_UNAVAILABLE,
            "No free Downloadslots available",
            15 * 60 * 1000l);
      if (br.containsHTML("limit\\-parallel"))
        throw new PluginException(
            LinkStatus.ERROR_IP_BLOCKED, "You're already downloading", RECONNECTWAIT);
      if (br.containsHTML("welche von Free\\-Usern gedownloadet werden kann"))
        throw new PluginException(
            LinkStatus.ERROR_FATAL,
            "Only Premium users are allowed to download files lager than 1,00 GB.");
      if (br.containsHTML("\"err\":\"Das Verteilen dieser Datei ist vermutlich nicht erlaubt"))
        throw new PluginException(LinkStatus.ERROR_FATAL, "Link abused, download not possible!");
      String url = br.getRegex("\"url\":\\s*?\"(.*?dl\\\\/.*?)\"").getMatch(0);
      if (url == null) throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
      url = url.replaceAll("\\\\/", "/");
      dl = BrowserAdapter.openDownload(br, downloadLink, url, false, 1);
      try {
        /* remove next major update */
        /* workaround for broken timeout in 0.9xx public */
        ((RAFDownload) dl).getRequest().setConnectTimeout(30000);
        ((RAFDownload) dl).getRequest().setReadTimeout(60000);
      } catch (final Throwable ee) {
      }
      if (!dl.getConnection().isContentDisposition()) {
        try {
          br.followConnection();
        } catch (final Throwable e) {
          logger.severe(e.getMessage());
        }
        logger.info(br.toString());
        if (dl.getConnection().getResponseCode() == 404) {
          throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
        }
        generalFreeErrorhandling(account);
        if (br.containsHTML("please try again in an hour or purchase one of our"))
          throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, RECONNECTWAIT);
        if (dl.getConnection().getResponseCode() == 508)
          throw new PluginException(
              LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "ServerError(508)", 30 * 60 * 1000l);
        if (br.containsHTML("try again later"))
          throw new PluginException(
              LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "ServerError", 30 * 60 * 1000l);
        if (br.containsHTML("All of our free\\-download capacities are"))
          throw new PluginException(
              LinkStatus.ERROR_HOSTER_TEMPORARILY_UNAVAILABLE,
              "All of our free-download capacities are exhausted currently",
              10 * 60 * 1000l);
        if (br.containsHTML("File not found!"))
          throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
        if (br.getURL().contains("view=error"))
          throw new PluginException(
              LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "ServerError", 10 * 60 * 1000l);
        if (br.containsHTML("Aus technischen Gr")
            && br.containsHTML("ist ein Download momentan nicht m"))
          throw new PluginException(
              LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "ServerError", 30 * 60 * 1000l);
        if ("No htmlCode read".equalsIgnoreCase(br.toString()))
          throw new PluginException(
              LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "ServerError", 30 * 60 * 1000l);
        if (br.containsHTML("Datei herunterladen")) {
          /*
           * we get fresh entry page after clicking download, means we have to start from beginning
           */
          throw new PluginException(
              LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Serverproblem", 5 * 60 * 1000l);
        }
        throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
      }
      if (dl.getConnection().getResponseCode() == 404) {
        br.followConnection();
        throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
      }
      if (account != null) account.setProperty("LASTDOWNLOAD", System.currentTimeMillis());
      dl.startDownload();
      hasDled.set(true);
    } catch (Exception e) {
      hasDled.set(false);
      throw e;
    } finally {
      timeBefore.set(System.currentTimeMillis());
      setIP(currentIP, downloadLink, account);
    }
  }
Example #3
0
  @SuppressWarnings("deprecation")
  public void doFree(
      DownloadLink downloadLink, boolean resumable, int maxchunks, boolean checkFastWay)
      throws Exception, PluginException {
    String passCode = null;
    String md5hash = new Regex(BRBEFORE, "<b>MD5.*?</b>.*?nowrap>(.*?)<").getMatch(0);
    if (md5hash != null) {
      md5hash = md5hash.trim();
      logger.info("Found md5hash: " + md5hash);
      downloadLink.setMD5Hash(md5hash);
    }
    String dllink = null;
    if (checkFastWay) {
      dllink = downloadLink.getStringProperty("freelink");
      if (dllink != null) {
        try {
          Browser br2 = br.cloneBrowser();
          URLConnectionAdapter con = br2.openGetConnection(dllink);
          if (con.getContentType().contains("html") || con.getLongContentLength() == -1) {
            downloadLink.setProperty("freelink", Property.NULL);
            dllink = null;
          }
          con.disconnect();
        } catch (Exception e) {
          dllink = null;
        }
      }
    }
    // Videolinks can already be found here, if a link is found here we can
    // skip waittimes and captchas
    if (dllink == null) {
      checkErrors(downloadLink, false, passCode);
      if (BRBEFORE.contains("\"download1\"")) {
        br.postPage(
            downloadLink.getDownloadURL(),
            "op=download1&usr_login=&id="
                + new Regex(
                        downloadLink.getDownloadURL(),
                        COOKIE_HOST.replace("http://", "") + "/" + "([a-z0-9]{12})")
                    .getMatch(0)
                + "&fname="
                + Encoding.urlEncode(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);
      long timeBefore = System.currentTimeMillis();
      boolean password = false;
      boolean skipWaittime = false;
      if (new Regex(BRBEFORE, PASSWORDTEXT).matches()) {
        password = true;
        logger.info("The downloadlink seems to be password protected.");
      }

      /* Captcha START */
      if (BRBEFORE.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 (BRBEFORE.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(BRBEFORE, "(api\\.recaptcha\\.net|google\\.com/recaptcha/api/)")
          .matches()) {
        logger.info("Detected captcha method \"Re Captcha\" for this host");
        PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
        jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br);
        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(cf, downloadLink);
        rc.prepareForm(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;
      }
      /* 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);
    }
    downloadLink.setProperty("freelink", dllink);
    if (passCode != null) downloadLink.setProperty("pass", passCode);
    dl.startDownload();
  }
Example #4
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";
       this.postPage(
           embed_access,
           "op=video_embed3&usr_login=&id2="
               + fuid
               + "&fname="
               + Encoding.urlEncode(downloadLink.getName())
               + "&referer=&file_code="
               + fuid
               + "&method_free=Click+here+to+watch+the+Video");
       // brv.getPage("http://grifthost.com/embed-" + fuid + ".html");
       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");
       /* 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 */
       sendForm(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 PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
         final jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br);
         rc.findID();
         rc.load();
         final File cf = rc.downloadCaptcha(getLocalCaptchaFile());
         final String c = getCaptchaCode(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 PluginForDecrypt solveplug = JDUtilities.getPluginForDecrypt("linkcrypt.ws");
         final jd.plugins.decrypter.LnkCrptWs.SolveMedia sm =
             ((jd.plugins.decrypter.LnkCrptWs) solveplug).getSolveMedia(br);
         File cf = null;
         try {
           cf = sm.downloadCaptcha(getLocalCaptchaFile());
         } catch (final Exception e) {
           if (jd.plugins.decrypter.LnkCrptWs.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(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 = null;
         final PluginForDecrypt keycplug = JDUtilities.getPluginForDecrypt("linkcrypt.ws");
         try {
           final jd.plugins.decrypter.LnkCrptWs.KeyCaptcha kc =
               ((jd.plugins.decrypter.LnkCrptWs) keycplug).getKeyCaptcha(br);
           result = kc.showDialog(downloadLink.getDownloadURL());
         } catch (final Throwable e) {
           result = null;
         }
         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);
       }
       sendForm(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");
         continue;
       } else {
         break;
       }
     }
   }
   logger.info("Final downloadlink = " + dllink + " starting the download...");
   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);
   }
 }
Example #5
0
 public void doFree(
     DownloadLink downloadLink, boolean resumable, int maxchunks, String directlinkproperty)
     throws Exception, PluginException {
   String passCode = null;
   // First, bring up saved final links
   String dllink = checkDirectLink(downloadLink, directlinkproperty);
   // Second, check for streaming links on the first page
   if (dllink == null) dllink = getDllink();
   // Third, continue like normal.
   if (dllink == null) {
     checkErrors(downloadLink, false, passCode);
     if (correctedBR.contains("\"download1\"")) {
       postPage(
           br.getURL(),
           "op=download1&usr_login=&id="
               + new Regex(downloadLink.getDownloadURL(), "/([A-Za-z0-9]{12})$").getMatch(0)
               + "&fname="
               + Encoding.urlEncode(downloadLink.getStringProperty("plainfilename"))
               + "&referer=&method_free=Free+Download");
       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);
     // how many forms deep do you want to try.
     int repeat = 4;
     for (int i = 1; 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 subquent pages
       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 (new Regex(correctedBR, "(api\\.recaptcha\\.net|google\\.com/recaptcha/api/)")
           .matches()) {
         logger.info("Detected captcha method \"Re Captcha\" for this host");
         PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
         jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br);
         rc.setForm(dlForm);
         String id = new Regex(correctedBR, "\\?k=([A-Za-z0-9%_\\+\\- ]+)\"").getMatch(0);
         rc.setId(id);
         rc.load();
         File cf = rc.downloadCaptcha(getLocalCaptchaFile());
         String c = getCaptchaCode(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;
       } else 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.");
       }
       /* Captcha END */
       if (password) passCode = handlePassword(passCode, dlForm, downloadLink);
       if (!skipWaittime) waitTime(timeBefore, downloadLink);
       sendForm(dlForm);
       logger.info("Submitted DLForm");
       checkErrors(downloadLink, true, passCode);
       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");
         continue;
       } else break;
     }
   }
   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();
     correctBR();
     checkServerErrors();
     throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
   }
   downloadLink.setProperty(directlinkproperty, dllink);
   if (passCode != null) downloadLink.setProperty("pass", passCode);
   try {
     // add a download slot
     controlFree(+1);
     // start the dl
     dl.startDownload();
   } finally {
     // remove download slot
     controlFree(-1);
   }
 }
Example #6
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 links on the first page
    if (dllink == null) {
      dllink = getDllink();
    }
    // Third, do they provide video hosting?
    if (dllink == null && VIDEOHOSTER) {
      final Browser brv = br.cloneBrowser();
      brv.getPage(
          "/vidembed-" + new Regex(downloadLink.getDownloadURL(), "([a-z0-9]+)$").getMatch(0));
      dllink = brv.getRedirectLocation();
    }
    // Fourth, continue like normal.
    if (dllink == null) {
      checkErrors(downloadLink, false);
      final Form download1 = getFormByKey("op", "download1");
      if (download1 != null) {
        download1.remove("method_premium");
        // 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
        sendForm(download1);
        checkErrors(downloadLink, false);
        dllink = getDllink();
      }
    }
    if (dllink == null) {
      Form dlForm = br.getFormbyProperty("name", "F1");
      if (dlForm == null) {
        throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
      }
      // 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
        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 PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
          final jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br);
          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 often 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);
          final File cf = sm.downloadCaptcha(getLocalCaptchaFile());
          final String code = getCaptchaCode(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);
          /** wait time is often skippable for reCaptcha handling */
          skipWaittime = false;
        }
        /* Captcha END */
        if (password) {
          passCode = handlePassword(dlForm, downloadLink);
        }
        if (!skipWaittime) {
          waitTime(timeBefore, downloadLink);
        }
        sendForm(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...");
    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();
      throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
    }
    downloadLink.setProperty(directlinkproperty, dllink);
    fixFilename(downloadLink);
    try {
      // add a download slot
      controlFree(+1);
      // start the dl
      dl.startDownload();
    } finally {
      // remove download slot
      controlFree(-1);
    }
  }
Example #7
0
  @Override
  public void handleFree(final DownloadLink link) throws Exception {
    directDownload = false;
    /*
     * for free users we dont use api filecheck, cause we have to call
     * website anyway
     */
    requestFileInformation(link);
    if ("http://hotfile.com/".equals(br.getURL()))
      throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
    if (directDownload) {
      logger.info("use directdownload");
      /* use directDownloadLink */
      br.setFollowRedirects(true);
      try {
        /* first retry with resume allowed */
        dl =
            jd.plugins.BrowserAdapter.openDownload(
                br,
                link,
                link.getDownloadURL(),
                true,
                getPluginConfig().getBooleanProperty(HotFileCom.UNLIMITEDMAXCON, false) == true
                    ? 0
                    : -5);
      } catch (final Throwable e) {
        try {
          dl.getConnection().disconnect();
        } catch (final Throwable e2) {
        }
        /* then try with resume disallowed */
        /* reset chunks */
        link.setChunksProgress(null);
        dl = jd.plugins.BrowserAdapter.openDownload(br, link, link.getDownloadURL(), false, 1);
      }
    } else {
      /* fetch link from website */
      if (br.containsHTML("You are currently downloading")) {
        throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, 5 * 60 * 1000l);
      }
      if (br.containsHTML("starthtimer\\(\\)")) {
        final String waittime =
            br.getRegex("starthtimer\\(\\).*?timerend=.*?\\+(\\d+);").getMatch(0);
        if (Long.parseLong(waittime.trim()) > 0) {
          throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, Long.parseLong(waittime.trim()));
        }
      }
      int tries = getPluginConfig().getIntegerProperty(HotFileCom.CAPTCHARETRIES, 20);
      while (true) {
        final Form[] forms = br.getForms();
        if (br.containsHTML("Could not open socket"))
          throw new PluginException(
              LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "ServerError", 15 * 60 * 1000l);
        final Form form = forms[1];
        long sleeptime = 0;
        try {
          sleeptime =
              Long.parseLong(br.getRegex("timerend=d\\.getTime\\(\\)\\+(\\d+);").getMatch(0)) + 1;
          // for debugging purposes
          logger.info("Regexed waittime is " + sleeptime + " seconds");
        } catch (final Exception e) {
          logger.info("WaittimeRegex broken");
          logger.info(br.toString());
          sleeptime = 60 * 1000l;
        }
        // Reconnect if the waittime is too big!
        if (sleeptime > 100 * 1000l) {
          throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, sleeptime);
        }
        /* 2secs more as extra buffer */
        this.sleep(sleeptime + 2000, link);
        submit(br, form);
        // captcha
        if (!br.containsHTML("Click here to download")) {
          final PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
          final jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br);
          rc.handleAuto(this, link);

          if (!br.containsHTML("Click here to download")) {
            if (tries-- > 0) {
              continue;
            } else {
              throw new PluginException(LinkStatus.ERROR_CAPTCHA);
            }
          }
        }

        break;
      }
      String dl_url =
          br.getRegex("<h3 style='margin-top: 20px'><a href=\"(.*?)\">Click here to download</a>")
              .getMatch(0);
      if (dl_url == null) {
        dl_url =
            br.getRegex("table id=\"download_file\".*?<a href=\"(.*?)\"").getMatch(0); /* polish */
      }
      if (dl_url == null) {
        if (!br.containsHTML("(Click here to download)")) {
          throw new PluginException(LinkStatus.ERROR_CAPTCHA);
        }
        if (br.containsHTML("name=waithash"))
          throw new PluginException(
              LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "ServerError,Waittime again", 30 * 1000l);
        throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
      }
      br.setFollowRedirects(true);
      br.setDebug(true);
      dl = jd.plugins.BrowserAdapter.openDownload(br, link, dl_url, false, 1);
      if (!dl.getConnection().isContentDisposition()) {
        br.followConnection();
        if (br.containsHTML("Invalid link")) {
          final String newLink = br.getRegex("href=\"(http://.*?)\"").getMatch(0);
          if (newLink != null) {
            /* set new downloadlink */
            logger.warning("invalid link -> use new link");
            link.setUrlDownload(newLink.trim());
            throw new PluginException(LinkStatus.ERROR_RETRY);
          }
        }
        if (br.containsHTML(">Your download expired, try again<"))
          throw new PluginException(
              LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE,
              "Download-Session expired",
              10 * 60 * 1000l);
        if (br.containsHTML("You are currently downloading")) {
          throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, 5 * 60 * 1000l);
        }
        throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
      }
      /* filename workaround */
      String urlFileName = Plugin.getFileNameFromURL(new URL(br.getURL()));
      urlFileName = Encoding.htmlDecode(urlFileName);
      link.setFinalFileName(urlFileName);
    }
    dl.startDownload();
  }
Example #8
0
 @SuppressWarnings("unused")
 public void doFree(
     final DownloadLink downloadLink,
     boolean resumable,
     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 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");
       }
     } catch (final Throwable e) {
       logger.info("Failed to get link via vidembed");
     }
   }
   // Possibility to skip captcha & (reconnect) waittimes
   dllink = null;
   boolean special_success = false;
   boolean special2_success = false;
   if (dllink == null
       && TRY_SPECIAL_WAY
       && !downloadLink.getBooleanProperty("special2_failed", false)) {
     try {
       final String temp_id =
           this.getPluginConfig().getStringProperty("spaceforfiles_tempid", null);
       if (temp_id != null) {
         final String checklink =
             "http://www.filespace.com/cgi-bin/dl.cgi/"
                 + temp_id
                 + "/"
                 + Encoding.urlEncode(downloadLink.getName());
         final boolean isvalid = checkDirectLink(checklink);
         if (isvalid) {
           dllink = checklink;
           special_success = true;
         }
       }
     } catch (final Throwable e) {
     }
   }
   if (dllink == null
       && TRY_SPECIAL_WAY_2
       && !downloadLink.getBooleanProperty("special2_failed", false)) {
     try {
       /* Pattern of finallinks generated here: http://www.spaceforfiles.com/dlcdn/xxxxxxxxxxxx/filename.ext */
       final Browser brad = br.cloneBrowser();
       final String fid = new Regex(downloadLink.getDownloadURL(), "([a-z0-9]{12})$").getMatch(0);
       final String postDataF1 =
           "op=download1&usr_login=&id="
               + fid
               + "&fname="
               + Encoding.urlEncode(downloadLink.getName())
               + "&referer=&lck=1&method_free=Free+Download";
       brad.postPage(br.getURL(), postDataF1);
       final String md5 = brad.getRegex("MD5 Checksum: ([a-f0-9]{32})").getMatch(0);
       if (md5 != null) {
         downloadLink.setMD5Hash(md5);
       }
       final String start_referer = brad.getURL();
       final String rand = brad.getRegex("name=\"rand\" value=\"([a-z0-9]+)\"").getMatch(0);
       if (rand == null) {
         throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
       }
       // br.postPage("http://filespace.com/xxxxxxxxxxxx", "op=download2&id=" + fid + "&rand=" +
       // rand +
       // "&referer=&method_free=Free+Download&method_premium=&adcopy_response=&adcopy_challenge=&down_script=1");
       brad.cloneBrowser().getPage("http://www.filespace.com/locker/locker.js?1");
       brad.getPage("http://www.filespace.com/locker/lockurl.php?uniqueid=" + fid);
       if (!brad.containsHTML("\"lockid\":\\-1")) {
         final String lockid = brad.getRegex("\"lockid\":(\")?(\\d+)").getMatch(1);
         final String hash = brad.getRegex("\"hash\":\"([a-z0-9]+)\"").getMatch(0);
         if (lockid == null || hash == null) {
           throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
         }
         brad.getPage(
             "http://www.spaceforfiles.com/locker/offers.php?hash=" + hash + "&sid=" + fid);
         brad.cloneBrowser()
             .getPage("http://www.filespace.com/locker/checkoffer.php?lockid=" + lockid);
       }
       brad.getHeaders().put("Referer", start_referer);
       final String postData =
           "op=download2&id="
               + fid
               + "&rand="
               + rand
               + "&referer="
               + Encoding.urlEncode(br.getURL())
               + "&method_free=Free+Download&method_premium=&method_highspeed=1&lck=1&down_script=1";
       brad.postPage(start_referer, postData);
       dllink = brad.getRedirectLocation();
       if (dllink != null) {
         // resumable = true;
         // maxchunks = 0;
         special2_success = true;
       }
     } catch (final Throwable e) {
     }
   }
   // Fourth, continue like normal.
   if (dllink == null) {
     checkErrors(downloadLink, false);
     final Form download1 = getFormByKey("op", "download1");
     if (download1 != null) {
       download1.remove("method_premium");
       // 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
       sendForm(download1);
       checkErrors(downloadLink, false);
       dllink = getDllink();
     }
   }
   if (dllink == null) {
     Form dlForm = br.getFormbyProperty("name", "F1");
     if (dlForm == null) {
       throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
     }
     // 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
       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 PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
         final jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br);
         rc.findID();
         rc.load();
         final File cf = rc.downloadCaptcha(getLocalCaptchaFile());
         final String c = getCaptchaCode(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 often skippable for reCaptcha handling */
         skipWaittime = true;
       } else if (br.containsHTML("solvemedia\\.com/papi/")) {
         logger.info("Detected captcha method \"solvemedia\" for this host");
         final PluginForDecrypt solveplug = JDUtilities.getPluginForDecrypt("linkcrypt.ws");
         final jd.plugins.decrypter.LnkCrptWs.SolveMedia sm =
             ((jd.plugins.decrypter.LnkCrptWs) solveplug).getSolveMedia(br);
         File cf = null;
         try {
           cf = sm.downloadCaptcha(getLocalCaptchaFile());
         } catch (final Exception e) {
           if (jd.plugins.decrypter.LnkCrptWs.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(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 = null;
         final PluginForDecrypt keycplug = JDUtilities.getPluginForDecrypt("linkcrypt.ws");
         try {
           final jd.plugins.decrypter.LnkCrptWs.KeyCaptcha kc =
               ((jd.plugins.decrypter.LnkCrptWs) keycplug).getKeyCaptcha(br);
           result = kc.showDialog(downloadLink.getDownloadURL());
         } catch (final Throwable e) {
           result = null;
         }
         if (result == null) {
           throw new PluginException(LinkStatus.ERROR_CAPTCHA);
         }
         if ("CANCEL".equals(result)) {
           throw new PluginException(LinkStatus.ERROR_FATAL);
         }
         dlForm.put("capcode", result);
         /** wait time is often skippable for reCaptcha handling */
         skipWaittime = false;
       }
       /* Captcha END */
       if (password) {
         passCode = handlePassword(dlForm, downloadLink);
       }
       if (!skipWaittime) {
         waitTime(timeBefore, downloadLink);
       }
       sendForm(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...");
   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();
     if (special_success) {
       downloadLink.setProperty("special_failed", true);
     } else if (special2_success) {
       downloadLink.setProperty("special2_failed", true);
     }
     int timesFailed =
         downloadLink.getIntegerProperty(NICE_HOSTproperty + "failedtimes_dllinknofile", 0);
     downloadLink.getLinkStatus().setRetryCount(0);
     if (timesFailed <= 2) {
       logger.info(NICE_HOST + ": Final link is no file -> Retrying");
       timesFailed++;
       downloadLink.setProperty(NICE_HOSTproperty + "failedtimes_dllinknofile", timesFailed);
       throw new PluginException(LinkStatus.ERROR_RETRY, "Final download link not found");
     } else {
       downloadLink.setProperty(NICE_HOSTproperty + "failedtimes_dllinknofile", Property.NULL);
       logger.info(NICE_HOST + ": Final link is no file -> Plugin is broken");
       throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
     }
   }
   final String tempid = new Regex(dllink, "cgi\\-bin/dl\\.cgi/([a-z0-9]+)/").getMatch(0);
   if (tempid != null) {
     this.getPluginConfig().setProperty("spaceforfiles_tempid", tempid);
   }
   downloadLink.setProperty(directlinkproperty, dllink);
   fixFilename(downloadLink);
   try {
     // add a download slot
     controlFree(+1);
     // start the dl
     dl.startDownload();
   } finally {
     // remove download slot
     controlFree(-1);
   }
 }
Example #9
0
  public void doFree(DownloadLink downloadLink) throws Exception, PluginException {
    String passCode = null;
    boolean resumable = true;
    int maxchunks = 0;
    // If the filesize regex above doesn't match you can copy this part into
    // the available status (and delete it here)
    Form freeform = br.getFormBySubmitvalue("Kostenloser+Download");
    if (freeform == null) {
      freeform = br.getFormBySubmitvalue("Free+Download");
      if (freeform == null) {
        freeform = br.getFormbyKey("download1");
      }
    }
    if (freeform != null) {
      freeform.remove("method_premium");
      br.submitForm(freeform);
      doSomething();
    }
    checkErrors(downloadLink, false, passCode);
    String md5hash = new Regex(brbefore, "<b>MD5.*?</b>.*?nowrap>(.*?)<").getMatch(0);
    if (md5hash != null) {
      md5hash = md5hash.trim();
      logger.info("Found md5hash: " + md5hash);
      downloadLink.setMD5Hash(md5hash);
    }
    br.setFollowRedirects(false);
    Form DLForm = br.getFormbyProperty("name", "F1");
    if (DLForm == null) throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
    // Ticket Time
    String ttt = new Regex(brbefore, "countdown\">.*?(\\d+).*?</span>").getMatch(0);
    if (ttt == null)
      ttt =
          new Regex(brbefore, "id=\"countdown_str\".*?<span id=\".*?\">.*?(\\d+).*?</span")
              .getMatch(0);
    if (ttt != null) {
      logger.info("Waittime detected, waiting " + ttt + " seconds from now on...");
      int tt = Integer.parseInt(ttt);
      sleep(tt * 1001, downloadLink);
    }
    boolean password = false;
    boolean recaptcha = false;
    if (brbefore.contains(PASSWORDTEXT0) || brbefore.contains(PASSWORDTEXT1)) {
      password = true;
      logger.info("The downloadlink seems to be password protected.");
    }

    /* Captcha START */
    if (brbefore.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 (brbefore.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(captchaurl, downloadLink);
      DLForm.put("code", code);
      logger.info(
          "Put captchacode "
              + code
              + " obtained by captcha metod \"Standard captcha\" in the form.");
    } else if (brbefore.contains("api.recaptcha.net")) {
      // Some hosters also got commentfields with captchas, therefore is
      // the !br.contains...check Exampleplugin:
      // FileGigaCom
      logger.info("Detected captcha method \"Re Captcha\" for this host");
      PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
      jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br);
      rc.parse();
      rc.load();
      File cf = rc.downloadCaptcha(getLocalCaptchaFile());
      String c = getCaptchaCode(cf, downloadLink);
      if (password) {
        passCode = handlePassword(passCode, rc.getForm(), downloadLink);
      }
      recaptcha = true;
      rc.setCode(c);
      logger.info(
          "Put captchacode "
              + c
              + " obtained by captcha metod \"Re Captcha\" in the form and submitted it.");
    }
    /* Captcha END */

    // If the hoster uses Re Captcha the form has already been sent before
    // here so here it's checked. Most hosters don't use Re Captcha so
    // usually recaptcha is false
    if (!recaptcha) {
      if (password) {
        passCode = handlePassword(passCode, DLForm, downloadLink);
      }
      dl = jd.plugins.BrowserAdapter.openDownload(br, downloadLink, DLForm, resumable, maxchunks);
      logger.info("Submitted DLForm");
    }
    if (dl.getConnection().getContentType().contains("html")) {
      br.followConnection();
      logger.info("followed connection...");
      doSomething();
      checkErrors(downloadLink, true, passCode);
      String 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();
        checkServerErrors();
        throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
      }
    }
    if (passCode != null) {
      downloadLink.setProperty("pass", passCode);
    }
    dl.startDownload();
  }
Example #10
0
  @Override
  public void handleFree(DownloadLink downloadLink) throws Exception {
    this.setBrowserExclusive();
    requestFileInformation(downloadLink);
    if (br.containsHTML("value=\"Free Users\""))
      br.postPage(downloadLink.getDownloadURL(), "Free=Free+Users");
    else if (br.getFormbyProperty("name", "entryform1") != null)
      br.submitForm(br.getFormbyProperty("name", "entryform1"));
    final Browser ajaxBR = br.cloneBrowser();
    ajaxBR.getHeaders().put("X-Requested-With", "XMLHttpRequest");

    final String rcID = br.getRegex("challenge\\?k=([^<>\"]*?)\"").getMatch(0);
    if (rcID != null) {
      PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
      jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br);
      rc.setId(rcID);
      rc.load();
      File cf = rc.downloadCaptcha(getLocalCaptchaFile());
      String c = getCaptchaCode(cf, downloadLink);
      ajaxBR.postPage(
          downloadLink.getDownloadURL(),
          "downloadverify=1&d=1&recaptcha_response_field="
              + c
              + "&recaptcha_challenge_field="
              + rc.getChallenge());
      if (ajaxBR.containsHTML("incorrect\\-captcha\\-sol"))
        throw new PluginException(LinkStatus.ERROR_CAPTCHA);
    } else if (br.containsHTML(this.getHost() + "/captcha\\.php\"")) {
      final String code =
          getCaptchaCode(
              "mhfstandard",
              COOKIE_HOST + "/captcha.php?rand=" + System.currentTimeMillis(),
              downloadLink);
      ajaxBR.postPage(downloadLink.getDownloadURL(), "downloadverify=1&d=1&captchacode=" + code);
      if (ajaxBR.containsHTML("Captcha number error or expired"))
        throw new PluginException(LinkStatus.ERROR_CAPTCHA);
    } else {
      ajaxBR.postPage(downloadLink.getDownloadURL(), "downloadverify=1&d=1");
    }
    final String reconnectWaittime =
        ajaxBR.getRegex("You must wait (\\d+) mins\\. for next download.").getMatch(0);
    if (reconnectWaittime != null)
      throw new PluginException(
          LinkStatus.ERROR_IP_BLOCKED, Integer.parseInt(reconnectWaittime) * 60 * 1001l);
    if (ajaxBR.containsHTML(">You have got max allowed download sessions from the same")
        || ajaxBR.containsHTML("The allowed download sessions assigned to your IP is used up"))
      throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, 60 * 60 * 1000l);
    final String finalLink = findLink(ajaxBR);
    if (finalLink == null) throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
    int wait = DEFAULTWAITTIME;
    String waittime = ajaxBR.getRegex("countdown\\((\\d+)\\);").getMatch(0);
    // For older versions it's usually skippable
    // if (waittime == null) waittime =
    // br.getRegex("var timeout=\\'(\\d+)\\';").getMatch(0);
    if (waittime != null) wait = Integer.parseInt(waittime);
    sleep(wait * 1001l, downloadLink);
    dl = jd.plugins.BrowserAdapter.openDownload(br, downloadLink, finalLink, false, 1);
    if (dl.getConnection().getContentType().contains("html")) {
      br.followConnection();

      if (br.containsHTML(">AccessKey is expired, please request"))
        throw new PluginException(LinkStatus.ERROR_FATAL, "FATAL server error, waittime skipped?");
      throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
    }
    dl.startDownload();
  }
Example #11
0
  @Override
  public void handleFree(DownloadLink downloadLink) throws Exception, PluginException {
    boolean resumable = false;
    int maxchunks = 1;
    requestFileInformation(downloadLink);
    // If the filesize regex above doesn't match you can copy this part into
    // the available status (and delete it here)
    Form freeform = br.getFormBySubmitvalue("Kostenloser+Download");
    if (freeform == null) {
      freeform = br.getFormBySubmitvalue("Free+Download");
      if (freeform == null) {
        freeform = br.getFormbyKey("download1");
      }
    }
    if (freeform != null) br.submitForm(freeform);
    /* Errorhandling START */
    // Handling for only-premium links
    if (br.containsHTML(
        "(You can download files up to.*?only|Upgrade your account to download bigger files)")) {
      String filesizelimit = br.getRegex("You can download files up to(.*?)only").getMatch(0);
      if (filesizelimit != null) {
        filesizelimit = filesizelimit.trim();
        logger.warning("As free user you can download files up to " + filesizelimit + " only");
        throw new PluginException(
            LinkStatus.ERROR_FATAL, "Free users can only download files up to " + filesizelimit);
      } else {
        logger.warning("Only downloadable via premium");
        throw new PluginException(LinkStatus.ERROR_FATAL, "Only downloadable via premium");
      }
    }
    if (br.containsHTML("This file reached max downloads")) {
      throw new PluginException(LinkStatus.ERROR_FATAL, "This file reached max downloads");
    }
    if (br.containsHTML("You have to wait")) {
      int minutes = 0, seconds = 0, hours = 0;
      String tmphrs = br.getRegex("\\s+(\\d+)\\s+hours?").getMatch(0);
      if (tmphrs != null) hours = Integer.parseInt(tmphrs);
      String tmpmin = br.getRegex("\\s+(\\d+)\\s+minutes?").getMatch(0);
      if (tmpmin != null) minutes = Integer.parseInt(tmpmin);
      String tmpsec = br.getRegex("\\s+(\\d+)\\s+seconds?").getMatch(0);
      if (tmpsec != null) seconds = Integer.parseInt(tmpsec);
      int waittime = ((3600 * hours) + (60 * minutes) + seconds + 1) * 1000;
      logger.info("Detected waittime #1, waiting " + waittime + "milliseconds");
      throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, null, waittime);
    }
    if (br.containsHTML("You have reached the download-limit")) {
      String tmphrs = br.getRegex("\\s+(\\d+)\\s+hours?").getMatch(0);
      String tmpmin = br.getRegex("\\s+(\\d+)\\s+minutes?").getMatch(0);
      String tmpsec = br.getRegex("\\s+(\\d+)\\s+seconds?").getMatch(0);
      if (tmphrs == null && tmpmin == null && tmpsec == null) {
        throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, null, 60 * 60 * 1000l);
      } else {
        int minutes = 0, seconds = 0, hours = 0;
        if (tmphrs != null) hours = Integer.parseInt(tmphrs);
        if (tmpmin != null) minutes = Integer.parseInt(tmpmin);
        if (tmpsec != null) seconds = Integer.parseInt(tmpsec);
        int waittime = ((3600 * hours) + (60 * minutes) + seconds + 1) * 1000;
        logger.info("Detected waittime #2, waiting " + waittime + "milliseconds");
        throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, null, waittime);
      }
    }
    /* Errorhandling END */
    String md5hash = br.getRegex("<b>MD5.*?</b>.*?nowrap>(.*?)<").getMatch(0);
    if (md5hash != null) {
      md5hash = md5hash.trim();
      logger.info("Found md5hash: " + md5hash);
      downloadLink.setMD5Hash(md5hash);
    }
    br.setFollowRedirects(false);
    Form DLForm = br.getFormbyProperty("name", "F1");
    if (DLForm == null) throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
    // Ticket Time
    String ttt = br.getRegex("countdown\">.*?(\\d+).*?</span>").getMatch(0);
    if (ttt != null) {
      logger.info("Waittime detected, waiting " + ttt.trim() + " seconds from now on...");
      int tt = Integer.parseInt(ttt);
      sleep(tt * 1001, downloadLink);
    }
    String passCode = null;
    boolean password = false;
    boolean recaptcha = false;
    if (br.containsHTML("(<b>Passwort:</b>|<b>Password:</b>)")) {
      password = true;
      logger.info("The downloadlink seems to be password protected.");
    }

    /* Captcha START */
    if (br.containsHTML("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 (br.containsHTML("/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(captchaurl, downloadLink);
      DLForm.put("code", code);
      logger.info(
          "Put captchacode "
              + code
              + " obtained by captcha metod \"Standard captcha\" in the form.");
    } else if (br.containsHTML("api.recaptcha.net")
        && !br.containsHTML(
            "api\\.recaptcha\\.net.*?<Textarea.*?<input type=\"submit\" value.*?</Form>")) {
      // Some hosters also got commentfields with captchas, therefore is
      // the !br.contains...check Exampleplugin:
      // FileGigaCom
      logger.info("Detected captcha method \"Re Captcha\" for this host");
      PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
      jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br);
      rc.parse();
      rc.load();
      File cf = rc.downloadCaptcha(getLocalCaptchaFile());
      String c = getCaptchaCode(cf, downloadLink);
      if (password == true) {
        if (downloadLink.getStringProperty("pass", null) == null) {
          passCode = getUserInput(null, downloadLink);
        } else {
          /* gespeicherten PassCode holen */
          passCode = downloadLink.getStringProperty("pass", null);
        }
        rc.getForm().put("password", passCode);
        logger.info("Put password \"" + passCode + "\" entered by user in the DLForm.");
        password = false;
      }
      recaptcha = true;
      rc.setCode(c);
      logger.info(
          "Put captchacode "
              + c
              + " obtained by captcha metod \"Re Captcha\" in the form and submitted it.");
    }
    /* Captcha END */

    // If the hoster uses Re Captcha the form has already been sent before
    // here so here it's checked. Most hosters don't use Re Captcha so
    // usually recaptcha is false
    if (recaptcha == false) {
      if (password == true) {
        if (downloadLink.getStringProperty("pass", null) == null) {
          passCode = getUserInput(null, downloadLink);
        } else {
          /* gespeicherten PassCode holen */
          passCode = downloadLink.getStringProperty("pass", null);
        }
        DLForm.put("password", passCode);
        logger.info("Put password \"" + passCode + "\" entered by user in the DLForm.");
      }
      jd.plugins.BrowserAdapter.openDownload(br, downloadLink, DLForm, resumable, maxchunks);
      logger.info("Submitted DLForm");
    }
    boolean error = false;
    try {
      if (dl.getConnection().getContentType().contains("html")) {
        error = true;
      }
    } catch (Exception e) {
      error = true;
    }
    if (br.getRedirectLocation() != null || error == true) {
      br.followConnection();
      logger.info("followed connection...");
      String dllink = br.getRedirectLocation();
      if (dllink == null) {
        if (br.containsHTML("You have to wait")) {
          int minutes = 0, seconds = 0, hours = 0;
          String tmphrs = br.getRegex("\\s+(\\d+)\\s+hours?").getMatch(0);
          if (tmphrs != null) hours = Integer.parseInt(tmphrs);
          String tmpmin = br.getRegex("\\s+(\\d+)\\s+minutes?").getMatch(0);
          if (tmpmin != null) minutes = Integer.parseInt(tmpmin);
          String tmpsec = br.getRegex("\\s+(\\d+)\\s+seconds?").getMatch(0);
          if (tmpsec != null) seconds = Integer.parseInt(tmpsec);
          int waittime = ((3600 * hours) + (60 * minutes) + seconds + 1) * 1000;
          logger.info("Detected waittime #1, waiting " + waittime + "milliseconds");
          throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, null, waittime);
        }
        if (br.containsHTML("You have reached the download-limit")) {
          String tmphrs = br.getRegex("\\s+(\\d+)\\s+hours?").getMatch(0);
          String tmpmin = br.getRegex("\\s+(\\d+)\\s+minutes?").getMatch(0);
          String tmpsec = br.getRegex("\\s+(\\d+)\\s+seconds?").getMatch(0);
          if (tmphrs == null && tmpmin == null && tmpsec == null) {
            throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, null, 60 * 60 * 1000l);
          } else {
            int minutes = 0, seconds = 0, hours = 0;
            if (tmphrs != null) hours = Integer.parseInt(tmphrs);
            if (tmpmin != null) minutes = Integer.parseInt(tmpmin);
            if (tmpsec != null) seconds = Integer.parseInt(tmpsec);
            int waittime = ((3600 * hours) + (60 * minutes) + seconds + 1) * 1000;
            logger.info("Detected waittime #2, waiting " + waittime + "milliseconds");
            throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, null, waittime);
          }
        }
        if (br.containsHTML("You're using all download slots for IP"))
          throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, null, 10 * 60 * 1001l);
        if (br.containsHTML("(<b>Passwort:</b>|<b>Password:</b>|Wrong password)")) {
          logger.warning(
              "Wrong password, the entered password \"" + passCode + "\" is wrong, retrying...");
          downloadLink.setProperty("pass", null);
          throw new PluginException(LinkStatus.ERROR_RETRY);
        }
        if (br.containsHTML("Wrong captcha")) {
          logger.warning("Wrong captcha or wrong password!");
          throw new PluginException(LinkStatus.ERROR_CAPTCHA);
        }
        if (dllink == null) {
          dllink = br.getRegex("dotted #bbb;padding.*?<a href=\"(.*?)\"").getMatch(0);
          if (dllink == null) {
            dllink =
                br.getRegex("This direct link will be available for your IP.*?href=\"(http.*?)\"")
                    .getMatch(0);
            if (dllink == null) {
              // This was for fileop.com, maybe also works for
              // others!
              dllink = br.getRegex("Download: <a href=\"(.*?)\"").getMatch(0);
            }
          }
        }
      }
      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...");
      jd.plugins.BrowserAdapter.openDownload(br, downloadLink, dllink, resumable, maxchunks);
    }
    if (passCode != null) {
      downloadLink.setProperty("pass", passCode);
    }
    boolean error2 = false;
    try {
      if (dl.getConnection().getContentType().contains("html")) {
        error2 = true;
      }
    } catch (Exception e) {
      error2 = true;
    }
    if (error2 == true) {
      logger.warning("The final dllink seems not to be a file!");
      br.followConnection();
      if (br.containsHTML("File Not Found")) {
        logger.warning("Server says link offline, please recheck that!");
        throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
      }
      throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
    }
    dl.startDownload();
  }
Example #12
0
  public ArrayList<DownloadLink> decryptIt(CryptedLink param, ProgressController progress)
      throws Exception {
    ArrayList<DownloadLink> decryptedLinks = new ArrayList<DownloadLink>();
    String parameter = param.toString();
    br.setFollowRedirects(false);
    br.getPage(parameter);
    if (br.containsHTML("(\"This link does not exist\\.\"|ERROR - this link does not exist)"))
      throw new DecrypterException(
          JDL.L(
              "plugins.decrypt.errormsg.unavailable",
              "Perhaps wrong URL or the download is not available anymore."));
    if (br.containsHTML(">Not yet checked</span>")) throw new DecrypterException("Not yet checked");
    if (br.containsHTML("To use reCAPTCHA you must get an API key from"))
      throw new DecrypterException("Server error, please contact the safelinking.net support!");
    if (!parameter.contains("/d/")) {
      Form capForm = new Form();
      capForm.put("post-protect", "1");
      capForm.setMethod(MethodType.POST);
      capForm.setAction(parameter);
      for (int i = 0; i <= 5; i++) {
        if (br.containsHTML(PASSWORDPROTECTEDTEXT)) {
          capForm.put("link-password", getUserInput(null, param));
        }
        if (br.containsHTML(RECAPTCHATEXT)) {
          PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
          jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br);
          rc.parse();
          rc.load();
          File cf = rc.downloadCaptcha(getLocalCaptchaFile());
          capForm.put("recaptcha_challenge_field", rc.getChallenge());
          capForm.put("recaptcha_response_field", getCaptchaCode(cf, param));
        } else if (br.getRegex(CAPTCHAREGEX1).getMatch(0) != null) {
          capForm.put(
              "securimage_response_field",
              getCaptchaCode(br.getRegex(CAPTCHAREGEX1).getMatch(0), param));
        } else if (br.getRegex(CAPTCHAREGEX2).getMatch(0) != null) {
          capForm.put(
              "3dcaptcha_response_field",
              getCaptchaCode(br.getRegex(CAPTCHAREGEX2).getMatch(0), param));
        } else if (br.containsHTML(CAPTCHATEXT3)) {
          Browser xmlbrowser = br.cloneBrowser();
          xmlbrowser.getPage("http://safelinking.net/includes/captcha_factory/fancycaptcha.php");
          capForm.put("fancy-captcha", xmlbrowser.toString().trim());
        }
        br.submitForm(capForm);
        if (br.containsHTML(RECAPTCHATEXT)
            || br.getRegex(CAPTCHAREGEX1).getMatch(0) != null
            || br.getRegex(CAPTCHAREGEX2).getMatch(0) != null
            || br.containsHTML(PASSWORDPROTECTEDTEXT)) continue;
        if (br.containsHTML(CAPTCHATEXT3)) {
          logger.warning("Captcha3 captchahandling failed for link: " + parameter);
          return null;
        }
        break;
      }
      if (br.containsHTML(RECAPTCHATEXT)
          || br.getRegex(CAPTCHAREGEX1).getMatch(0) != null
          || br.getRegex(CAPTCHAREGEX2).getMatch(0) != null)
        throw new DecrypterException(DecrypterException.CAPTCHA);
      if (br.containsHTML(PASSWORDPROTECTEDTEXT))
        throw new DecrypterException(DecrypterException.PASSWORD);
      if (br.containsHTML(">All links are dead\\.<"))
        throw new DecrypterException(
            JDL.L(
                "plugins.decrypt.errormsg.unavailable",
                "Perhaps wrong URL or the download is not available anymore."));
      // container handling (if no containers found, use webprotection
      if (br.containsHTML("\\.dlc")) {
        decryptedLinks = loadcontainer(".dlc", param);
        if (decryptedLinks != null && decryptedLinks.size() > 0) return decryptedLinks;
      }

      if (br.containsHTML("\\.rsdf")) {
        decryptedLinks = loadcontainer(".rsdf", param);
        if (decryptedLinks != null && decryptedLinks.size() > 0) return decryptedLinks;
      }

      if (br.containsHTML("\\.ccf")) {
        decryptedLinks = loadcontainer(".ccf", param);
        if (decryptedLinks != null && decryptedLinks.size() > 0) return decryptedLinks;
      }
      decryptedLinks = new ArrayList<DownloadLink>();
      // Webprotection decryption
      String[] links =
          br.getRegex("class=\"linked\">(http://safelinking\\.net/d/.*?)</a>").getColumn(0);
      if (links == null || links.length == 0) {
        String allLinks =
            br.getRegex("class=\"link-box\" id=\"direct-links\".*?>(.*?<a href=\".*?)</div>")
                .getMatch(0);
        if (allLinks != null) links = new Regex(allLinks, "<a href=\"(.*?)\"").getColumn(0);
        if (links == null || links.length == 0) {
          links = br.getRegex("\"(http://safelinking\\.net/d/[a-z0-9]+)\"").getColumn(0);
          if (links == null || links.length == 0) {
            links = br.getRegex("class=\"linked\">(http://.*?)</a>").getColumn(0);
          }
        }
      }
      if (links == null || links.length == 0) return null;
      progress.setRange(links.length);
      for (String link : links) {
        if (!link.contains("safelinking.net/")) {
          decryptedLinks.add(createDownloadlink(link));
        } else {
          br.getPage(link);
          String finallink = br.getRedirectLocation();
          if (finallink == null) {
            logger.warning("Decrypter broken, decryption stopped at link: " + link);
            return null;
          }
          if (!parameter.equals(finallink)) decryptedLinks.add(createDownloadlink(finallink));
        }
        progress.increase(1);
      }
    } else {
      if (br.getRedirectLocation() == null) {
        logger.warning("Error in single-link handling for link: " + parameter);
        return null;
      }
      decryptedLinks.add(createDownloadlink(br.getRedirectLocation()));
    }
    return decryptedLinks;
  }
 @SuppressWarnings("unchecked")
 private void login(Account account, boolean showCaptcha, boolean doCheck) throws Exception {
   synchronized (LOCK) {
     try {
       /** Load cookies */
       br.setCookiesExclusive(true);
       br.setCookie(COOKIE_HOST, "lang", "english");
       final Object ret = account.getProperty("cookies", null);
       boolean refreshCookies = true;
       boolean acmatch =
           Encoding.urlEncode(account.getUser())
               .equals(account.getStringProperty("name", Encoding.urlEncode(account.getUser())));
       if (acmatch)
         acmatch =
             Encoding.urlEncode(account.getPass())
                 .equals(account.getStringProperty("pass", Encoding.urlEncode(account.getPass())));
       if (acmatch && ret != null && ret instanceof HashMap<?, ?>) {
         final HashMap<String, String> cookies = (HashMap<String, String>) ret;
         if (account.isValid()) {
           for (final Map.Entry<String, String> cookieEntry : cookies.entrySet()) {
             final String key = cookieEntry.getKey();
             final String value = cookieEntry.getValue();
             this.br.setCookie(COOKIE_HOST, key, value);
           }
           if (doCheck) {
             br.getPage(COOKIE_HOST + "/?op=my_account");
             doSomething();
             if ((br.getCookie(COOKIE_HOST, "login")) == null
                 || br.getCookie(COOKIE_HOST, "xfss") == null) {
               /* cookies are no longer valid, refresh them */
               refreshCookies = true;
             } else {
               /* cookies are still okay, no need to refresh */
               refreshCookies = false;
             }
           } else {
             /* no doCheck */
             return;
           }
         }
       }
       if (refreshCookies) {
         /* fresh login = new cookies */
         br.getPage(COOKIE_HOST + "/login.html");
         Form loginform = br.getForm(0);
         if (loginform == null) throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
         loginform.put("login", Encoding.urlEncode(account.getUser()));
         loginform.put("password", Encoding.urlEncode(account.getPass()));
         if (br.containsHTML("RecaptchaOptions")) {
           /* too many logins result in recaptcha login */
           if (showCaptcha == false) {
             AccountInfo ai = account.getAccountInfo();
             if (ai != null) {
               ai.setStatus("Logout/Login in Browser please!");
             }
             throw new PluginException(
                 LinkStatus.ERROR_PREMIUM, PluginException.VALUE_ID_PREMIUM_DISABLE);
           } else {
             /* recaptcha needed */
             PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
             jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br);
             rc.setForm(loginform);
             String id = this.br.getRegex("\\?k=([A-Za-z0-9%_\\+\\- ]+)\"").getMatch(0);
             rc.setId(id);
             rc.load();
             File cf = rc.downloadCaptcha(getLocalCaptchaFile());
             DownloadLink dummyLink =
                 new DownloadLink(null, "Account", "easybytez.com", "http://easybytez.com", true);
             String c = getCaptchaCode(cf, dummyLink);
             rc.setCode(c);
           }
         } else {
           /* no recaptcha needed */
           br.submitForm(loginform);
         }
       }
       if (br.getCookie(COOKIE_HOST, "login") == null || br.getCookie(COOKIE_HOST, "xfss") == null)
         throw new PluginException(
             LinkStatus.ERROR_PREMIUM, PluginException.VALUE_ID_PREMIUM_DISABLE);
       if (refreshCookies) {
         /* we have to fetch my_account page again */
         br.getPage(COOKIE_HOST + "/?op=my_account");
         doSomething();
       }
       if (!new Regex(
               BRBEFORE,
               "(Premium\\-Account expire|/\\?op=payments\">Get Premium<|>Renew premium<)")
           .matches())
         throw new PluginException(
             LinkStatus.ERROR_PREMIUM, PluginException.VALUE_ID_PREMIUM_DISABLE);
       if (!new Regex(BRBEFORE, "(Premium\\-Account expire|>Renew premium<)").matches()) {
         account.setProperty("nopremium", true);
       } else {
         account.setProperty("nopremium", false);
       }
       /** Save cookies */
       final HashMap<String, String> cookies = new HashMap<String, String>();
       final Cookies add = this.br.getCookies(COOKIE_HOST);
       for (final Cookie c : add.getCookies()) {
         cookies.put(c.getKey(), c.getValue());
       }
       account.setProperty("name", Encoding.urlEncode(account.getUser()));
       account.setProperty("pass", Encoding.urlEncode(account.getPass()));
       account.setProperty("cookies", cookies);
     } catch (PluginException e) {
       account.setProperty("cookies", null);
       throw e;
     }
   }
 }
 @Override
 public void handleFree(DownloadLink downloadLink) throws Exception {
   checkShowFreeDialog();
   requestFileInformation(downloadLink);
   br.setFollowRedirects(true);
   if (server != -1) {
     synchronized (noFreeSlot) {
       Long ret = noFreeSlot.get(server);
       if (ret != null) {
         if (System.currentTimeMillis() - ret < waitNoFreeSlot) {
           if (downloadLink.getLinkStatus().getRetryCount() >= 5) {
             /*
              * reset counter this error does not cause plugin to stop
              */
             downloadLink.getLinkStatus().setRetryCount(0);
           }
           throw new PluginException(
               LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE,
               JDL.L(
                   "plugins.hoster.shareonlinebiz.errors.servernotavailable3",
                   "No free Free-User Slots! Get PremiumAccount or wait!"),
               waitNoFreeSlot);
         } else {
           noFreeSlot.remove(server);
         }
       }
     }
     synchronized (overloadedServer) {
       Long ret = overloadedServer.get(server);
       if (ret != null) {
         if (System.currentTimeMillis() - ret < waitOverloadedServer) {
           if (downloadLink.getLinkStatus().getRetryCount() >= 5) {
             /*
              * reset counter this error does not cause plugin to stop
              */
             downloadLink.getLinkStatus().setRetryCount(0);
           }
           throw new PluginException(
               LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Server overloaded", waitNoFreeSlot);
         } else {
           overloadedServer.remove(server);
         }
       }
     }
   }
   this.setBrowserExclusive();
   br.getHeaders().put("User-Agent", UA.toString());
   br.getHeaders()
       .put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
   br.getHeaders().put("Accept-Language", "en-us,de;q=0.7,en;q=0.3");
   br.getHeaders().put("Pragma", null);
   br.getHeaders().put("Cache-Control", null);
   br.setCookie("http://www.share-online.biz", "page_language", "english");
   // redirects!
   try {
     br.getPage(downloadLink.getDownloadURL().replace("https://", "http://"));
   } catch (final BrowserException e) {
     if (br.getRequest().getHttpConnection().getResponseCode() == 502) {
       throw new PluginException(
           LinkStatus.ERROR_HOSTER_TEMPORARILY_UNAVAILABLE,
           JDL.L("plugins.hoster.shareonlinebiz.errors.maintenance", "Server maintenance"),
           30 * 60 * 1000l);
     }
     throw new PluginException(
         LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE,
         JDL.L("plugins.hoster.shareonlinebiz.errors.unknownservererror", "Unknown server error"),
         1 * 60 * 60 * 1000l);
   }
   if (br.getURL().contains("/failure/proxy/1")) {
     throw new PluginException(LinkStatus.ERROR_FATAL, "Proxy error");
   }
   final Browser brc = br.cloneBrowser();
   try {
     brc.openGetConnection("/template/images/corp/uploadking.php?show=last");
   } finally {
     try {
       brc.getHttpConnection().disconnect();
     } catch (final Throwable e) {
     }
   }
   errorHandling(br, downloadLink, null, null);
   if (!br.containsHTML(">>> continue for free <<<")) {
     throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
   }
   String ID = getID(downloadLink);
   br.postPage("/dl/" + ID + "/free/", "dl_free=1");
   errorHandling(br, downloadLink, null, null);
   String wait = br.getRegex("var wait=(\\d+)").getMatch(0);
   boolean captcha = br.containsHTML("RECAPTCHA active");
   long startWait = 0;
   if (captcha == true) {
     startWait = System.currentTimeMillis();
   } else {
     if (wait != null) {
       this.sleep(Integer.parseInt(wait) * 1000l, downloadLink);
     }
   }
   String dlINFO = br.getRegex("var dl=\"(.*?)\"").getMatch(0);
   String url = Encoding.Base64Decode(dlINFO);
   if (captcha) {
     /* recaptcha handling */
     PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
     jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br);
     rc.setId("6LdatrsSAAAAAHZrB70txiV5p-8Iv8BtVxlTtjKX");
     rc.load();
     File cf = rc.downloadCaptcha(getLocalCaptchaFile());
     String c = getCaptchaCode("recaptcha", cf, downloadLink);
     if (wait != null) {
       long gotWait = Integer.parseInt(wait) * 500l;
       long waited = System.currentTimeMillis() - startWait;
       gotWait -= waited;
       if (gotWait > 0) {
         this.sleep(gotWait, downloadLink);
       }
     }
     br.postPage(
         "/dl/" + ID + "/free/captcha/" + System.currentTimeMillis(),
         "dl_free=1&recaptcha_response_field="
             + Encoding.urlEncode(c)
             + "&recaptcha_challenge_field="
             + rc.getChallenge());
     url = br.getRegex("([a-zA-Z0-9/=]+)").getMatch(0);
     if ("0".equals(url)) {
       throw new PluginException(LinkStatus.ERROR_CAPTCHA);
     }
     url = Encoding.Base64Decode(url);
     if (url == null || !url.startsWith("http")) {
       url = null;
     }
     if (wait != null) {
       this.sleep(Integer.parseInt(wait) * 1000l, downloadLink);
     }
   }
   br.setFollowRedirects(true);
   /* Datei herunterladen */
   if (url != null && url.trim().length() == 0) {
     throw new PluginException(
         LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "ServerError", 5 * 60 * 1000l);
   }
   if (br.containsHTML(">Proxy\\-Download not supported for free access")) {
     throw new PluginException(
         LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE,
         "Proxy download not supported for free access",
         5 * 60 * 1000l);
   }
   if (url == null || !url.startsWith("http")) {
     logger.info("share-online.biz: Unknown error");
     int timesFailed = downloadLink.getIntegerProperty("timesfailedshareonlinebiz_unknown", 0);
     if (timesFailed <= 2) {
       timesFailed++;
       downloadLink.setProperty("timesfailedshareonlinebiz_unknown", timesFailed);
       throw new PluginException(LinkStatus.ERROR_RETRY, "Unknown error");
     } else {
       downloadLink.setProperty("timesfailedshareonlinebiz_unknown", Property.NULL);
       logger.info("share-online.biz: Unknown error - Plugin broken!");
       throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
     }
   }
   dl = jd.plugins.BrowserAdapter.openDownload(br, downloadLink, url);
   if (dl.getConnection().isContentDisposition()
       || (dl.getConnection().getContentType() != null
           && dl.getConnection().getContentType().contains("octet-stream"))) {
     try {
       validateLastChallengeResponse();
     } catch (final Throwable e) {
     }
     dl.startDownload();
   } else {
     try {
       invalidateLastChallengeResponse();
     } catch (final Throwable e) {
     }
     br.followConnection();
     errorHandling(br, downloadLink, null, null);
     throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
   }
 }
Example #15
0
  public void doFree(
      final DownloadLink downloadLink,
      final boolean resumable,
      final int maxchunks,
      final String directlinkproperty)
      throws Exception, PluginException {
    br.setFollowRedirects(false);
    String passCode = null;
    // First, bring up saved final links
    String dllink = checkDirectLink(downloadLink, directlinkproperty);
    // Second, check for streaming links on the first page
    if (dllink == null) dllink = getDllink();
    // Third, do they provide video hosting?
    if (dllink == null && VIDEOHOSTER) {
      // jwplayer - http://vdoreel.com/test/ExorcomPlayer.swf
      final Browser brv = br.cloneBrowser();
      brv.getPage(
          COOKIE_HOST
              + "/xml2/"
              + new Regex(downloadLink.getDownloadURL(), "([a-z0-9]+)$").getMatch(0)
              + ".xml");
      String a = brv.getRegex("CDATA\\[([^\\]]+={0,2})").getMatch(0);
      if (a == null || a.length() < 10) {
        logger.warning("Can't find 'a'");
        throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
      }
      try {
        Cipher c = Cipher.getInstance("DES/ECB/PKCS5Padding");
        /* CHECK: we should always use getBytes("UTF-8") or with wanted charset, never system charset! */
        SecretKeySpec keySpec = new SecretKeySpec("N%66=]H6".getBytes(), "DES");
        c.init(Cipher.DECRYPT_MODE, keySpec);
        /* CHECK: we should always use new String (bytes,charset) to avoid issues with system charset and utf-8 */
        dllink = new String(c.doFinal(Base64.decode(a.substring(0, a.length() - 6))));
      } catch (Throwable e) {
      }
    }
    // Fourth, continue like normal.
    if (dllink == null) {
      checkErrors(downloadLink, false, passCode);
      final Form download1 = getFormByKey("op", "download1");
      if (download1 != null) {
        download1.remove("method_premium");
        // 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
        sendForm(download1);
        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);
      // 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
        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 PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
          final jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br);
          final String id = new Regex(correctedBR, "\\?k=([A-Za-z0-9%_\\+\\- ]+)\"").getMatch(0);
          if (id == null) throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
          rc.setId(id);
          rc.load();
          final File cf = rc.downloadCaptcha(getLocalCaptchaFile());
          final String c = getCaptchaCode(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 often skippable for reCaptcha handling */
          skipWaittime = true;
        } else if (br.containsHTML("solvemedia\\.com/papi/")) {
          logger.info("Detected captcha method \"solvemedia\" for this host");
          final PluginForDecrypt solveplug = JDUtilities.getPluginForDecrypt("linkcrypt.ws");
          final jd.plugins.decrypter.LnkCrptWs.SolveMedia sm =
              ((jd.plugins.decrypter.LnkCrptWs) solveplug).getSolveMedia(br);
          final File cf = sm.downloadCaptcha(getLocalCaptchaFile());
          final String code = getCaptchaCode(cf, downloadLink);
          final String chid = sm.getChallenge(code);
          dlForm.put("adcopy_challenge", chid);
          dlForm.put("adcopy_response", "manual_challenge");
        }
        /* Captcha END */

        if (password) passCode = handlePassword(passCode, dlForm, downloadLink);

        if (!skipWaittime) waitTime(timeBefore, downloadLink);

        sendForm(dlForm);
        logger.info("Submitted DLForm");

        dllink = getDllink();
        if (dllink == null
            && (!br.containsHTML("<Form name=\"F1\" method=\"POST\" action=\"\"") || i == repeat)) {
          checkErrors(downloadLink, true, passCode);
          logger.warning("Final downloadlink (String is \"dllink\") regex didn't match!");
          break;
        } else if (dllink == null
            && br.containsHTML("<Form name=\"F1\" method=\"POST\" action=\"\"")) {
          dlForm = br.getFormbyProperty("name", "F1");
          continue;
        } else {
          break;
        }
      }
    }
    checkErrors(downloadLink, true, passCode);
    if (dllink == null) 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")) {
      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();
      throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
    }
    downloadLink.setProperty(directlinkproperty, dllink);
    if (passCode != null) downloadLink.setProperty("pass", passCode);
    fixFilename(downloadLink);
    try {
      // add a download slot
      controlFree(+1);
      // start the dl
      dl.startDownload();
    } finally {
      // remove download slot
      controlFree(-1);
    }
  }