public ArrayList<DownloadLink> decryptIt(CryptedLink param, ProgressController progress)
     throws Exception {
   ArrayList<DownloadLink> decryptedLinks = new ArrayList<DownloadLink>();
   String parameter =
       "http://epicpaste.com/index.php/view/raw/"
           + new Regex(param.toString(), "([a-z0-9]+)$").getMatch(0);
   br.getPage(parameter);
   /** Link offline/invalid? */
   if (br.containsHTML(
       "(>404 Page Not Found<|>The page you requested was not found|<title>Stikked</title>)"))
     return decryptedLinks;
   final String fpName = br.getRegex("<h1>(.*?)</h1>").getMatch(0);
   final String pagePiece = br.getRegex("<pre>(.*?)</pre>").getMatch(0);
   if (pagePiece == null) {
     logger.warning("Decrypter broken for link: " + parameter);
     return null;
   }
   String[] links = HTMLParser.getHttpLinks(pagePiece, "");
   if (links == null || links.length == 0) {
     logger.warning("Decrypter broken for link: " + parameter);
     return null;
   }
   for (String singleLink : links)
     if (!new Regex(
             singleLink, "http://(www\\.)?epicpaste\\.com/index\\.php/view/(raw/)?[a-z0-9]+")
         .matches()) decryptedLinks.add(createDownloadlink(singleLink));
   if (fpName != null) {
     FilePackage fp = FilePackage.getInstance();
     fp.setName(Encoding.htmlDecode(fpName.trim()));
     fp.addLinks(decryptedLinks);
   }
   return decryptedLinks;
 }
Esempio n. 2
0
 public ArrayList<DownloadLink> decryptIt(CryptedLink param, ProgressController progress)
     throws Exception {
   ArrayList<DownloadLink> decryptedLinks = new ArrayList<DownloadLink>();
   String parameter = param.toString().replace("ultrastar-warez.com", "ultrastar-base.com");
   br.getPage(parameter);
   if (br.containsHTML(
       "(>Uploaded: 31\\.12\\.69 \\(23:00\\)<|class=\"title\"> \\- </span></td>)")) {
     logger.info("Link offline: " + parameter);
     return decryptedLinks;
   }
   String fpName = br.getRegex("<span class=\"title\">(.*?)</span>").getMatch(0);
   final String mirrors[] =
       br.getRegex(
               "<b>Download (\\d+)?:</b></td>[\t\r\n ]+<td colspan=\"4\" align=\"left\">(.*?)</td>")
           .getColumn(1);
   if (mirrors == null || mirrors.length == 0) return null;
   for (String mirror : mirrors) {
     final String[] links = HTMLParser.getHttpLinks(mirror, "");
     if (links == null || links.length == 0) continue;
     for (String dl : links) decryptedLinks.add(createDownloadlink(dl));
   }
   if (decryptedLinks.size() == 0) {
     logger.warning("Decrypter broken for link: " + parameter);
     return null;
   }
   if (fpName != null) {
     FilePackage fp = FilePackage.getInstance();
     fp.setName(fpName.trim());
     fp.addLinks(decryptedLinks);
   }
   return decryptedLinks;
 }
 public static final HashSet<String> handleBase64Decode(final String b64) {
   if (b64 == null) {
     return null;
   }
   final HashSet<String> results = new HashSet<String>();
   String finallink = b64;
   int i = 0;
   // this covers nested encoding.
   while (i < 20 && finallink != null && !new Regex(finallink, "(?:ftp|https?)://.+").matches()) {
     i++;
     // cleanup crap after padding. this can break subsequent tries
     finallink = Encoding.Base64Decode(finallink.replaceFirst("(={1,2})[\\w\\+]+$", "$1"));
     // urldecode
     if (finallink != null && new Regex(finallink, "%[0-9A-Fa-f]{2}").matches()) {
       finallink = Encoding.urlDecode(finallink, false);
     }
     // whitespace cleanup
     finallink = StringUtils.trim(finallink);
   }
   // determine multi or single result?
   final String[] multi = new Regex(finallink, "(?:https?|ftp)://").getColumn(-1);
   if (multi != null && multi.length > 1) {
     // because links might not be separated or deliminated, its best to use htmlparser
     final String[] links = HTMLParser.getHttpLinks(finallink, "");
     if (links != null) {
       for (final String link : links) {
         results.add(link);
       }
     }
   } else {
     results.add(finallink);
   }
   return results;
 }
Esempio n. 4
0
  public ArrayList<DownloadLink> decryptIt(CryptedLink param, ProgressController progress)
      throws Exception {
    ArrayList<DownloadLink> decryptedLinks = new ArrayList<DownloadLink>();
    String parameter = param.toString();
    br.setCustomCharset("windows-1251");
    br.getPage(parameter);

    final String fpName = br.getRegex("<title>(.*?)(?:&raquo;.*)</title>").getMatch(0);
    String xmlLinks =
        br.getRegex("<param [^>]*?value=\"[^\"]*?file=([a-zA-Z0-9:/\\.\\-]+)[^\"]*?\" */>")
            .getMatch(0);
    if (xmlLinks == null)
      xmlLinks =
          br.getRegex("<embed [^>]*?flashvars=\"[^\"]*?file=([a-zA-Z0-9:/\\.\\-]+)[^\"]*?\" *>")
              .getMatch(0);
    if (xmlLinks == null) return decryptedLinks;

    br.getPage(xmlLinks);
    final String xmlFile = br.toString();
    if (xmlFile == null) return decryptedLinks;

    String[] links = HTMLParser.getHttpLinks(xmlFile, "");
    if (links == null || links.length == 0) return null;

    DownloadLink dl;
    for (String elem : links) decryptedLinks.add(dl = createDownloadlink(elem));

    if (fpName != null) {
      FilePackage fp = FilePackage.getInstance();
      fp.setName(fpName.trim());
      fp.addLinks(decryptedLinks);
    }
    return decryptedLinks;
  }
Esempio n. 5
0
  // this function takes a page containing links or a description and cleans it so only interesting
  // file links remain
  private String extractLinksFromHtml(String html, String limit_to_host, String[] exclude_hosters) {
    String result = "";

    // get all links in the html

    // there is a bug in HTMLParser.getHttpLinks() - it does not handle <br/> correctly, so we must
    // take action ourselves
    html = html.replace("http://", " http://");

    // use HTMLParser.getHttpLinks to get links, maybe make our own link extractor some day
    String[] links = HTMLParser.getHttpLinks(html, null);

    // go over all links
    for (String link : links) {
      // go over all host plugins
      try {
        // HostPluginWrapper.readLock.lock();
        for (final HostPluginWrapper pHost : HostPluginWrapper.getHostWrapper()) {
          // make sure this hoster is enabled
          if (!pHost.isEnabled()) continue;

          // check if we need to ignore certain hosters
          if (exclude_hosters != null) {
            boolean in_ignore_list = false;
            for (final String exclude_hoster : exclude_hosters) {
              if (pHost.getHost().equalsIgnoreCase(exclude_hoster)) in_ignore_list = true;
            }
            if (in_ignore_list) continue;
          }

          // check if we limit to certain hosters
          if ((limit_to_host != null) && (!limit_to_host.equals(JDFeedMeFeed.HOSTER_ANY_HOSTER))) {
            if (limit_to_host.equals(JDFeedMeFeed.HOSTER_ANY_PREMIUM)) {
              // make sure we have a premium account for this hoster

              if (!pHost.isPremiumEnabled()) continue;
              Account account = AccountController.getInstance().getValidAccount(pHost.getPlugin());
              if (account == null) continue;
            } else // regular hoster limit
            {
              if (!pHost.getHost().equalsIgnoreCase(limit_to_host)) continue;
            }
          }
          if (!pHost.canHandle(link)) continue;

          // if here than this link is ok
          result += link + "\r\n";
        }
      } finally {
        // HostPluginWrapper.readLock.unlock();
      }
    }

    return result;
  }
Esempio n. 6
0
 @Override
 public void onAction(ActionEvent e) {
     StringBuilder def = new StringBuilder();
     try {
         String newText = ClipboardHandler.getClipboard().getCurrentClipboardLinks();
         String[] links = HTMLParser.getHttpLinks(newText, null);
         ArrayList<String> pws = HTMLParser.findPasswords(newText);
         for (String l : links)
             def.append(l).append("\r\n");
         for (String pw : pws) {
             def.append("password: "******"\r\n");
         }
     } catch (Exception e2) {
     }
     String link = UserIO.getInstance().requestInputDialog(UserIO.NO_COUNTDOWN | UserIO.STYLE_LARGE, _GUI._.gui_dialog_addurl_title(), _GUI._.gui_dialog_addurl_message(), def.toString(), NewTheme.I().getIcon("linkgrabber", 32), _GUI._.gui_dialog_addurl_okoption_parse(), null);
     if (link == null || link.length() == 0) return;
     if (CNL2.checkText(link)) return;
     DistributeData tmp = new DistributeData(link, false);
     tmp.setDisableDeepEmergencyScan(false);
     tmp.start();
 }
Esempio n. 7
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;
    }
  }
Esempio n. 8
0
 public String findLink() throws Exception {
   String finalLink = null;
   String[] sitelinks = HTMLParser.getHttpLinks(br.toString(), null);
   if (sitelinks == null || sitelinks.length == 0)
     throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
   for (String alink : sitelinks) {
     alink = Encoding.htmlDecode(alink);
     if (alink.contains("access_key=") || alink.contains("getfile.php?")) {
       finalLink = alink;
       break;
     }
   }
   return finalLink;
 }
Esempio n. 9
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.getRedirectLocation() != null) {
      decryptedLinks.add(createDownloadlink(br.getRedirectLocation()));
    } else {
      String fpName = br.getRegex("<h1 class=\"title\">(.*?)</h1>").getMatch(0);
      if (fpName == null)
        fpName = br.getRegex("<title>(.*?) \\- [A-Za-z0-9\\-]+ download</title>").getMatch(0);
      String textArea =
          br.getRegex(
                  "id=\"copy\\-links\" class=\"select\\-content\" wrap=\"off\">(.*?)</textarea>")
              .getMatch(0);
      String singleLink = br.getRegex("globalVar\\.url=\\'(.*?)\\'").getMatch(0);
      if (singleLink == null)
        singleLink =
            br.getRegex("<div id=\"urlHolder\" style=\"display:none\">[\t\n\r ]+<a href=\"(.*?)\"")
                .getMatch(0);
      if ((textArea == null || textArea.length() == 0) && singleLink == null) {
        logger.warning("Decrypter broken for link: " + parameter);
        return null;
      }
      if (textArea != null && textArea.length() != 0) {
        String[] links = HTMLParser.getHttpLinks(textArea, "");
        if (links == null || links.length == 0) return null;
        for (String dl : links) decryptedLinks.add(createDownloadlink(dl));
      }
      if (singleLink != null) decryptedLinks.add(createDownloadlink(singleLink));
      if (fpName != null) {
        FilePackage fp = FilePackage.getInstance();
        fp.setName(fpName.trim());
        fp.addLinks(decryptedLinks);
      }
    }

    return decryptedLinks;
  }
Esempio n. 10
0
  // @Override
  public void handleFree(DownloadLink downloadLink) throws Exception {
    requestFileInformation(downloadLink);
    /* Link holen */
    HashMap<String, String> submitvalues = HTMLParser.getInputHiddenFields(br.toString());
    postdata = "act=" + Encoding.urlEncode(submitvalues.get("act"));
    postdata = postdata + "&id=" + Encoding.urlEncode(submitvalues.get("id"));
    postdata = postdata + "&fname=" + Encoding.urlEncode(submitvalues.get("fname"));
    if (br.containsHTML("type=\"password\" name=\"password\"")) {
      String password =
          Plugin.getUserInput(
              JDL.L("plugins.hoster.speedysharecom.password", "Enter Password:"******"")) {
        postdata = postdata + "&password=" + Encoding.urlEncode(password);
      }
    }

    /* Zwangswarten, 30seks */
    sleep(30000, downloadLink);

    /* Datei herunterladen */
    jd.plugins.BrowserAdapter.openDownload(
            br, downloadLink, downloadLink.getDownloadURL(), postdata)
        .startDownload();
  }
Esempio n. 11
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);
    }
  }
Esempio n. 12
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);
   }
 }
Esempio n. 13
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();
  }
Esempio n. 14
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);
   }
 }
Esempio n. 15
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);
    }
  }
Esempio n. 16
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);
   }
 }
Esempio n. 17
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();
  }
Esempio n. 18
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();
  }