diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java index 9ccf6a20..d4287083 100644 --- a/source/net/sourceforge/filebot/media/MediaDetection.java +++ b/source/net/sourceforge/filebot/media/MediaDetection.java @@ -1359,6 +1359,21 @@ public class MediaDetection { } }; + public static Object loadMetaInfo(File file) { + if (useExtendedFileAttributes()) { + try { + MetaAttributes xattr = new MetaAttributes(file); + Object meta = xattr.getObject(); + if (meta instanceof Episode || meta instanceof Movie) { + return meta; + } + } catch (Throwable e) { + Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Unable to read xattr: " + e.getMessage()); + } + } + return null; + } + public static void storeMetaInfo(File file, Object model, String original, boolean useExtendedFileAttributes, boolean useCreationDate) { // only for Episode / Movie objects if ((useExtendedFileAttributes || useCreationDate) && (model instanceof Episode || model instanceof Movie) && file.isFile()) { @@ -1387,7 +1402,9 @@ public class MediaDetection { // store original name and model as xattr if (useExtendedFileAttributes) { try { - xattr.setObject(model); + if (model instanceof Episode || model instanceof Movie) { + xattr.setObject(model); + } if (xattr.getOriginalName() == null && original != null) { xattr.setOriginalName(original); } diff --git a/source/net/sourceforge/filebot/ui/rename/FilesListTransferablePolicy.java b/source/net/sourceforge/filebot/ui/rename/FilesListTransferablePolicy.java index 89541ce0..a4a2c721 100644 --- a/source/net/sourceforge/filebot/ui/rename/FilesListTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/rename/FilesListTransferablePolicy.java @@ -98,7 +98,7 @@ class FilesListTransferablePolicy extends FileTransferablePolicy { } } - model.addAll(FastFile.foreach(entries)); + model.addAll(FastFile.get(entries)); } @Override diff --git a/source/net/sourceforge/filebot/ui/rename/NamesListTransferablePolicy.java b/source/net/sourceforge/filebot/ui/rename/NamesListTransferablePolicy.java index a3148ac6..8937c098 100644 --- a/source/net/sourceforge/filebot/ui/rename/NamesListTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/rename/NamesListTransferablePolicy.java @@ -1,7 +1,5 @@ - package net.sourceforge.filebot.ui.rename; - import static java.awt.datatransfer.DataFlavor.*; import static net.sourceforge.filebot.hash.VerificationUtilities.*; import static net.sourceforge.filebot.ui.transfer.FileTransferable.*; @@ -26,43 +24,37 @@ import net.sourceforge.filebot.vfs.SimpleFileInfo; import net.sourceforge.filebot.web.Episode; import net.sourceforge.tuned.FastFile; - class NamesListTransferablePolicy extends FileTransferablePolicy { - + private static final DataFlavor episodeArrayFlavor = ArrayTransferable.flavor(Episode.class); - + private final List model; - public NamesListTransferablePolicy(List model) { this.model = model; } - @Override protected void clear() { model.clear(); } - @Override public boolean accept(Transferable tr) throws Exception { return tr.isDataFlavorSupported(stringFlavor) || hasFileListFlavor(tr); } - @Override protected boolean accept(List files) { return true; } - @Override public void handleTransferable(Transferable tr, TransferAction action) throws Exception { if (action == TransferAction.PUT) { clear(); } - + if (tr.isDataFlavorSupported(episodeArrayFlavor)) { // episode array transferable model.addAll(Arrays.asList((Episode[]) tr.getTransferData((episodeArrayFlavor)))); @@ -74,29 +66,25 @@ class NamesListTransferablePolicy extends FileTransferablePolicy { load((String) tr.getTransferData(stringFlavor)); } } - protected void load(String string) { List values = new ArrayList(); - Scanner scanner = new Scanner(string); - + while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); - if (line.length() > 0) { values.add(line); } } - + model.addAll(values); } - @Override protected void load(List files) throws IOException { List values = new ArrayList(); - + if (containsOnly(files, MediaTypes.getDefaultFilter("application/list"))) { // list files loadListFiles(files, values); @@ -108,42 +96,40 @@ class NamesListTransferablePolicy extends FileTransferablePolicy { loadTorrentFiles(files, values); } else { // load all files from the given folders recursively up do a depth of 5 - values.addAll(FastFile.foreach(flatten(files, 5, false))); + values.addAll(FastFile.get(flatten(files, 5, false))); } - + model.addAll(values); } - protected void loadListFiles(List files, List values) throws IOException { for (File file : files) { // don't use new Scanner(File) because of BUG 6368019 (http://bugs.sun.com/view_bug.do?bug_id=6368019) Scanner scanner = new Scanner(createTextReader(file)); - + while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); - + if (line.length() > 0) { values.add(line); } } - + scanner.close(); } } - protected void loadVerificationFiles(List files, List values) throws IOException { for (File verificationFile : files) { HashType type = getHashType(verificationFile); - + // check if type is supported if (type == null) continue; - + // add all file names from verification file VerificationFileReader parser = new VerificationFileReader(createTextReader(verificationFile), type.getFormat()); - + try { while (parser.hasNext()) { values.add(new SimpleFileInfo(parser.next().getKey().getName(), -1)); @@ -153,22 +139,20 @@ class NamesListTransferablePolicy extends FileTransferablePolicy { } } } - protected void loadTorrentFiles(List files, List values) throws IOException { for (File file : files) { Torrent torrent = new Torrent(file); - + for (Torrent.Entry entry : torrent.getFiles()) { values.add(new SimpleFileInfo(entry.getName(), entry.getLength())); } } } - @Override public String getFileFilterDescription() { return "text files, verification files, torrent files"; } - + } diff --git a/source/net/sourceforge/tuned/FastFile.java b/source/net/sourceforge/tuned/FastFile.java index c90ad22b..1262e2d2 100644 --- a/source/net/sourceforge/tuned/FastFile.java +++ b/source/net/sourceforge/tuned/FastFile.java @@ -1,74 +1,64 @@ - package net.sourceforge.tuned; - import java.io.File; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collection; import java.util.List; - public class FastFile extends File { - + private Long length; private Boolean isDirectory; private Boolean isFile; - - + public FastFile(String path) { super(path); } - - + public FastFile(File parent, String child) { super(parent, child); } - - + @Override public long length() { return length != null ? length : (length = super.length()); } - - + @Override public boolean isDirectory() { return isDirectory != null ? isDirectory : (isDirectory = super.isDirectory()); } - - + @Override public boolean isFile() { return isFile != null ? isFile : (isFile = super.isFile()); } - - + @Override public File[] listFiles() { String[] names = list(); if (names == null) return null; - + File[] files = new File[names.length]; for (int i = 0; i < names.length; i++) { files[i] = new FastFile(this, names[i]); } return files; } - - - public static List foreach(File... files) { - return foreach(Arrays.asList(files)); + + public static FastFile get(File file) { + return new FastFile(file.getPath()); } - - - public static List foreach(final List files) { + + public static List get(Collection files) { List result = new ArrayList(files.size()); - + for (File file : files) { result.add(new FastFile(file.getPath())); } - + return result; } + }