コード例 #1
0
ファイル: OliveServlet.java プロジェクト: the-oem/OliVE
  private void handleSplitVideo(
      HttpServletRequest request, HttpServletResponse response, HttpSession session, String json)
      throws IOException {
    SplitVideoRequest splitVideoRequest = new Gson().fromJson(json, SplitVideoRequest.class);

    response.setContentType("text/plain");

    PrintWriter out = response.getWriter();

    if (!Security.isSafeVideoName(splitVideoRequest.arguments.video)) {
      out.println("Name of video to split is invalid.");
      log.warning("Name of video to split is invalid.");
      response.sendError(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    if (!Security.isSafeSplitTimeInSeconds(splitVideoRequest.arguments.splitTimeInSeconds)) {
      out.println("Split time (in seconds) is invalid.");
      log.warning("Split time (in seconds) is invalid.");
      response.sendError(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    int projectId = getProjectIdFromSessionAttributes(session);
    int videoId = DatabaseApi.getVideoId(splitVideoRequest.arguments.video, projectId);
    Video[] videoFragments =
        ZencoderApi.split(videoId, splitVideoRequest.arguments.splitTimeInSeconds);

    for (Video videoFragment : videoFragments) { // foreach-loop
      // Give the video a name only at the last moment to prevent duplicates.
      String newVideoName =
          Security.convertToSafeAndUniqueVideoName(
              videoFragment.getName(),
              projectId); // .getName() returns the original video name at this point.
      videoFragment.setName(newVideoName); // Now, change .getName() to a unique name.

      DatabaseApi.addVideo(
          new Video(
              videoFragment.getName(),
              videoFragment.getUrl(),
              videoFragment.getIcon(),
              projectId,
              -1,
              -1,
              false)); // projectId not computed by Zencoder
    }

    out.println(
        splitVideoRequest.arguments.video
            + " split at "
            + splitVideoRequest.arguments.splitTimeInSeconds
            + " seconds successfully.");
    out.flush();
    out.close();
  }
コード例 #2
0
ファイル: OliveServlet.java プロジェクト: the-oem/OliVE
  private void handleRenameVideo(
      HttpServletRequest request, HttpServletResponse response, HttpSession session, String json)
      throws IOException {
    RenameVideoRequest renameVideoRequest = new Gson().fromJson(json, RenameVideoRequest.class);

    String newVideoName = renameVideoRequest.arguments.newVideoName;
    String oldVideoName = renameVideoRequest.arguments.oldVideoName;
    int videoId = getVideoIdFromSessionAttributes(session, oldVideoName);
    int projectId = getProjectIdFromSessionAttributes(session);
    response.setContentType("text/plain");
    PrintWriter out = response.getWriter();

    if (Security.isSafeVideoName(newVideoName)
        && Security.isUniqueVideoName(newVideoName, projectId)) {
      DatabaseApi.renameVideo(videoId, newVideoName);
      out.println(newVideoName);
    } else {
      out.println(oldVideoName);
    }
    out.flush();
    out.close();
  }