예제 #1
0
 private static String get(int hashCode, String userId, String tweetTime) {
   StringBuilder sb = new StringBuilder();
   List<Entry> entries = entryDAO.getEntry(hashCode, userId, tweetTime);
   for (Entry entry : entries) {
     String textDecoded = StringEscapeUtils.unescapeJava(entry.getTweetText());
     entry.setTweetText(textDecoded);
     sb.append(entry.toString());
   }
   return sb.toString();
 }
예제 #2
0
  /** {@inheritDoc} */
  @Override
  public void afterStatement(Statement statement, Scope scope, Throwable exception) {
    try {
      for (VariableReference var : statement.getVariableReferences()) {
        if (var.equals(statement.getReturnValue())
            || var.equals(statement.getReturnValue().getAdditionalVariableReference())) continue;
        Object object = var.getObject(scope);

        if (var.isPrimitive()) {
          ConstantValue value = new ConstantValue(test, var.getGenericClass());
          value.setValue(object);
          // logger.info("Statement before inlining: " + statement.getCode());
          statement.replace(var, value);
          // logger.info("Statement after inlining: " + statement.getCode());
        } else if (var.isString() && object != null) {
          ConstantValue value = new ConstantValue(test, var.getGenericClass());
          try {
            String val = StringEscapeUtils.unescapeJava(object.toString());
            value.setValue(val);
            statement.replace(var, value);
          } catch (IllegalArgumentException e) {
            // Exceptions may happen if strings are not valid unicode
            logger.info("Cannot escape invalid string: " + object);
          }
          // logger.info("Statement after inlining: " + statement.getCode());
        } else if (var.isArrayIndex()) {
          // If this is an array index and there is an object outside the array
          // then replace the array index with that object
          for (VariableReference otherVar : scope.getElements(var.getType())) {
            Object otherObject = otherVar.getObject(scope);
            if (otherObject == object
                && !otherVar.isArrayIndex()
                && otherVar.getStPosition() < statement.getPosition()) {
              statement.replace(var, otherVar);
              break;
            }
          }
        } else {
          // TODO: Ignoring exceptions during getObject, but keeping the assertion for now
          if (object == null) {
            ConstantValue value = new ConstantValue(test, var.getGenericClass());
            value.setValue(null);
            // logger.info("Statement before inlining: " + statement.getCode());
            statement.replace(var, value);
            // logger.info("Statement after inlining: " + statement.getCode());
          }
        }
      }
    } catch (CodeUnderTestException e) {
      logger.warn("Not inlining test: " + e.getCause());
      // throw new AssertionError("This case isn't handled yet: " + e.getCause()
      //        + ", " + Arrays.asList(e.getStackTrace()));
    }
  }
  private static String getAnimeInformation(int animeID) {
    URL url; // The URL to read
    HttpURLConnection conn = null; // The actual connection to the web page
    BufferedReader rr; // Used to read results from the web page
    String line; // An individual line of the web page HTML
    String result = ""; // A long string containing all the HTML
    try {
      url = new URL(ANI_BASEURL + ANIMEDATA + animeID + "?access_token=" + ConnectionManager.token);
      conn = (HttpURLConnection) url.openConnection();
      conn.setDoOutput(true);
      conn.setConnectTimeout(15 * 1000);
      conn.setRequestMethod("GET");
      conn.setRequestProperty("User-Agent", "My Anime Manager");
      conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
      rr = new BufferedReader(new InputStreamReader(conn.getInputStream()));
      while ((line = rr.readLine()) != null) result += line;
      rr.close();
    } catch (java.net.SocketTimeoutException timeout) {
      JOptionPane.showMessageDialog(
          AnimeIndex.frame,
          "Errore durante la connessione! Potrebbe dipendere dalla tua connessione o dal sito di Anilist.",
          "Errore!",
          JOptionPane.ERROR_MESSAGE);
    } catch (Exception e) {
      try {
        if (conn.getResponseCode() == 401) {
          System.out.println("Errore 401");
          System.out.println("Token scaduto, richiesta nuovo token");
          ConnectionManager.tokenExpired = true;
          attempts++;
          if (attempts > 5) {
            ConnectAndGetToken();
            getAnimeInformation(animeID);
            attempts = 0;
          } else
            JOptionPane.showMessageDialog(
                AnimeIndex.frame,
                "Errore durante la connessione! Potrebbe dipendere dalla tua connessione o dal sito di Anilist.",
                "Errore!",
                JOptionPane.ERROR_MESSAGE);
        } else {
          e.printStackTrace();
          MAMUtil.writeLog(e);
        }
      } catch (IOException e1) {

        e1.printStackTrace();
        MAMUtil.writeLog(e1);
      }
    }
    result = StringEscapeUtils.unescapeJava(result);
    return result;
  }
  public void formatFieldComment(FieldDetails fieldDetails) {
    // If a comment was defined, we need to format it
    if (fieldDetails.getComment() != null) {

      // First replace all "" with the proper escape sequence \"
      String unescapedMultiLineComment = fieldDetails.getComment().replaceAll("\"\"", "\\\\\"");

      // Then unescape all characters
      unescapedMultiLineComment = StringEscapeUtils.unescapeJava(unescapedMultiLineComment);

      CommentFormatter commentFormatter = new CommentFormatter();
      String javadocComment = commentFormatter.formatStringAsJavadoc(unescapedMultiLineComment);

      fieldDetails.setComment(commentFormatter.format(javadocComment, 1));
    }
  }
  private static String getSearchedAnime(String animeToSearch) {
    if (token == null) {
      try {
        ConnectAndGetToken();
      } catch (ConnectException e) {
        MAMUtil.writeLog(e);
        e.printStackTrace();
      } catch (UnknownHostException e) {
        MAMUtil.writeLog(e);
        e.printStackTrace();
      }
    }
    URL url; // The URL to read
    HttpURLConnection conn = null; // The actual connection to the web page
    BufferedReader rr; // Used to read results from the web page
    String line; // An individual line of the web page HTML
    String result = ""; // A long string containing all the HTML
    try {
      String animeQuery =
          URLEncoder.encode(
              animeToSearch
                  .replace(".", "\\.")
                  .replace("/", "\\ ")
                  .replace("-", "\\-")
                  .replace("!", "\\!"),
              "UTF-8");

      url = new URL(ANI_BASEURL + SEARCH + animeQuery + "?access_token=" + ConnectionManager.token);

      conn = (HttpURLConnection) url.openConnection();
      conn.setDoOutput(true);
      conn.setRequestMethod("GET");
      conn.setRequestProperty("User-Agent", "My Anime Manager");
      conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
      rr = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
      while ((line = rr.readLine()) != null) result += line + "\r\n";
      rr.close();
    } catch (Exception e) {
      try {
        if (conn.getResponseCode() == 401) {
          System.out.println("Errore 401");
          System.out.println("Token scaduto, richiesta nuovo token");
          ConnectionManager.tokenExpired = true;
          attempts++;
          if (attempts > 5) {
            ConnectAndGetToken();
            AnimeSearch(animeToSearch);
            attempts = 0;
          } else
            JOptionPane.showMessageDialog(
                AnimeIndex.frame,
                "Errore durante la connessione! Potrebbe dipendere dalla tua connessione o dal sito di Anilist.",
                "Errore!",
                JOptionPane.ERROR_MESSAGE);
        } else {
          e.printStackTrace();
          MAMUtil.writeLog(e);
        }

      } catch (IOException e1) {
        MAMUtil.writeLog(e1);
        e1.printStackTrace();
      }
    }
    result = StringEscapeUtils.unescapeJava(result);
    return result;
  }
  private List<VideoDownload> extractUrlEncodedVideos(String sline, String id) throws Exception {
    List<VideoDownload> sNextVideoURL = new ArrayList<VideoDownload>();
    String[] urlStrings = sline.split("url=");

    for (String urlString : urlStrings) {
      urlString = StringEscapeUtils.unescapeJava(urlString);

      String urlFull = URLDecoder.decode(urlString, "UTF-8");

      // universal request
      {
        String url = null;
        {
          Pattern link = Pattern.compile("([^&,]*)[&,]");
          Matcher linkMatch = link.matcher(urlString);
          if (linkMatch.find()) {
            url = linkMatch.group(1);
            url = URLDecoder.decode(url, "UTF-8");
          }
        }

        String itag = null;
        {
          Pattern link = Pattern.compile("itag=(\\d+)");
          Matcher linkMatch = link.matcher(urlFull);
          if (linkMatch.find()) {
            itag = linkMatch.group(1);
          }
        }

        String sig = null;

        if (sig == null) {
          Pattern link = Pattern.compile("&signature=([^&,]*)");
          Matcher linkMatch = link.matcher(urlFull);
          if (linkMatch.find()) {
            sig = linkMatch.group(1);
          }
        }

        if (sig == null) {
          Pattern link = Pattern.compile("sig=([^&,]*)");
          Matcher linkMatch = link.matcher(urlFull);
          if (linkMatch.find()) {
            sig = linkMatch.group(1);
          }
        }

        if (sig == null) {
          Pattern link = Pattern.compile("[&,]s=([^&,]*)");
          Matcher linkMatch = link.matcher(urlFull);
          if (linkMatch.find()) {
            sig = linkMatch.group(1);
            sig = decryptSignature(sig);
          }
        }

        if (url != null && itag != null && sig != null) {
          try {
            url += "&signature=" + sig;

            addVideo(sNextVideoURL, itag, new URL(url));
            continue;
          } catch (MalformedURLException e) {
            // ignore bad urls
          }
        }
      }
    }
    return sNextVideoURL;
  }
  private List<VideoDownload> extractJsonInfo() throws Exception {
    List<VideoDownload> sNextVideoURL = new ArrayList<VideoDownload>();
    {
      Matcher matcher = patternAge.matcher(jsonConfiguration);
      if (matcher.find()) return sNextVideoURL;
    }
    {
      Matcher matcher = patternUnavailable.matcher(jsonConfiguration);
      if (matcher.find()) return sNextVideoURL;
    }

    {
      Matcher matcher = patternUrlencod.matcher(jsonConfiguration);
      if (matcher.find()) {
        String url_encoded_fmt_stream_map;
        url_encoded_fmt_stream_map = matcher.group(1);

        // normal embedded video, unable to grab age restricted videos
        Matcher encodMatch = patternUrl.matcher(url_encoded_fmt_stream_map);
        if (encodMatch.find()) {
          String sline = encodMatch.group(1);

          sNextVideoURL.addAll(extractUrlEncodedVideos(sline, id));
        }

        // stream video

        Matcher encodStreamMatch = patternStream.matcher(url_encoded_fmt_stream_map);
        if (encodStreamMatch.find()) {
          String sline = encodStreamMatch.group(1);

          String[] urlStrings = sline.split("stream=");

          for (String urlString : urlStrings) {
            urlString = StringEscapeUtils.unescapeJava(urlString);
            Matcher linkMatch = patternLink.matcher(urlString);
            if (linkMatch.find()) {
              String sparams = linkMatch.group(1);
              String itag = linkMatch.group(2);
              String url = linkMatch.group(3);

              url = "http" + url + "?" + sparams;
              url = URLDecoder.decode(url, "UTF-8");
              addVideo(sNextVideoURL, itag, new URL(url));
            }
          }
        }
      }
    }
    // adaptive trailer are kinda useless: die video stream is separated from the audio stream :(
    // {
    // Pattern urlencod = Pattern.compile("\"adaptive_fmts\": \"([^\"]*)\"");
    // Matcher urlencodMatch = urlencod.matcher(html);
    // if (urlencodMatch.find()) {
    // String adaptive_fmts;
    // adaptive_fmts = urlencodMatch.group(1);
    //
    // // normal embedded video, unable to grab age restricted videos
    // Pattern encod = Pattern.compile("url=(.*)");
    // Matcher encodMatch = encod.matcher(adaptive_fmts);
    // if (encodMatch.find()) {
    // String sline = encodMatch.group(1);
    //
    // sNextVideoURL.addAll(extractUrlEncodedVideos(sline));
    // }
    // }
    // }

    Collections.sort(sNextVideoURL, new VideoUrlComparator());

    return sNextVideoURL;
  }