Ejemplo n.º 1
0
 @Override
 public AccountInfo fetchAccountInfo(final Account account) throws Exception {
   try {
     this.login(account, true);
   } catch (final PluginException e) {
     if (e.getValue() != PluginException.VALUE_ID_PREMIUM_TEMP_DISABLE) {
       if (account.getAccountInfo() == null) {
         account.setAccountInfo(new AccountInfo());
       }
       account.getAccountInfo().setStatus(e.getErrorMessage());
       account.setValid(false);
     }
     return account.getAccountInfo();
   }
   return account.getAccountInfo();
 }
Ejemplo n.º 2
0
  /** no override to keep plugin compatible to old stable */
  @SuppressWarnings("deprecation")
  public void handleMultiHost(final DownloadLink link, final Account account) throws Exception {

    synchronized (hostUnavailableMap) {
      HashMap<String, Long> unavailableMap = hostUnavailableMap.get(account);
      if (unavailableMap != null) {
        Long lastUnavailable = unavailableMap.get(link.getHost());
        if (lastUnavailable != null && System.currentTimeMillis() < lastUnavailable) {
          final long wait = lastUnavailable - System.currentTimeMillis();
          throw new PluginException(
              LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE,
              "Host is temporarily unavailable via " + this.getHost(),
              wait);
        } else if (lastUnavailable != null) {
          unavailableMap.remove(link.getHost());
          if (unavailableMap.size() == 0) {
            hostUnavailableMap.remove(account);
          }
        }
      }
    }

    String user = Encoding.urlEncode(account.getUser());
    String pw = Encoding.urlEncode(account.getPass());
    String url = Encoding.urlEncode(link.getDownloadURL());
    br.setFollowRedirects(true);
    br.setConnectTimeout(90 * 1000);
    br.setReadTimeout(90 * 1000);
    dl = null;
    showMessage(link, "Phase 1/2: Get download link");
    String genlink =
        br.getPage(
            "http://www."
                + hostPublicDomain
                + "/api/get_ddl.php?login="******"&password="******"&url="
                + url);
    String maxChunksString = br.getRequest().getResponseHeader("X-MaxChunks");
    // Tested with share-online.biz: max 4 chunks possible
    int maxChunks = 1;
    if (link.getBooleanProperty(NOCHUNKS, false)) {
      maxChunks = 1;
    } else if (maxChunksString != null) {
      try {
        maxChunks = -(Integer.parseInt(maxChunksString));
      } catch (final Throwable e) {
        logger.severe(e.getMessage());
      }
    }
    if (!genlink.startsWith("http://")) {
      logger.severe(hostPublicDomain + "(Error): " + genlink);
      /*
       * after x retries we disable this host and retry with normal plugin
       */
      if (link.getLinkStatus().getRetryCount() >= 3) {
        /* reset retry counter */
        link.getLinkStatus().setRetryCount(0);
        /* disable hoster for one hour */
        tempUnavailableHoster(account, link, 60 * 60 * 1000);
      }
      String msg = "(" + link.getLinkStatus().getRetryCount() + 1 + "/" + 3 + ")";
      throw new PluginException(
          LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Retry in few secs" + msg, 10 * 1000l);
    }
    showMessage(link, "Phase 2/2: Start download...");
    dl = jd.plugins.BrowserAdapter.openDownload(br, link, genlink, true, maxChunks);
    if (dl.getConnection().getResponseCode() == 404) {
      /* file offline */
      dl.getConnection().disconnect();
      throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
    }
    final String serverfilename = getFileNameFromHeader(dl.getConnection());
    if ("Too_many_open_connections.txt".equals(serverfilename)) {
      logger.info("received 'Too_many_open_connections.txt' as server filename...");
      /* unknown error, we disable multiple chunks */
      if (link.getBooleanProperty(StreamManiaCom.NOCHUNKS, false) == false) {
        link.setProperty(StreamManiaCom.NOCHUNKS, Boolean.valueOf(true));
        throw new PluginException(LinkStatus.ERROR_RETRY);
      } else {
        throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, 5 * 60 * 1000l);
      }
    }
    if (!dl.getConnection().isContentDisposition()) {
      /* unknown error */
      br.followConnection();
      logger.severe(hostPublicDomain + "(Error): " + br.toString());
      /* disable for 20 min */
      tempUnavailableHoster(account, link, 20 * 60 * 1000);
    }
    if (dl.getConnection().getContentType().contains("html")) {
      logger.warning("final downloadlink leads to html code...");
      br.followConnection();
      logger.info(this.getHost() + ": unknowndlerror");
      int timesFailed = link.getIntegerProperty("timesfailed" + FAIL_STRING + "_unknowndlerror", 1);
      link.getLinkStatus().setRetryCount(0);
      if (timesFailed <= 20) {
        timesFailed++;
        link.setProperty("timesfailed" + FAIL_STRING + "_unknowndlerror", timesFailed);
        throw new PluginException(LinkStatus.ERROR_RETRY, "Unknown download error");
      } else {
        link.setProperty("timesfailed" + FAIL_STRING + "_unknowndlerror", Property.NULL);
        logger.info(this.getHost() + ": unknowndlerror --> Remporarily desabling current host");
        tempUnavailableHoster(account, link, 60 * 60 * 1000);
      }
    }
    try {
      if (!this.dl.startDownload()) {
        try {
          if (dl.externalDownloadStop()) {
            return;
          }
        } catch (final Throwable e) {
        }
        /* unknown error, we disable multiple chunks */
        if (link.getBooleanProperty(StreamManiaCom.NOCHUNKS, false) == false) {
          link.setProperty(StreamManiaCom.NOCHUNKS, Boolean.valueOf(true));
          throw new PluginException(LinkStatus.ERROR_RETRY);
        }
      }
    } catch (final PluginException e) {
      // New V2 errorhandling
      /* unknown error, we disable multiple chunks */
      if (e.getLinkStatus() != LinkStatus.ERROR_RETRY
          && link.getBooleanProperty(StreamManiaCom.NOCHUNKS, false) == false) {
        link.setProperty(StreamManiaCom.NOCHUNKS, Boolean.valueOf(true));
        throw new PluginException(LinkStatus.ERROR_RETRY);
      }
      throw e;
    }
  }
Ejemplo n.º 3
0
  @Override
  public void handleFree(final DownloadLink downloadLink) throws Exception, PluginException {
    requestFileInformation(downloadLink);
    String passCode = downloadLink.getStringProperty("pass", null);
    DLLINK = checkDirectLink(downloadLink, "panbaidudirectlink");
    if (DLLINK == null) {
      final String original_url = downloadLink.getStringProperty("mainLink", null);
      final String shareid = downloadLink.getStringProperty("origurl_shareid", null);
      final String uk = downloadLink.getStringProperty("origurl_uk", null);
      final String link_password = downloadLink.getStringProperty("important_link_password", null);
      final String link_password_cookie =
          downloadLink.getStringProperty("important_link_password_cookie", null);
      if (link_password_cookie != null) {
        br.setCookie("http://pan.baidu.com/", "BDCLND", link_password_cookie);
      }
      br.getPage(original_url);

      /* Experimental code */
      final String i_frame =
          br.getRegex(
                  "<iframe src=\"(http://pan\\.baidu\\.com/share/link\\?shareid=\\d+\\&uk=\\d+\\&t=[A-Za-z0-9]+)\"")
              .getMatch(0);
      if (i_frame != null) {
        logger.info("Found i_frame - accessing it!");
        br.getPage(i_frame);
      } else {
        logger.info("Found no i_frame");
      }

      /* Fallback handling if the password cookie didn't work */
      if (link_password != null
          && br.getURL().matches(TYPE_FOLDER_LINK_NORMAL_PASSWORD_PROTECTED)) {
        br.postPage(
            "http://pan.baidu.com/share/verify?"
                + "vcode=&shareid="
                + shareid
                + "&uk="
                + uk
                + "&t="
                + System.currentTimeMillis(),
            "&pwd=" + Encoding.urlEncode(link_password));
        if (!br.containsHTML("\"errno\":0")) {
          // Wrong password -> Impossible
          logger.warning(
              "pan.baidu.com: Couldn't download password protected link even though the password is given...");
          throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
        }
        br.getPage(original_url);
      }
      final String sign = br.getRegex("FileUtils\\.share_sign=\"([a-z0-9]+)\"").getMatch(0);
      final String tsamp = br.getRegex("FileUtils\\.share_timestamp=\"(\\d+)\"").getMatch(0);
      if (sign == null || tsamp == null) {
        throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
      }
      final String fsid = downloadLink.getStringProperty("important_fsid", null);
      final String postLink =
          "http://pan.baidu.com/share/download?channel=chunlei&clienttype=0&web=1&uk="
              + uk
              + "&shareid="
              + shareid
              + "&timestamp="
              + tsamp
              + "&sign="
              + sign
              + "&bdstoken=null&channel=chunlei&clienttype=0&web=1";
      br.getHeaders().put("X-Requested-With", "XMLHttpRequest");
      br.postPage(postLink, "fid_list=%5B" + fsid + "%5D");
      String code = null;
      for (int i = 1; i <= 3; i++) {
        final String captchaLink = getJson("img");
        if (captchaLink == null) {
          break;
        }
        final String captchaid = new Regex(captchaLink, "([A-Z0-9]+)$").getMatch(0);
        try {
          code = getCaptchaCode(captchaLink, downloadLink);
        } catch (final Throwable e) {
          logger.info("Captcha download failed -> Retrying!");
          throw new PluginException(LinkStatus.ERROR_RETRY, "Captcha download failed");
        }
        br.postPage(
            postLink,
            "fid_list=%5B"
                + fsid
                + "%5D&input="
                + Encoding.urlEncode(code)
                + "&vcode="
                + captchaid);
      }
      if (getJson("img") != null) {
        throw new PluginException(LinkStatus.ERROR_CAPTCHA);
      }
      if (br.containsHTML("\"errno\":\\-20")) {
        handlePluginBroken(downloadLink, "unknownerror20", 3);
      } else if (br.containsHTML("\"errno\":112")) {
        handlePluginBroken(downloadLink, "unknownerror112", 3);
      }
      DLLINK = getJson("dlink");
      if (DLLINK == null) {
        throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
      }
    }

    int maxChunks = 0;
    if (downloadLink.getBooleanProperty(NOCHUNKS, false)) {
      maxChunks = 1;
    }

    dl = jd.plugins.BrowserAdapter.openDownload(br, downloadLink, DLLINK, true, maxChunks);
    if (dl.getConnection().getContentType().contains("html")) {
      br.followConnection();
      throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
    }
    downloadLink.setFinalFileName(Encoding.htmlDecode(getFileNameFromHeader(dl.getConnection())));
    if (passCode != null) {
      downloadLink.setProperty("pass", passCode);
    }
    downloadLink.setProperty("panbaidudirectlink", DLLINK);
    try {
      if (!this.dl.startDownload()) {
        try {
          if (dl.externalDownloadStop()) {
            return;
          }
        } catch (final Throwable e) {
        }
        /* unknown error, we disable multiple chunks */
        if (downloadLink.getBooleanProperty(PanBaiduCom.NOCHUNKS, false) == false) {
          downloadLink.setProperty(PanBaiduCom.NOCHUNKS, Boolean.valueOf(true));
          throw new PluginException(LinkStatus.ERROR_RETRY);
        }
      }
    } catch (final PluginException e) {
      // New V2 errorhandling
      /* unknown error, we disable multiple chunks */
      if (e.getLinkStatus() != LinkStatus.ERROR_RETRY
          && downloadLink.getBooleanProperty(PanBaiduCom.NOCHUNKS, false) == false) {
        downloadLink.setProperty(PanBaiduCom.NOCHUNKS, Boolean.valueOf(true));
        throw new PluginException(LinkStatus.ERROR_RETRY);
      }
      throw e;
    }
  }
Ejemplo n.º 4
0
  @Override
  public void handleFree(final DownloadLink downloadLink) throws Exception, PluginException {
    requestFileInformation(downloadLink);
    String dllink =
        br.getRegex("\"(https?://[a-z0-9\\-_]+\\.sharesend\\.com/download\\?[^<>\"]*?)\"")
            .getMatch(0);
    if (dllink == null) {
      throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
    }
    dllink = Encoding.htmlDecode(dllink);
    /* Fix dllink */
    final String ctype = new Regex(dllink, "content_type=([^<>\"]*?)&").getMatch(0);
    if (ctype != null) {
      dllink = dllink.replace(ctype, Encoding.urlEncode(ctype));
    }

    /* Waittime is skippable */
    // final String waittime = br.getRegex("<span>(\\d+)</span> seconds</p>").getMatch(0);
    // int wait = 5;
    // if (waittime != null) wait = Integer.parseInt(waittime);
    // sleep(wait * 1001l, downloadLink);

    int maxChunks = 0;
    if (downloadLink.getBooleanProperty(NOCHUNKS, false)) {
      maxChunks = 1;
    }

    dl = jd.plugins.BrowserAdapter.openDownload(br, downloadLink, dllink, true, maxChunks);
    if (dl.getConnection().getContentType().contains("html")) {
      br.followConnection();
      /* Usually happens when we try with too many connections (refering to simultan downloads) */
      if (br.containsHTML("\"error_code\": 2")) {
        throw new PluginException(
            LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Server error", 5 * 60 * 1000l);
      }
      throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
    }
    try {
      if (!this.dl.startDownload()) {
        try {
          if (dl.externalDownloadStop()) {
            return;
          }
        } catch (final Throwable e) {
        }
        /* unknown error, we disable multiple chunks */
        if (downloadLink.getBooleanProperty(ShareSendCom.NOCHUNKS, false) == false) {
          downloadLink.setProperty(ShareSendCom.NOCHUNKS, Boolean.valueOf(true));
          throw new PluginException(LinkStatus.ERROR_RETRY);
        }
      }
    } catch (final PluginException e) {
      // New V2 errorhandling
      /* unknown error, we disable multiple chunks */
      if (e.getLinkStatus() != LinkStatus.ERROR_RETRY
          && downloadLink.getBooleanProperty(ShareSendCom.NOCHUNKS, false) == false) {
        downloadLink.setProperty(ShareSendCom.NOCHUNKS, Boolean.valueOf(true));
        throw new PluginException(LinkStatus.ERROR_RETRY);
      }
      throw e;
    }
  }
  /** no override to keep plugin compatible to old stable */
  public void handleMultiHost(final DownloadLink link, final Account acc) throws Exception {
    login(acc, true);
    String dllink = checkDirectLink(link, "premiumaxnetdirectlink");
    if (dllink == null) {
      br.getHeaders().put("Accept", "*/*");
      br.getHeaders().put("X-Requested-With", "XMLHttpRequest");
      br.postPage(
          "http://www.premiumax.net/direct_link.html?rand=0." + System.currentTimeMillis(),
          "captcha=&key=indexKEY&urllist=" + Encoding.urlEncode(link.getDownloadURL()));
      if (br.containsHTML("temporary problem")) {
        logger.info(
            "Current hoster is temporarily not available via premiumax.net -> Disabling it");
        tempUnavailableHoster(acc, link, 60 * 60 * 1000l);
      } else if (br.containsHTML("You do not have the rights to download from")) {
        logger.info(
            "Current hoster is not available via this premiumax.net account -> Disabling it");
        tempUnavailableHoster(acc, link, 60 * 60 * 1000l);
      } else if (br.containsHTML("We do not support your link")) {
        logger.info("Current hoster is not supported by premiumax.net -> Disabling it");
        tempUnavailableHoster(acc, link, 3 * 60 * 60 * 1000l);
      } else if (br.containsHTML("You only can download")) {
        /* We're too fast - usually this should not happen */
        throw new PluginException(
            LinkStatus.ERROR_RETRY, "Too many connections active, try again in some seconds...");
      } else if (br.containsHTML("> Our server can\\'t connect to")) {
        logger.info(NICE_HOST + ": cantconnect");
        int timesFailed = link.getIntegerProperty(NICE_HOSTproperty + "timesfailed_cantconnect", 0);
        link.getLinkStatus().setRetryCount(0);
        if (timesFailed <= 10) {
          timesFailed++;
          link.setProperty(NICE_HOSTproperty + "timesfailed_cantconnect", timesFailed);
          logger.info(NICE_HOST + ": cantconnect -> Retrying");
          throw new PluginException(LinkStatus.ERROR_RETRY, "cantconnect");
        } else {
          link.setProperty(NICE_HOSTproperty + "timesfailed_cantconnect", Property.NULL);
          logger.info(NICE_HOST + ": cantconnect - disabling current host!");
          tempUnavailableHoster(acc, link, 30 * 60 * 1000l);
        }
      }

      dllink = br.getRegex("\"(http://(www\\.)?premiumax\\.net/dl/[a-z0-9]+/?)\"").getMatch(0);
      if (dllink == null) {
        logger.info(NICE_HOST + ": dllinknullerror");
        int timesFailed =
            link.getIntegerProperty(NICE_HOSTproperty + "timesfailed_dllinknullerror", 0);
        link.getLinkStatus().setRetryCount(0);
        if (timesFailed <= 2) {
          timesFailed++;
          link.setProperty(NICE_HOSTproperty + "timesfailed_dllinknullerror", timesFailed);
          logger.info(NICE_HOST + ": dllinknullerror -> Retrying");
          throw new PluginException(LinkStatus.ERROR_RETRY, "dllinknullerror");
        } else {
          link.setProperty(NICE_HOSTproperty + "timesfailed_dllinknullerror", Property.NULL);
          logger.info(NICE_HOST + ": dllinknullerror - disabling current host!");
          tempUnavailableHoster(acc, link, 60 * 60 * 1000l);
        }
      }
    }

    int maxChunks = 0;
    if (link.getBooleanProperty(PremiumaxNet.NOCHUNKS, false)) {
      maxChunks = 1;
    }

    dl = jd.plugins.BrowserAdapter.openDownload(br, link, dllink, true, maxChunks);
    if (dl.getConnection().getContentType().contains("html")) {
      br.followConnection();
      logger.info("Unhandled download error on premiumax.net: " + br.toString());
      throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
    }
    link.setProperty("premiumaxnetdirectlink", dllink);
    try {
      if (!this.dl.startDownload()) {
        try {
          if (dl.externalDownloadStop()) return;
        } catch (final Throwable e) {
        }
        /* unknown error, we disable multiple chunks */
        if (link.getBooleanProperty(PremiumaxNet.NOCHUNKS, false) == false) {
          link.setProperty(PremiumaxNet.NOCHUNKS, Boolean.valueOf(true));
          throw new PluginException(LinkStatus.ERROR_RETRY);
        }
      }
    } catch (final PluginException e) {
      // New V2 errorhandling
      /* unknown error, we disable multiple chunks */
      if (e.getLinkStatus() != LinkStatus.ERROR_RETRY
          && link.getBooleanProperty(PremiumaxNet.NOCHUNKS, false) == false) {
        link.setProperty(PremiumaxNet.NOCHUNKS, Boolean.valueOf(true));
        throw new PluginException(LinkStatus.ERROR_RETRY);
      }
      throw e;
    }
  }