示例#1
0
  @Override
  public void handlePremium(final DownloadLink downloadLink, final Account account)
      throws Exception {
    this.br.forceDebug(true);
    this.workAroundTimeOut(this.br);

    /* TODO: remove me after 0.9xx public */
    if ("MD5NOTFOUND".equalsIgnoreCase(downloadLink.getMD5Hash())) {
      downloadLink.setMD5Hash(null);
    }
    /* we need file size to calculate left traffic */
    if (downloadLink.getDownloadSize() <= 0) {
      this.requestFileInformation(downloadLink);
    }
    try {
      this.br.forceDebug(true);

      Request request = null;

      this.accName = account.getUser();
      /* synchronized check of account, package handling */
      synchronized (Rapidshare.LOCK) {
        this.br = this.login(account, false);
      }
      this.br.setFollowRedirects(false);

      RSLink link = null;
      try {
        link = RSLink.parse(downloadLink);
      } catch (final NumberFormatException e) {
        /* invalid link format */
        throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
      }
      String query =
          "https://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=download&try=1&fileid="
              + link.getId()
              + "&filename="
              + link.getName()
              + "&cookie="
              + account.getProperty("cookie");
      /* needed for secured links */
      if (link.getSecMD5() != null) {
        query += "&seclinkmd5=" + link.getSecMD5();
      }
      if (link.getSecTimout() != null) {
        query += "&seclinktimeout=" + link.getSecTimout();
      }
      this.queryAPI(this.br, query, account);
      this.handleErrors(this.br);

      String host = this.br.getRegex("DL:(.*?),").getMatch(0);

      // this might bypass some isps limit restrictions on rapidshare host
      // names
      if (this.getPluginConfig().getBooleanProperty(Rapidshare.PRE_RESOLVE, false)) {
        try {
          logger.fine("Try to resolve adress " + host);
          final InetAddress inetAddress = InetAddress.getByName(host);
          host = inetAddress.getHostAddress();
        } catch (final Exception e) {
          JDLogger.exception(e);
        }
      }
      String directurl =
          "https://"
              + host
              + "/cgi-bin/rsapi.cgi?sub=download&bin=1&noflvheader=1&fileid="
              + link.getId()
              + "&filename="
              + link.getName()
              + "&cookie="
              + account.getProperty("cookie");
      /* needed for secured links */
      if (link.getSecMD5() != null) {
        directurl += "&seclinkmd5=" + link.getSecMD5();
      }
      if (link.getSecTimout() != null) {
        directurl += "&seclinktimeout=" + link.getSecTimout();
      }

      br.setFollowRedirects(true);
      dl = jd.plugins.BrowserAdapter.openDownload(br, downloadLink, directurl, true, 0);
      URLConnectionAdapter urlConnection = dl.getConnection();
      /*
       * Download starten prüft ob ein content disposition header
       * geschickt wurde. Falls nicht, ist es eintweder eine Bilddatei
       * oder eine Fehlerseite. BIldfiles haben keinen Cache-Control
       * Header
       */
      if (!urlConnection.isContentDisposition()
          && urlConnection.getHeaderField("Cache-Control") != null) {
        // Lädt die zuletzt aufgebaute vernindung
        this.br.setRequest(request);
        this.br.followConnection();

        // Fehlerbehanldung
        /*
         * Achtung! keine Parsing arbeiten an diesem String!!!
         */

        this.reportUnknownError(this.br.toString(), 6);
        throw new PluginException(LinkStatus.ERROR_RETRY);
      }
      this.dl.startDownload();
    } finally {
      if (!downloadLink.getLinkStatus().hasStatus(LinkStatus.FINISHED)) {
        this.accName = null;
        // rs api does not return 416 error for bad ranges
        if ((JDL.L("download.error.message.rangeheaderparseerror", "Unexpected rangeheader format:")
                + "null")
            .equals(downloadLink.getLinkStatus().getErrorMessage())) {
          downloadLink.setChunksProgress(null);
          throw new PluginException(LinkStatus.ERROR_DOWNLOAD_FAILED, "Too many Chunks");
        }
      }
      if (account == Rapidshare.dummyAccount) {
        downloadLink
            .getLinkStatus()
            .setStatusText(
                JDL.LF("plugins.host.rapidshare.loadedvia", "Loaded via %s", "DirectDownload"));
      } else {
        downloadLink
            .getLinkStatus()
            .setStatusText(
                JDL.LF("plugins.host.rapidshare.loadedvia", "Loaded via %s", account.getUser()));
      }
    }
  }
示例#2
0
  @Override
  public void handleFree(final DownloadLink downloadLink) throws Exception {
    this.accName = "FreeUser";
    if ("MD5NOTFOUND".equalsIgnoreCase(downloadLink.getMD5Hash())) {
      downloadLink.setMD5Hash(null);
    }
    this.workAroundTimeOut(this.br); /* TODO: remove me after 0.9xx public */
    /* we need file size to calculate left traffic */
    if (downloadLink.getDownloadSize() <= 0) {
      this.requestFileInformation(downloadLink);
    }
    try {

      this.br.setFollowRedirects(false);
      RSLink link = null;
      try {
        link = RSLink.parse(downloadLink);
      } catch (final NumberFormatException e) {
        /* invalid link format */
        throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
      }
      String query =
          "http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=download&try=1&fileid="
              + link.getId()
              + "&filename="
              + link.getName();
      /* needed for secured links */
      if (link.getSecMD5() != null) {
        query += "&seclinkmd5=" + link.getSecMD5();
      }
      if (link.getSecTimout() != null) {
        query += "&seclinktimeout=" + link.getSecTimout();
      }
      this.queryAPI(this.br, query, null);
      this.handleErrors(this.br);
      // RS URL wird aufgerufen
      // this.br.getPage(link);
      final String host = this.br.getRegex("DL:(.*?),").getMatch(0);
      final String auth = this.br.getRegex("DL:(.*?),(.*?),").getMatch(1);
      final String wait = this.br.getRegex("DL:(.*?),(.*?),(\\d+)").getMatch(2);
      if (wait == null) throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
      this.sleep(Long.parseLong(wait) * 1000l, downloadLink);

      String directurl =
          "http://"
              + host
              + "/cgi-bin/rsapi.cgi?sub=download&dlauth="
              + auth
              + "&bin=1&noflvheader=1&fileid="
              + link.getId()
              + "&filename="
              + link.getName();
      /* needed for secured links */
      if (link.getSecMD5() != null) {
        directurl += "&seclinkmd5=" + link.getSecMD5();
      }
      if (link.getSecTimout() != null) {
        directurl += "&seclinktimeout=" + link.getSecTimout();
      }
      logger.finest("Direct-Download: Server-Selection not available!");

      br.setFollowRedirects(true);
      try {
        br.setVerbose(true);
      } catch (Throwable e) {
        /* only available after 0.9xx version */
      }
      dl = jd.plugins.BrowserAdapter.openDownload(br, downloadLink, directurl, true, 1);
      URLConnectionAdapter urlConnection = dl.getConnection();
      if (!urlConnection.isContentDisposition()
          && urlConnection.getHeaderField("Cache-Control") != null) {
        urlConnection.disconnect();
        throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, 10 * 60 * 1000l);
      }
      this.dl.startDownload();
    } finally {
      if (!downloadLink.getLinkStatus().hasStatus(LinkStatus.FINISHED)) {
        this.accName = null;
      }
    }
  }