More robust handling of odd files
This commit is contained in:
parent
ffd3b7917c
commit
af986a7200
4 changed files with 30 additions and 6 deletions
|
|
@ -17,6 +17,7 @@ import javax.imageio.ImageReadParam;
|
|||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
|
||||
import com.drew.imaging.jpeg.JpegProcessingException;
|
||||
import org.forkalsrud.album.db.DirectoryProps;
|
||||
import org.forkalsrud.album.video.MovieCoder;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -60,6 +61,10 @@ public class DirectoryMetadataGenerator {
|
|||
File[] files = dir.listFiles();
|
||||
for (File f : files) {
|
||||
|
||||
if (f.length() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = f.getName();
|
||||
if (f.isDirectory()) {
|
||||
if ("CVS".equals(name)) {
|
||||
|
|
@ -80,7 +85,9 @@ public class DirectoryMetadataGenerator {
|
|||
}
|
||||
if (name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".JPG")) {
|
||||
Map<String, String> p = generateThumbnailProperties(f);
|
||||
addPropsForFile(props, f, p);
|
||||
if (p != null) {
|
||||
addPropsForFile(props, f, p);
|
||||
}
|
||||
} else if (name.endsWith(".mov") || name.endsWith(".MOV") || name.endsWith(".mp4") || name.endsWith(".m4v") || name.endsWith(".avi")) {
|
||||
Map<String, String> p = movieCoder.generateVideoProperties(f);
|
||||
addPropsForFile(props, f, p);
|
||||
|
|
@ -128,6 +135,11 @@ public class DirectoryMetadataGenerator {
|
|||
Metadata metadata;
|
||||
try {
|
||||
metadata = JpegMetadataReader.readMetadata(f);
|
||||
} catch (JpegProcessingException e) {
|
||||
// not a JPEG file
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Directory exifDirectory = metadata.getDirectory(ExifIFD0Directory.class);
|
||||
if (exifDirectory != null && exifDirectory.containsTag(ExifIFD0Directory.TAG_ORIENTATION)) {
|
||||
int orientation = exifDirectory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package org.forkalsrud.album.exif;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class SearchEngine {
|
||||
|
|
@ -8,12 +10,14 @@ public class SearchEngine {
|
|||
SearchResults results;
|
||||
LinkedList<DirectoryEntry> queue;
|
||||
|
||||
int rootPathLen;
|
||||
|
||||
public SearchEngine(DirectoryEntry root) {
|
||||
this.root = root;
|
||||
this.results = new SearchResults(root);
|
||||
this.queue = new LinkedList<DirectoryEntry>();
|
||||
this.queue.add(root);
|
||||
this.rootPathLen = root.file.getAbsolutePath().length();
|
||||
}
|
||||
|
||||
public SearchResults search(String query) {
|
||||
|
|
@ -32,7 +36,7 @@ public class SearchEngine {
|
|||
|
||||
tryAttribute(dir, dir.getName(), query);
|
||||
tryAttribute(dir, dir.getCaption(), query);
|
||||
tryAttribute(dir, dir.getPath().getAbsolutePath(), query);
|
||||
tryPath(dir, dir.getPath(), query);
|
||||
|
||||
for (Entry e : dir.getContents()) {
|
||||
if ("dir".equals(e.getType())) {
|
||||
|
|
@ -42,10 +46,14 @@ public class SearchEngine {
|
|||
FileEntry file = (FileEntry)e;
|
||||
tryAttribute(file, file.getName(), query);
|
||||
tryAttribute(file, file.getCaption(), query);
|
||||
tryAttribute(file, file.getPath().getAbsolutePath(), query);
|
||||
tryPath(file, file.getPath(), query);
|
||||
}
|
||||
}
|
||||
|
||||
void tryPath(Entry entry, File path, String query) {
|
||||
tryAttribute(entry, path.getAbsolutePath().substring(rootPathLen), query);
|
||||
}
|
||||
|
||||
void tryAttribute(Entry entry, String attr, String query) {
|
||||
if (isMatch(attr, query)) {
|
||||
results.addMatch(entry);
|
||||
|
|
|
|||
|
|
@ -197,7 +197,11 @@ public class MovieCoder {
|
|||
props.put("orientation", orientation);
|
||||
}
|
||||
|
||||
props.put("dimensions", userData.get("ImageSize").toString());
|
||||
Object imageSize = userData.get("ImageSize");
|
||||
if (imageSize == null) {
|
||||
imageSize = props.get("ImageWidth") + "x" + props.get("ImageHeight");
|
||||
}
|
||||
props.put("dimensions", imageSize.toString());
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
|
||||
props.put("captureDate", sdf.format(new Date(f.lastModified())));
|
||||
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ $(function() {
|
|||
|
||||
var gridDiv = $("<div class=\"grid\">\n"
|
||||
+ " <span class=\"name\">" + entry.name + "</span><br/>\n"
|
||||
+ " <div class=\"imgborder\"><a class=\"ss\" id=\"ent" + idx + "\" href=\"/photo/album" + entry.path + "?size=" + picSize + "\" title=\"" + entry.name + "\">"
|
||||
+ "<img class=\"" + entry.type + "pic\" src=\"/photo/album" + (entry.thumbtype == "movie" ? entry.path + ".frame" : entry.path) + "?size=" + thmb + "\" border=\"0\" width=\"" + dim.w + "\" height=\"" + dim.h + "\"/></a></div>\n"
|
||||
+ " <div class=\"imgborder\"><a class=\"ss\" id=\"ent" + idx + "\" href=\"/photo/album" + encodeURIComponent(entry.path) + "?size=" + picSize + "\" title=\"" + entry.name + "\">"
|
||||
+ "<img class=\"" + entry.type + "pic\" src=\"/photo/album" + (entry.thumbtype == "movie" ? encodeURIComponent(entry.path) + ".frame" : encodeURIComponent(entry.path)) + "?size=" + thmb + "\" border=\"0\" width=\"" + dim.w + "\" height=\"" + dim.h + "\"/></a></div>\n"
|
||||
+ "</div>\n");
|
||||
|
||||
var captionP = $("<p id=\"" + entry.name + "\" class=\"caption\"></p>\n");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue