<artifactId>svjatoslavcommons</artifactId>
<version>1.7</version>
</dependency>
-
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.tika</groupId>
+ <artifactId>tika-core</artifactId>
+ <version>1.18</version>
+ </dependency>
</dependencies>
<build>
import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension;
import eu.svjatoslav.meviz.htmlindexer.metadata.DirectoryMetadata;
-import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.AbstractFile;
-import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.DirectoryFile;
-import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.GeneralFile;
-import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture;
+import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.*;
import java.io.File;
import java.io.UnsupportedEncodingException;
+import static eu.svjatoslav.meviz.htmlindexer.Constants.SUPPORTED_IMAGE_EXTENSIONS;
+import static eu.svjatoslav.meviz.htmlindexer.Constants.SUPPORTED_VIDEO_EXTENSIONS;
+
public abstract class AbstractIndexer {
public static boolean isImage(final String fileExtension) {
- for (final String ext : Constants.SUPPORTED_IMAGE_EXTENSIONS)
+ for (final String ext : SUPPORTED_IMAGE_EXTENSIONS)
if (ext.equals(fileExtension))
return true;
return false;
}
- public static boolean isOgv(final String fileExtension) {
- return fileExtension.equalsIgnoreCase("ogv");
+ public static boolean isVideo(final String fileExtension) {
+ for (final String ext : SUPPORTED_VIDEO_EXTENSIONS)
+ if (ext.equals(fileExtension))
+ return true;
+ return false;
}
static boolean shallFileBeIndexed(final File file) {
for (final AbstractFile file : directory.getFiles())
if (file instanceof GeneralFile) {
- final String fileExtension = file.getFileExtension();
-
- if (isVideo(fileExtension))
- layout.enlistVideo(file);
- else
- layout.enlistFile(file, directory);
-
- } else if (file instanceof Picture)
+ layout.enlistFile(file, directory);
+ } else if (file instanceof Picture){
layout.enlistImage((Picture) file, directory);
- else if (file instanceof DirectoryFile)
+ } else if (file instanceof Video){
+ layout.enlistVideo((Video) file);
+ } else if (file instanceof DirectoryFile)
layout.enlistDirectory(file, directory);
-
}
public abstract String getDirectoryUrl(final AbstractFile directory,
public abstract String getThumbnailUrl(Picture picture,
final Dimension desiredDimension, IndexingContext context);
- public static String getVideoType(String fileExtension) {
- switch (fileExtension){
- case "ogv":
- return "video/ogg";
- case "webm":
- return "video/webm";
- case "mp4":
- return "video/mp4";
- default:
- return null;
- }
- }
-
- public boolean isVideo(String fileExtension){
- return getVideoType(fileExtension) != null;
- }
}
*/
public static final String HTML_MAGIC_STRING = "DirListGen";
- public static final String HTML_MEMO = "Directory Listing Generator by Svjatoslav Agejenko. E-mail: svjatoslav@svjatoslav.eu, homepage: http://svjatoslav.eu";
+ public static final String HTML_MEMO = "Directory Listing Generator by Svjatoslav Agejenko. " +
+ "E-mail: svjatoslav@svjatoslav.eu, homepage: http://svjatoslav.eu";
- public static final String[] SUPPORTED_IMAGE_EXTENSIONS = {"jpg", "jpeg",
- "png", "gif"};
+ public static final String[] SUPPORTED_IMAGE_EXTENSIONS = {
+ "jpg", "jpeg", "png", "gif"};
+
+ public static final String[] SUPPORTED_VIDEO_EXTENSIONS = {
+ "avi", "mp4", "mpeg", "mpg", "mkv", "flv", "ogv"};
public static final String THUMBNAIL_VERSION = "2";
for (final File file : directoryToIndex.listFiles())
if (shallFileBeIndexed(file)) {
- metadata.ensureFileMetainfoIsUpToDate(directoryToIndex, file);
+ metadata.ensureFileMetadataIsUpToDate(directoryToIndex, file);
if (file.isDirectory())
new FilesystemIndexer(file, commandlineHandler,
import eu.svjatoslav.meviz.htmlindexer.metadata.DirectoryMetadata;
import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.AbstractFile;
import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture;
+import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Video;
-import java.io.IOException;
import java.util.List;
/**
/**
* Enlist video file.
*/
- void enlistVideo(AbstractFile file);
+ void enlistVideo(Video file);
/**
* Return layout specific suffix that will be appended between
/**
* After necessary files have been enlisted for particular directory, use
* this method to retrieve generated HTML result.
- *
- * @throws IOException
*/
String getHtml(final boolean showTitle,
final boolean doHtmlHeaderAndFooter, DirectoryMetadata metadata)
import eu.svjatoslav.meviz.htmlindexer.layouts.MixedLayout;
-import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.util.HashSet;
import java.util.zip.CRC32;
-public class Utils {
+import static javax.imageio.ImageIO.read;
- private static final String UTF_8 = "UTF-8";
+public class Utils {
private static File lastLoadedFile;
private static BufferedImage lastLoadedBufferedImage;
return lastLoadedBufferedImage;
System.out.println("Loading image: " + file.getPath());
- lastLoadedBufferedImage = ImageIO.read(file);
+ lastLoadedBufferedImage = read(file);
lastLoadedFile = file;
if (lastLoadedBufferedImage == null) {
import eu.svjatoslav.meviz.htmlindexer.metadata.DirectoryMetadata;
import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.AbstractFile;
import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture;
+import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Video;
import org.apache.log4j.Logger;
import java.io.IOException;
import java.util.List;
import static eu.svjatoslav.commons.file.FilePathParser.getFileNameWithoutExtension;
-import static eu.svjatoslav.meviz.htmlindexer.AbstractIndexer.getVideoType;
import static eu.svjatoslav.meviz.htmlindexer.Utils.urlEncode;
public class MixedLayout implements Layout {
}
@Override
- public void enlistVideo(AbstractFile file) {
+ public void enlistVideo(Video video) {
filesHtml.append("<div style=\"margin: 30px; clear: both;\">\n");
// watchable video
filesHtml.append(" <video width=\"640\" controls>\n");
- filesHtml.append(" <source src=\"" + getFileUrl(file) + "\" type=\""
- + getVideoType(file.getFileExtension()) + "\"/>\n");
+ filesHtml.append(" <source src=\"" + getFileUrl(video) + "\" type=\"" + video.mimeType + "\"/>\n");
filesHtml.append(" </video>\n");
filesHtml.append(" <br/>\n");
// video title
filesHtml.append(" Video: <b>"
- + getFileNameWithoutExtension(file.fileName)
+ + getFileNameWithoutExtension(video.fileName)
+ "<b/> ");
// video download link
- filesHtml.append(" <a href=\"" + getFileUrl(file) + "\">download</a>\n");
+ filesHtml.append(" <a href=\"" + getFileUrl(video) + "\">download</a>\n");
filesHtml.append("</div>\n");
package eu.svjatoslav.meviz.htmlindexer.metadata;
import eu.svjatoslav.commons.file.FilePathParser;
-import eu.svjatoslav.meviz.htmlindexer.AbstractIndexer;
import eu.svjatoslav.meviz.htmlindexer.FileSortComparator;
import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.*;
import java.io.Serializable;
import java.util.*;
+import static eu.svjatoslav.meviz.htmlindexer.AbstractIndexer.isImage;
+import static eu.svjatoslav.meviz.htmlindexer.AbstractIndexer.isVideo;
+
/**
* Corresponds to single filesystem directory.
*/
while (fileIterator.hasNext()) {
final AbstractFile file = fileIterator.next();
- if (!file.isMetaInfoVerified())
+ if (!file.isMetadataVerified())
fileIterator.remove();
}
}
- public void ensureFileMetainfoIsUpToDate(final File parentDirectory,
+ public void ensureFileMetadataIsUpToDate(final File parentDirectory,
final File file) throws Exception {
final String fileName = file.getName();
if (fileNameToFileMap.containsKey(fileName)) {
- final boolean metainfoUpdated = fileNameToFileMap.get(fileName)
- .ensureFileMetainfoIsUpToDate(parentDirectory);
+ final boolean metadataUpdated = fileNameToFileMap.get(fileName)
+ .ensureFileMetadataIsUpToDate(parentDirectory);
- if (metainfoUpdated)
+ if (metadataUpdated)
changed = true;
} else
registerFile(parentDirectory, file);
final String fileExtension = FilePathParser.getFileExtension(fileName)
.toLowerCase();
- if (AbstractIndexer.isImage(fileExtension))
+ if (isImage(fileExtension))
try {
return new Picture(parentDirectory, fileName);
} catch (final Exception exception) {
return new GeneralFile(parentDirectory, fileName);
}
+ if (isVideo(fileExtension))
+ try {
+ return new Video(parentDirectory, fileName);
+ } catch (final Exception exception) {
+ // in case video decoding failed, handle it as general file
+ return new GeneralFile(parentDirectory, fileName);
+ }
+
if (fileName.endsWith(".meviz.org"))
return new MevizSpecialFile(parentDirectory, fileName);
public void removeUnusedMetadataEntries() {
- new HashSet<>(fileNameToFileMap.keySet()).stream().filter(key -> !fileNameToFileMap.get(key).isMetaInfoVerified()).forEach(key -> {
+ new HashSet<>(fileNameToFileMap.keySet()).stream().filter(key -> !fileNameToFileMap.get(key).isMetadataVerified()).forEach(key -> {
fileNameToFileMap.remove(key);
changed = true;
});
*/
private long fileLength = -1;
- private transient boolean metaInfoVerified;
+ private transient boolean metadataVerified;
AbstractFile(final File parentDirectory, final String fileName)
throws Exception {
this.fileName = fileName;
- ensureFileMetainfoIsUpToDate(parentDirectory);
+ ensureFileMetadataIsUpToDate(parentDirectory);
}
/**
* @return <code>true</code> if file metadata was updated.
*/
- public boolean ensureFileMetainfoIsUpToDate(final File parentDirectory)
+ public boolean ensureFileMetadataIsUpToDate(final File parentDirectory)
throws Exception {
- if (!isMetainfoUpToDate(parentDirectory)) {
+ if (!isMetadataUpToDate(parentDirectory)) {
fileLength = getFile(parentDirectory).length();
- updateFileMetainfo(parentDirectory);
- metaInfoVerified = true;
+ updateFileMetadata(parentDirectory);
+ metadataVerified = true;
return true;
}
return false;
return fileLength;
}
- private boolean isMetainfoUpToDate(final java.io.File parentDirectory) {
+ private boolean isMetadataUpToDate(final java.io.File parentDirectory) {
- if (metaInfoVerified)
+ if (metadataVerified)
return true;
final File file = getFile(parentDirectory);
if (file.length() != fileLength)
return false;
- metaInfoVerified = true;
+ metadataVerified = true;
return true;
}
- public boolean isMetaInfoVerified() {
- return metaInfoVerified;
+ public boolean isMetadataVerified() {
+ return metadataVerified;
}
- protected abstract void updateFileMetainfo(final File parentDirectory)
- throws Exception;
+ protected abstract void updateFileMetadata(final File parentDirectory) throws Exception;
}
}
@Override
- protected void updateFileMetainfo(final File parentDirectory)
+ protected void updateFileMetadata(final File parentDirectory)
throws IOException {
}
}
@Override
- protected void updateFileMetainfo(final File parentDirectory)
+ protected void updateFileMetadata(final File parentDirectory)
throws IOException {
}
}
@Override
- protected void updateFileMetainfo(final File parentDirectory)
+ protected void updateFileMetadata(final File parentDirectory)
throws IOException {
fileContent = IOHelper
import java.util.ArrayList;
import java.util.List;
+import static eu.svjatoslav.meviz.htmlindexer.Utils.getBufferedImage;
+
public class Picture extends AbstractFile {
private static final long serialVersionUID = -4156533490858298387L;
try {
- final BufferedImage inputImage = Utils.getBufferedImage(inputFile);
+ final BufferedImage inputImage = getBufferedImage(inputFile);
final java.awt.Dimension sourceImageDimension = new java.awt.Dimension(
inputImage.getWidth(), inputImage.getHeight());
}
@Override
- public void updateFileMetainfo(final File parentDirectory) throws Exception {
- final BufferedImage image = Utils
- .getBufferedImage(getFile(parentDirectory));
+ public void updateFileMetadata(final File parentDirectory) throws Exception {
+ final BufferedImage image = getBufferedImage(getFile(parentDirectory));
dimensions = new Dimension(image.getWidth(), image.getHeight());
}
--- /dev/null
+package eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes;
+
+import org.apache.tika.Tika;
+
+import java.io.File;
+
+public class Video extends AbstractFile {
+
+ public String mimeType;
+
+ public Video(File parentDirectory, String fileName) throws Exception {
+ super(parentDirectory, fileName);
+ }
+
+ @Override
+ protected void updateFileMetadata(File parentDirectory) throws Exception {
+ File file = getFile(parentDirectory);
+ Tika tika = new Tika();
+ mimeType = tika.detect(file);
+ System.out.println("Detected video type: " + mimeType);
+ }
+}