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.ImageReader;
|
||||||
import javax.imageio.stream.ImageInputStream;
|
import javax.imageio.stream.ImageInputStream;
|
||||||
|
|
||||||
|
import com.drew.imaging.jpeg.JpegProcessingException;
|
||||||
import org.forkalsrud.album.db.DirectoryProps;
|
import org.forkalsrud.album.db.DirectoryProps;
|
||||||
import org.forkalsrud.album.video.MovieCoder;
|
import org.forkalsrud.album.video.MovieCoder;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
@ -60,6 +61,10 @@ public class DirectoryMetadataGenerator {
|
||||||
File[] files = dir.listFiles();
|
File[] files = dir.listFiles();
|
||||||
for (File f : files) {
|
for (File f : files) {
|
||||||
|
|
||||||
|
if (f.length() == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
String name = f.getName();
|
String name = f.getName();
|
||||||
if (f.isDirectory()) {
|
if (f.isDirectory()) {
|
||||||
if ("CVS".equals(name)) {
|
if ("CVS".equals(name)) {
|
||||||
|
|
@ -80,7 +85,9 @@ public class DirectoryMetadataGenerator {
|
||||||
}
|
}
|
||||||
if (name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".JPG")) {
|
if (name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".JPG")) {
|
||||||
Map<String, String> p = generateThumbnailProperties(f);
|
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")) {
|
} else if (name.endsWith(".mov") || name.endsWith(".MOV") || name.endsWith(".mp4") || name.endsWith(".m4v") || name.endsWith(".avi")) {
|
||||||
Map<String, String> p = movieCoder.generateVideoProperties(f);
|
Map<String, String> p = movieCoder.generateVideoProperties(f);
|
||||||
addPropsForFile(props, f, p);
|
addPropsForFile(props, f, p);
|
||||||
|
|
@ -128,6 +135,11 @@ public class DirectoryMetadataGenerator {
|
||||||
Metadata metadata;
|
Metadata metadata;
|
||||||
try {
|
try {
|
||||||
metadata = JpegMetadataReader.readMetadata(f);
|
metadata = JpegMetadataReader.readMetadata(f);
|
||||||
|
} catch (JpegProcessingException e) {
|
||||||
|
// not a JPEG file
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
Directory exifDirectory = metadata.getDirectory(ExifIFD0Directory.class);
|
Directory exifDirectory = metadata.getDirectory(ExifIFD0Directory.class);
|
||||||
if (exifDirectory != null && exifDirectory.containsTag(ExifIFD0Directory.TAG_ORIENTATION)) {
|
if (exifDirectory != null && exifDirectory.containsTag(ExifIFD0Directory.TAG_ORIENTATION)) {
|
||||||
int orientation = exifDirectory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
|
int orientation = exifDirectory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package org.forkalsrud.album.exif;
|
package org.forkalsrud.album.exif;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
public class SearchEngine {
|
public class SearchEngine {
|
||||||
|
|
@ -8,12 +10,14 @@ public class SearchEngine {
|
||||||
SearchResults results;
|
SearchResults results;
|
||||||
LinkedList<DirectoryEntry> queue;
|
LinkedList<DirectoryEntry> queue;
|
||||||
|
|
||||||
|
int rootPathLen;
|
||||||
|
|
||||||
public SearchEngine(DirectoryEntry root) {
|
public SearchEngine(DirectoryEntry root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
this.results = new SearchResults(root);
|
this.results = new SearchResults(root);
|
||||||
this.queue = new LinkedList<DirectoryEntry>();
|
this.queue = new LinkedList<DirectoryEntry>();
|
||||||
this.queue.add(root);
|
this.queue.add(root);
|
||||||
|
this.rootPathLen = root.file.getAbsolutePath().length();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SearchResults search(String query) {
|
public SearchResults search(String query) {
|
||||||
|
|
@ -32,7 +36,7 @@ public class SearchEngine {
|
||||||
|
|
||||||
tryAttribute(dir, dir.getName(), query);
|
tryAttribute(dir, dir.getName(), query);
|
||||||
tryAttribute(dir, dir.getCaption(), query);
|
tryAttribute(dir, dir.getCaption(), query);
|
||||||
tryAttribute(dir, dir.getPath().getAbsolutePath(), query);
|
tryPath(dir, dir.getPath(), query);
|
||||||
|
|
||||||
for (Entry e : dir.getContents()) {
|
for (Entry e : dir.getContents()) {
|
||||||
if ("dir".equals(e.getType())) {
|
if ("dir".equals(e.getType())) {
|
||||||
|
|
@ -42,10 +46,14 @@ public class SearchEngine {
|
||||||
FileEntry file = (FileEntry)e;
|
FileEntry file = (FileEntry)e;
|
||||||
tryAttribute(file, file.getName(), query);
|
tryAttribute(file, file.getName(), query);
|
||||||
tryAttribute(file, file.getCaption(), 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) {
|
void tryAttribute(Entry entry, String attr, String query) {
|
||||||
if (isMatch(attr, query)) {
|
if (isMatch(attr, query)) {
|
||||||
results.addMatch(entry);
|
results.addMatch(entry);
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,11 @@ public class MovieCoder {
|
||||||
props.put("orientation", orientation);
|
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");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
|
||||||
props.put("captureDate", sdf.format(new Date(f.lastModified())));
|
props.put("captureDate", sdf.format(new Date(f.lastModified())));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,8 @@ $(function() {
|
||||||
|
|
||||||
var gridDiv = $("<div class=\"grid\">\n"
|
var gridDiv = $("<div class=\"grid\">\n"
|
||||||
+ " <span class=\"name\">" + entry.name + "</span><br/>\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 + "\">"
|
+ " <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" ? entry.path + ".frame" : entry.path) + "?size=" + thmb + "\" border=\"0\" width=\"" + dim.w + "\" height=\"" + dim.h + "\"/></a></div>\n"
|
+ "<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");
|
+ "</div>\n");
|
||||||
|
|
||||||
var captionP = $("<p id=\"" + entry.name + "\" class=\"caption\"></p>\n");
|
var captionP = $("<p id=\"" + entry.name + "\" class=\"caption\"></p>\n");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue