Ejemplo n.º 1
0
 /**
  * Holt den Dateinamen aus einem Content-Disposition header. wird dieser nicht gefunden, wird der
  * dateiname aus der url ermittelt
  *
  * @param urlConnection
  * @return Filename aus dem header (content disposition) extrahiert
  */
 public static String getFileNameFromHeader(final URLConnectionAdapter urlConnection) {
   if (urlConnection.getHeaderField("Content-Disposition") == null
       || urlConnection.getHeaderField("Content-Disposition").indexOf("filename") < 0) {
     return Plugin.getFileNameFromURL(urlConnection.getURL());
   }
   return Plugin.getFileNameFromDispositionHeader(
       urlConnection.getHeaderField("Content-Disposition"));
 }
Ejemplo n.º 2
0
 @Override
 public void handlePremium(final DownloadLink downloadLink, final Account account)
     throws Exception {
   checkLinks(new DownloadLink[] {downloadLink});
   if (downloadLink.isAvailabilityStatusChecked() && !downloadLink.isAvailable()) {
     throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
   }
   if (getPluginConfig().getBooleanProperty(HotFileCom.TRY_IWL_BYPASS, false)) {
     logger.severe("trying iwl-bypass");
     handlePremiumWebsite(downloadLink, account);
     return;
   }
   final HashMap<String, String> params = new HashMap<String, String>();
   params.put("link", Encoding.urlEncode(downloadLink.getDownloadURL() + "\n\r"));
   params.put("alllinks", "1");
   final HashMap<String, String> info = callAPI(null, "getdirectdownloadlink", account, params);
   logger.severe("HotFileDebug(Download): " + info.get("httpresponse"));
   if (info.get("httpresponse").contains("file was deleted")) {
     throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
   }
   if (info.get("httpresponse").contains("file not found")) {
     throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
   }
   if (info.get("httpresponse").contains("premium required")) {
     throw new PluginException(LinkStatus.ERROR_PREMIUM, PluginException.VALUE_ID_PREMIUM_DISABLE);
   }
   final String finalUrls = info.get("httpresponse").trim();
   if (finalUrls == null || finalUrls.startsWith(".")) {
     if (finalUrls != null) {
       if (finalUrls.startsWith(".too many failed")) {
         logger.severe(
             "api reports: too many failed logins(check logins)! using website fallback!");
         handlePremiumWebsite(downloadLink, account);
         return;
       }
       if (finalUrls.startsWith(".ip blocked")) {
         logger.severe("api reports: ip blocked! using website fallback!");
         handlePremiumWebsite(downloadLink, account);
         return;
       }
       if (finalUrls.startsWith(".server that hosts the file is temporarily")) {
         throw new PluginException(
             LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE,
             "Server temporarily unavailable",
             30 * 60 * 1000l);
       }
     }
     logger.severe(finalUrls);
     throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
   }
   final String dlUrls[] = Regex.getLines(finalUrls);
   final StringBuilder errorSb = new StringBuilder("");
   if (dlUrls == null || dlUrls.length == 0) {
     throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
   }
   boolean contentHeader = false;
   for (final String url : dlUrls) {
     if (!url.startsWith("http")) {
       errorSb.append(url + "\n\r");
       continue;
     }
     dl =
         jd.plugins.BrowserAdapter.openDownload(
             br,
             downloadLink,
             url,
             true,
             getPluginConfig().getBooleanProperty(HotFileCom.UNLIMITEDMAXCON, false) == true
                 ? 0
                 : -5);
     if (!dl.getConnection().isContentDisposition()) {
       br.followConnection();
       errorSb.append(br.toString() + "\n\r");
     } else {
       contentHeader = true;
       break;
     }
   }
   if (contentHeader) {
     /* filename workaround , MAYBE no longer needed because of api */
     String urlFileName = Plugin.getFileNameFromURL(new URL(br.getURL()));
     urlFileName = Encoding.htmlDecode(urlFileName);
     downloadLink.setFinalFileName(urlFileName);
     dl.startDownload();
   } else {
     logger.info("APIDebug:" + errorSb.toString());
     /* try website workaround */
     handlePremiumWebsite(downloadLink, account);
   }
 }
Ejemplo n.º 3
0
 public void handlePremiumWebsite(final DownloadLink downloadLink, final Account account)
     throws Exception {
   loginWebsite(account);
   String finalUrl = null;
   br.getPage(downloadLink.getDownloadURL());
   if (br.getRedirectLocation() != null) {
     finalUrl = br.getRedirectLocation();
   } else {
     if (br.containsHTML("span>Free</span")) {
       throw new PluginException(
           LinkStatus.ERROR_PREMIUM,
           "ISP blocked by Hotfile, Premium not possible",
           PluginException.VALUE_ID_PREMIUM_TEMP_DISABLE);
     }
     finalUrl =
         br.getRegex(
                 "<h3 style='margin-top: 20px'><a href=\"(.*?hotfile.*?)\">Click here to download</a></h3>")
             .getMatch(0);
     if (finalUrl == null) {
       finalUrl =
           br.getRegex("table id=\"download_file\".*?<a href=\"(.*?)\"").getMatch(0); /* polish */
     }
   }
   br.setFollowRedirects(true);
   if ("http://hotfile.com/".equals(br.getURL()))
     throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
   if (finalUrl == null) {
     throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
   }
   // Set the meximum connections per file
   dl =
       jd.plugins.BrowserAdapter.openDownload(
           br,
           downloadLink,
           finalUrl,
           true,
           getPluginConfig().getBooleanProperty(HotFileCom.UNLIMITEDMAXCON, false) == true
               ? 0
               : -5);
   if (!dl.getConnection().isContentDisposition()) {
     br.followConnection();
     finalUrl =
         br.getRegex(
                 "<h3 style='margin-top: 20px'><a href=\"(.*?hotfile.*?)\">Click here to download</a></h3>")
             .getMatch(0);
     if (finalUrl == null) {
       finalUrl =
           br.getRegex("table id=\"download_file\".*?<a href=\"(.*?)\"").getMatch(0); /* polish */
     }
     if (finalUrl == null) {
       throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
     }
     dl =
         jd.plugins.BrowserAdapter.openDownload(
             br,
             downloadLink,
             finalUrl,
             true,
             getPluginConfig().getBooleanProperty(HotFileCom.UNLIMITEDMAXCON, false) == true
                 ? 0
                 : -5);
   }
   if (!dl.getConnection().isContentDisposition()) {
     br.followConnection();
     throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
   }
   /* filename workaround */
   String urlFileName = Plugin.getFileNameFromURL(new URL(br.getURL()));
   urlFileName = Encoding.htmlDecode(urlFileName);
   downloadLink.setFinalFileName(urlFileName);
   dl.startDownload();
 }
Ejemplo n.º 4
0
  @Override
  public void handleFree(final DownloadLink link) throws Exception {
    directDownload = false;
    /*
     * for free users we dont use api filecheck, cause we have to call
     * website anyway
     */
    requestFileInformation(link);
    if ("http://hotfile.com/".equals(br.getURL()))
      throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
    if (directDownload) {
      logger.info("use directdownload");
      /* use directDownloadLink */
      br.setFollowRedirects(true);
      try {
        /* first retry with resume allowed */
        dl =
            jd.plugins.BrowserAdapter.openDownload(
                br,
                link,
                link.getDownloadURL(),
                true,
                getPluginConfig().getBooleanProperty(HotFileCom.UNLIMITEDMAXCON, false) == true
                    ? 0
                    : -5);
      } catch (final Throwable e) {
        try {
          dl.getConnection().disconnect();
        } catch (final Throwable e2) {
        }
        /* then try with resume disallowed */
        /* reset chunks */
        link.setChunksProgress(null);
        dl = jd.plugins.BrowserAdapter.openDownload(br, link, link.getDownloadURL(), false, 1);
      }
    } else {
      /* fetch link from website */
      if (br.containsHTML("You are currently downloading")) {
        throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, 5 * 60 * 1000l);
      }
      if (br.containsHTML("starthtimer\\(\\)")) {
        final String waittime =
            br.getRegex("starthtimer\\(\\).*?timerend=.*?\\+(\\d+);").getMatch(0);
        if (Long.parseLong(waittime.trim()) > 0) {
          throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, Long.parseLong(waittime.trim()));
        }
      }
      int tries = getPluginConfig().getIntegerProperty(HotFileCom.CAPTCHARETRIES, 20);
      while (true) {
        final Form[] forms = br.getForms();
        if (br.containsHTML("Could not open socket"))
          throw new PluginException(
              LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "ServerError", 15 * 60 * 1000l);
        final Form form = forms[1];
        long sleeptime = 0;
        try {
          sleeptime =
              Long.parseLong(br.getRegex("timerend=d\\.getTime\\(\\)\\+(\\d+);").getMatch(0)) + 1;
          // for debugging purposes
          logger.info("Regexed waittime is " + sleeptime + " seconds");
        } catch (final Exception e) {
          logger.info("WaittimeRegex broken");
          logger.info(br.toString());
          sleeptime = 60 * 1000l;
        }
        // Reconnect if the waittime is too big!
        if (sleeptime > 100 * 1000l) {
          throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, sleeptime);
        }
        /* 2secs more as extra buffer */
        this.sleep(sleeptime + 2000, link);
        submit(br, form);
        // captcha
        if (!br.containsHTML("Click here to download")) {
          final PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
          final jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br);
          rc.handleAuto(this, link);

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

        break;
      }
      String dl_url =
          br.getRegex("<h3 style='margin-top: 20px'><a href=\"(.*?)\">Click here to download</a>")
              .getMatch(0);
      if (dl_url == null) {
        dl_url =
            br.getRegex("table id=\"download_file\".*?<a href=\"(.*?)\"").getMatch(0); /* polish */
      }
      if (dl_url == null) {
        if (!br.containsHTML("(Click here to download)")) {
          throw new PluginException(LinkStatus.ERROR_CAPTCHA);
        }
        if (br.containsHTML("name=waithash"))
          throw new PluginException(
              LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "ServerError,Waittime again", 30 * 1000l);
        throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
      }
      br.setFollowRedirects(true);
      br.setDebug(true);
      dl = jd.plugins.BrowserAdapter.openDownload(br, link, dl_url, false, 1);
      if (!dl.getConnection().isContentDisposition()) {
        br.followConnection();
        if (br.containsHTML("Invalid link")) {
          final String newLink = br.getRegex("href=\"(http://.*?)\"").getMatch(0);
          if (newLink != null) {
            /* set new downloadlink */
            logger.warning("invalid link -> use new link");
            link.setUrlDownload(newLink.trim());
            throw new PluginException(LinkStatus.ERROR_RETRY);
          }
        }
        if (br.containsHTML(">Your download expired, try again<"))
          throw new PluginException(
              LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE,
              "Download-Session expired",
              10 * 60 * 1000l);
        if (br.containsHTML("You are currently downloading")) {
          throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, 5 * 60 * 1000l);
        }
        throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
      }
      /* filename workaround */
      String urlFileName = Plugin.getFileNameFromURL(new URL(br.getURL()));
      urlFileName = Encoding.htmlDecode(urlFileName);
      link.setFinalFileName(urlFileName);
    }
    dl.startDownload();
  }