@Override
 public AccountInfo fetchAccountInfo(final Account account) throws Exception {
   AccountInfo ai = new AccountInfo();
   /* reset maxPrem workaround on every fetchaccount info */
   try {
     synchronized (account) {
       String token = api_getAccessToken(account, false);
       String tokenType = null;
       try {
         tokenType = api_getTokenType(account, token, true);
       } catch (final PluginException e) {
         token = api_getAccessToken(account, false);
         tokenType = api_getTokenType(account, token, true);
       }
       if ("free".equals(tokenType)) {
         /* free user */
         ai.setStatus("Free accounts are not supported");
         account.setValid(false);
         account.setProperty("token", null);
         account.setProperty("tokenType", null);
       } else if ("premium".equals(tokenType)) {
         String traffic = br.getRegex("traffic_left\":\\s*?\"?(\\d+)").getMatch(0);
         long max = 100 * 1024 * 1024 * 1024l;
         long current = Long.parseLong(traffic);
         ai.setTrafficMax(Math.max(max, current));
         ai.setTrafficLeft(current);
         String expireDate = br.getRegex("account_premium\":\\s*?\"?(\\d+)").getMatch(0);
         ai.setValidUntil(Long.parseLong(expireDate) * 1000);
         if (current <= 0 || br.containsHTML("download_available\":false")) {
           String refreshIn = br.getRegex("traffic_reset\":\\s*?(\\d+)").getMatch(0);
           if (refreshIn != null) {
             account.setProperty(
                 "PROPERTY_TEMP_DISABLED_TIMEOUT", Long.parseLong(refreshIn) * 1000);
           } else {
             account.setProperty("PROPERTY_TEMP_DISABLED_TIMEOUT", Property.NULL);
           }
           logger.info("Download_available: " + br.containsHTML("download_available\":true"));
           throw new PluginException(
               LinkStatus.ERROR_PREMIUM, PluginException.VALUE_ID_PREMIUM_TEMP_DISABLE);
         }
         ai.setStatus("Premium account");
         if (!ai.isExpired()) account.setValid(true);
       } else {
         throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
       }
     }
   } catch (final PluginException e) {
     account.setProperty("token", null);
     account.setProperty("tokenType", null);
     throw e;
   }
   return ai;
 }
Beispiel #2
0
  private void loginAPI(Account account, AccountInfo ai) throws IOException, PluginException {
    synchronized (LOGINLOCK) {
      workAroundTimeOut(br);
      if (ai == null) {
        ai = account.getAccountInfo();
        if (ai == null) {
          ai = new AccountInfo();
          account.setAccountInfo(ai);
        }
      }
      br.getPage("http://www.zevera.com/");
      String res =
          br.getPage(
              "http://www.zevera.com/jDownloader.ashx?cmd=accountinfo&login="******"&pass="******"user.language");
      if ("No trafic".equals(res) || res == null || res.trim().length() == 0) {
        if ("de".equalsIgnoreCase(lang)) {
          throw new PluginException(
              LinkStatus.ERROR_PREMIUM,
              "\r\nUngültiger Benutzername/Passwort oder Traffic aufgebraucht!\r\nSchnellhilfe: \r\nDu bist dir sicher, dass dein eingegebener Benutzername und Passwort stimmen?\r\nFalls dein Passwort Sonderzeichen enthält, ändere es und versuche es erneut!",
              PluginException.VALUE_ID_PREMIUM_DISABLE);
        } else {
          throw new PluginException(
              LinkStatus.ERROR_PREMIUM,
              "\r\nInvalid username/password or no traffic left!\r\nQuick help:\r\nYou're sure that the username and password you entered are correct?\r\nIf your password contains special characters, change it (remove them) and try again!",
              PluginException.VALUE_ID_PREMIUM_DISABLE);
        }
      }
      res = res.trim();
      account.setValid(true);
      if ("Login Error".equalsIgnoreCase(res)) {
        ai.setStatus("Unknown user");
        if ("de".equalsIgnoreCase(lang)) {
          throw new PluginException(
              LinkStatus.ERROR_PREMIUM,
              "\r\nUngültiger Benutzername oder ungültiges Passwort!\r\nSchnellhilfe: \r\nDu bist dir sicher, dass dein eingegebener Benutzername und Passwort stimmen?\r\nFalls dein Passwort Sonderzeichen enthält, ändere es und versuche es erneut!",
              PluginException.VALUE_ID_PREMIUM_DISABLE);
        } else {
          throw new PluginException(
              LinkStatus.ERROR_PREMIUM,
              "\r\nInvalid username/password!\r\nQuick help:\r\nYou're sure that the username and password you entered are correct?\r\nIf your password contains special characters, change it (remove them) and try again!",
              PluginException.VALUE_ID_PREMIUM_DISABLE);
        }
      } else {
        /* normal premium */
        // 0 DayTrafficLimit:5120,
        // 1 EndSubscriptionDate:2012/6/29 0:0:0,
        // 2 TrafficUsedToday:0,
        // 3 AvailableTodayTraffic5120,
        // 4 OronDayTrafficLimit:5120
        ai.setStatus("Premium");
        String infos[] = br.getRegex("(.*?)(,|$)").getColumn(0);
        if (infos == null || infos.length != 6) {
          logger.info(br.toString());
        }
        String EndSubscriptionDate = new Regex(infos[1], "EndSubscriptionDate:(.+)").getMatch(0);
        ai.setValidUntil(
            TimeFormatter.getMilliSeconds(EndSubscriptionDate, "yyyy/MM/dd HH:mm:ss", null));

        /* Traffic balance not working in Zevera JD API */
        // Integer DayTraffic = Integer.parseInt(new
        // Regex(infos[0],"DayTrafficLimit:(.+)").getMatch(0).trim());
        // Integer TrafficUsedToday = Integer.parseInt(new
        // Regex(infos[0],"TrafficUsedToday:(.+)").getMatch(0).trim());
        // Integer Balance = DayTraffic - TrafficUsedToday;
        // ai.setAccountBalance(Balance * 1024);
        String AvailableTodayTraffic =
            new Regex(infos[3], "AvailableTodayTraffic:(\\d+)").getMatch(0);
        logger.info("Zevera: AvailableTodayTraffic=" + AvailableTodayTraffic);
        ai.setTrafficLeft(SizeFormatter.getSize(AvailableTodayTraffic + "mb"));
        if (ai.isExpired()) {
          if ("de".equalsIgnoreCase(lang)) {
            throw new PluginException(
                LinkStatus.ERROR_PREMIUM,
                "\r\nAccount abgelaufen!",
                PluginException.VALUE_ID_PREMIUM_DISABLE);
          } else {
            throw new PluginException(
                LinkStatus.ERROR_PREMIUM,
                "\r\nAccount expired!",
                PluginException.VALUE_ID_PREMIUM_DISABLE);
          }
        }
      }
    }
  }