@Override
 public void generateThumbnailsFrom(File video) {
   if (video.exists() && video.isFile()) {
     MetaData metadata = MetadataExtractor.getInstance().extractMetadata(video);
     TimeData timeData = metadata.getDuration();
     if (timeData != null) {
       File thumbnailDir = video.getParentFile();
       for (ThumbnailPeriod thumbPeriod : ThumbnailPeriod.ALL_VALIDS) {
         double timePeriod = thumbPeriod.getPercent() * timeData.getTimeAsLong() / 1000;
         FFmpegUtil.extractVideoThumbnail(
             video, new File(thumbnailDir, thumbPeriod.getFilename()), (int) timePeriod);
       }
     } else {
       SilverTrace.warn(
           "VideoTool",
           getClass().getSimpleName(),
           "Problem to retrieve video duration, process video thumbnails has failed");
     }
   }
 }
Exemplo n.º 2
0
  /**
   * Method declaration
   *
   * @param req
   * @param res
   * @throws IOException
   * @throws ServletException
   * @see
   */
  @Override
  public void doPost(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    SilverTrace.info("attachment", "DragAndDrop.doPost", "root.MSG_GEN_ENTER_METHOD");
    HttpRequest request = HttpRequest.decorate(req);
    if (!request.isContentInMultipart()) {
      res.getOutputStream().println("SUCCESS");
      return;
    }

    String userId = req.getParameter("UserId");
    try {
      request.setCharacterEncoding(CharEncoding.UTF_8);
      String componentId = request.getParameter("ComponentId");
      String id = request.getParameter("PubId");
      String lang = I18NHelper.checkLanguage(request.getParameter("lang"));
      SilverTrace.info(
          "attachment",
          "DragAndDrop.doPost",
          "root.MSG_GEN_PARAM_VALUE",
          "componentId = " + componentId + ", id = " + id + ", userId = " + userId);
      boolean bIndexIt = StringUtil.getBooleanValue(request.getParameter("IndexIt"));

      List<FileItem> items = request.getFileItems();
      for (FileItem item : items) {
        SilverTrace.info(
            "attachment",
            "DragAndDrop.doPost",
            "root.MSG_GEN_PARAM_VALUE",
            "item = " + item.getFieldName());
        SilverTrace.info(
            "attachment",
            "DragAndDrop.doPost",
            "root.MSG_GEN_PARAM_VALUE",
            "item = " + item.getName() + "; " + item.getString(CharEncoding.UTF_8));

        if (!item.isFormField()) {
          String fileName = item.getName();
          if (fileName != null) {
            String mimeType = FileUtil.getMimeType(fileName);
            SilverTrace.info(
                "attachment",
                "DragAndDrop.doPost",
                "root.MSG_GEN_PARAM_VALUE",
                "item size = " + item.getSize());
            // create AttachmentDetail Object
            SimpleDocument document =
                new SimpleDocument(
                    new SimpleDocumentPK(null, componentId),
                    id,
                    0,
                    false,
                    new SimpleAttachment(
                        fileName,
                        lang,
                        null,
                        null,
                        item.getSize(),
                        mimeType,
                        userId,
                        new Date(),
                        null));
            document.setDocumentType(determineDocumentType(request));
            File tempFile = File.createTempFile("silverpeas_", fileName);
            try {
              FileUploadUtil.saveToFile(tempFile, item);
              MetadataExtractor extractor = MetadataExtractor.getInstance();
              MetaData metadata = extractor.extractMetadata(tempFile);
              document.setSize(tempFile.length());
              document.setTitle(metadata.getTitle());
              document.setDescription(metadata.getSubject());
              document =
                  AttachmentServiceFactory.getAttachmentService()
                      .createAttachment(document, tempFile, bIndexIt);
            } finally {
              FileUtils.deleteQuietly(tempFile);
            }
            // Specific case: 3d file to convert by Actify Publisher
            ActifyDocumentProcessor.getProcessor().process(document);
          }
        }
      }
    } catch (Exception e) {
      SilverTrace.error("attachment", "DragAndDrop.doPost", "ERREUR", e);
      final StringBuilder sb = new StringBuilder("ERROR: ");
      final String errorMessage =
          SilverpeasTransverseWebErrorUtil.performAppletAlertExceptionMessage(
              e, UserDetail.getById(userId).getUserPreferences().getLanguage());
      if (StringUtil.isDefined(errorMessage)) {
        sb.append(errorMessage);
      } else {
        sb.append(e.getMessage());
      }
      res.getOutputStream().println(sb.toString());
      return;
    }
    res.getOutputStream().println("SUCCESS");
  }