diff --git a/source/net/filebot/cli/ArgumentBean.java b/source/net/filebot/cli/ArgumentBean.java index b33f1f87..a68cb6a0 100644 --- a/source/net/filebot/cli/ArgumentBean.java +++ b/source/net/filebot/cli/ArgumentBean.java @@ -13,8 +13,6 @@ import java.util.Locale; import java.util.Map; import java.util.logging.Level; -import net.filebot.Language; - import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.CmdLineException; import org.kohsuke.args4j.CmdLineParser; @@ -22,6 +20,8 @@ import org.kohsuke.args4j.Option; import org.kohsuke.args4j.ParserProperties; import org.kohsuke.args4j.spi.ExplicitBooleanOptionHandler; +import net.filebot.Language; + public class ArgumentBean { @Option(name = "--mode", usage = "Open GUI in single panel mode", metaVar = "[Rename, Subtitles, SFV]") diff --git a/source/net/filebot/cli/CmdlineOperations.java b/source/net/filebot/cli/CmdlineOperations.java index c674d274..5626175c 100644 --- a/source/net/filebot/cli/CmdlineOperations.java +++ b/source/net/filebot/cli/CmdlineOperations.java @@ -10,6 +10,7 @@ import static net.filebot.Settings.*; import static net.filebot.WebServices.*; import static net.filebot.hash.VerificationUtilities.*; import static net.filebot.media.MediaDetection.*; +import static net.filebot.media.XattrMetaInfo.*; import static net.filebot.subtitle.SubtitleUtilities.*; import static net.filebot.util.FileUtilities.*; import static net.filebot.util.StringUtilities.*; @@ -660,19 +661,15 @@ public class CmdlineOperations implements CmdlineInterface { // write metadata into xattr if xattr is enabled if (matches != null && renameLog.size() > 0 && (useExtendedFileAttributes() || useCreationDate()) && renameAction != StandardRenameAction.TEST) { - try { - for (Match match : matches) { - File source = match.getValue(); - Object infoObject = match.getCandidate(); - if (infoObject != null) { - File destination = renameLog.get(source); - if (destination != null && destination.isFile()) { - MediaDetection.storeMetaInfo(destination, infoObject, source.getName(), useExtendedFileAttributes(), useCreationDate()); - } + for (Match match : matches) { + File source = match.getValue(); + Object infoObject = match.getCandidate(); + if (infoObject != null) { + File destination = renameLog.get(source); + if (destination != null && destination.isFile()) { + xattr.storeMetaInfo(destination, infoObject, source.getName()); } } - } catch (Throwable e) { - log.warning("Failed to write xattr: " + e.getMessage()); } } @@ -1079,7 +1076,7 @@ public class CmdlineOperations implements CmdlineInterface { List output = new ArrayList(); for (File file : filter(files, fileFilter)) { - String line = formatter.format(new MediaBindingBean(readMetaInfo(file), file, null)); + String line = formatter.format(new MediaBindingBean(xattr.readMetaInfo(file), file, null)); output.add(line); } return output; diff --git a/source/net/filebot/cli/GroovyPad.java b/source/net/filebot/cli/GroovyPad.java index 90324d78..4c64e5d4 100644 --- a/source/net/filebot/cli/GroovyPad.java +++ b/source/net/filebot/cli/GroovyPad.java @@ -31,17 +31,17 @@ import javax.swing.SwingWorker; import javax.swing.text.BadLocationException; import javax.swing.text.JTextComponent; +import org.fife.ui.rsyntaxtextarea.FileLocation; +import org.fife.ui.rsyntaxtextarea.SyntaxConstants; +import org.fife.ui.rsyntaxtextarea.TextEditorPane; +import org.fife.ui.rtextarea.RTextScrollPane; + import net.filebot.ResourceManager; import net.filebot.Settings; import net.filebot.Settings.ApplicationFolder; import net.filebot.cli.ArgumentProcessor.DefaultScriptProvider; import net.filebot.util.TeePrintStream; -import org.fife.ui.rsyntaxtextarea.FileLocation; -import org.fife.ui.rsyntaxtextarea.SyntaxConstants; -import org.fife.ui.rsyntaxtextarea.TextEditorPane; -import org.fife.ui.rtextarea.RTextScrollPane; - public class GroovyPad extends JFrame { public GroovyPad() throws IOException { diff --git a/source/net/filebot/cli/ScriptShell.java b/source/net/filebot/cli/ScriptShell.java index 20bcd40f..7bdc6bb4 100644 --- a/source/net/filebot/cli/ScriptShell.java +++ b/source/net/filebot/cli/ScriptShell.java @@ -1,7 +1,5 @@ package net.filebot.cli; -import groovy.lang.GroovyClassLoader; - import java.net.URI; import java.util.Map; import java.util.ResourceBundle; @@ -16,6 +14,8 @@ import org.codehaus.groovy.control.customizers.ImportCustomizer; import org.codehaus.groovy.jsr223.GroovyScriptEngineImpl; import org.codehaus.groovy.runtime.StackTraceUtils; +import groovy.lang.GroovyClassLoader; + public class ScriptShell { public static final String ARGV_BINDING_NAME = "args"; diff --git a/source/net/filebot/cli/ScriptShellBaseClass.java b/source/net/filebot/cli/ScriptShellBaseClass.java index e0c2d71e..3af6e418 100644 --- a/source/net/filebot/cli/ScriptShellBaseClass.java +++ b/source/net/filebot/cli/ScriptShellBaseClass.java @@ -3,11 +3,8 @@ package net.filebot.cli; import static java.util.Arrays.*; import static java.util.Collections.*; import static net.filebot.Logging.*; +import static net.filebot.media.XattrMetaInfo.*; import static net.filebot.util.StringUtilities.*; -import groovy.lang.Closure; -import groovy.lang.MissingPropertyException; -import groovy.lang.Script; -import groovy.xml.MarkupBuilder; import java.io.File; import java.io.FileFilter; @@ -33,6 +30,15 @@ import java.util.logging.Logger; import javax.script.Bindings; import javax.script.SimpleBindings; +import org.codehaus.groovy.runtime.StackTraceUtils; +import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; + +import com.sun.jna.Platform; + +import groovy.lang.Closure; +import groovy.lang.MissingPropertyException; +import groovy.lang.Script; +import groovy.xml.MarkupBuilder; import net.filebot.HistorySpooler; import net.filebot.RenameAction; import net.filebot.StandardRenameAction; @@ -43,11 +49,6 @@ import net.filebot.similarity.SeasonEpisodeMatcher.SxE; import net.filebot.util.FileUtilities; import net.filebot.web.Movie; -import org.codehaus.groovy.runtime.StackTraceUtils; -import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; - -import com.sun.jna.Platform; - public abstract class ScriptShellBaseClass extends Script { private final Map defaultValues = synchronizedMap(new LinkedHashMap()); @@ -226,7 +227,7 @@ public abstract class ScriptShellBaseClass extends Script { public Movie detectMovie(File file, boolean strict) { // 1. xattr - Object metaObject = MediaDetection.readMetaInfo(file); + Object metaObject = xattr.readMetaInfo(file); if (metaObject instanceof Movie) { return (Movie) metaObject; } diff --git a/source/net/filebot/cli/ScriptShellMethods.java b/source/net/filebot/cli/ScriptShellMethods.java index 6be6e9b9..f14c31c5 100644 --- a/source/net/filebot/cli/ScriptShellMethods.java +++ b/source/net/filebot/cli/ScriptShellMethods.java @@ -4,7 +4,6 @@ import static java.nio.charset.StandardCharsets.*; import static java.util.Arrays.*; import static java.util.Collections.*; import static net.filebot.MediaTypes.*; -import groovy.lang.Closure; import java.io.File; import java.io.IOException; @@ -20,6 +19,12 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import org.codehaus.groovy.runtime.DefaultGroovyMethods; + +import com.cedarsoftware.util.io.JsonReader; +import com.cedarsoftware.util.io.JsonWriter; + +import groovy.lang.Closure; import net.filebot.MediaTypes; import net.filebot.MetaAttributeView; import net.filebot.media.MediaDetection; @@ -31,11 +36,6 @@ import net.filebot.util.FastFile; import net.filebot.util.FileUtilities; import net.filebot.web.WebRequest; -import org.codehaus.groovy.runtime.DefaultGroovyMethods; - -import com.cedarsoftware.util.io.JsonReader; -import com.cedarsoftware.util.io.JsonWriter; - public class ScriptShellMethods { public static File plus(File self, String name) { diff --git a/source/net/filebot/format/AssociativeScriptObject.java b/source/net/filebot/format/AssociativeScriptObject.java index 3f3d591a..b29af7f2 100644 --- a/source/net/filebot/format/AssociativeScriptObject.java +++ b/source/net/filebot/format/AssociativeScriptObject.java @@ -2,8 +2,6 @@ package net.filebot.format; -import groovy.lang.GroovyObjectSupport; - import java.util.AbstractMap; import java.util.AbstractSet; import java.util.HashMap; @@ -13,6 +11,8 @@ import java.util.Map.Entry; import java.util.Set; import java.util.TreeSet; +import groovy.lang.GroovyObjectSupport; + public class AssociativeScriptObject extends GroovyObjectSupport implements Iterable> { diff --git a/source/net/filebot/format/DynamicBindings.java b/source/net/filebot/format/DynamicBindings.java index 7310d2ac..d7d62fe9 100644 --- a/source/net/filebot/format/DynamicBindings.java +++ b/source/net/filebot/format/DynamicBindings.java @@ -1,11 +1,11 @@ package net.filebot.format; -import groovy.lang.GroovyObjectSupport; - import java.util.Arrays; import java.util.function.Function; import java.util.stream.Stream; +import groovy.lang.GroovyObjectSupport; + public class DynamicBindings extends GroovyObjectSupport { private Function map; diff --git a/source/net/filebot/format/ExpressionFileFilter.java b/source/net/filebot/format/ExpressionFileFilter.java index de490bc3..b9d1d29d 100644 --- a/source/net/filebot/format/ExpressionFileFilter.java +++ b/source/net/filebot/format/ExpressionFileFilter.java @@ -1,7 +1,7 @@ package net.filebot.format; import static net.filebot.Logging.*; -import static net.filebot.media.MediaDetection.*; +import static net.filebot.media.XattrMetaInfo.*; import java.io.File; import java.io.FileFilter; @@ -23,7 +23,7 @@ public class ExpressionFileFilter implements FileFilter { @Override public boolean accept(File f) { try { - return filter.matches(new MediaBindingBean(readMetaInfo(f), f, null)); + return filter.matches(new MediaBindingBean(xattr.readMetaInfo(f), f, null)); } catch (Exception e) { debug.warning(format("Expression failed: %s", e)); return error; diff --git a/source/net/filebot/format/ExpressionFormat.java b/source/net/filebot/format/ExpressionFormat.java index 5cd5a5c3..05b95461 100644 --- a/source/net/filebot/format/ExpressionFormat.java +++ b/source/net/filebot/format/ExpressionFormat.java @@ -3,9 +3,6 @@ package net.filebot.format; import static net.filebot.similarity.Normalization.*; import static net.filebot.util.ExceptionUtilities.*; import static net.filebot.util.FileUtilities.*; -import groovy.lang.GroovyClassLoader; -import groovy.lang.GroovyRuntimeException; -import groovy.lang.MissingPropertyException; import java.security.AccessController; import java.text.FieldPosition; @@ -29,6 +26,10 @@ import org.codehaus.groovy.control.MultipleCompilationErrorsException; import org.codehaus.groovy.control.customizers.ImportCustomizer; import org.codehaus.groovy.jsr223.GroovyScriptEngineImpl; +import groovy.lang.GroovyClassLoader; +import groovy.lang.GroovyRuntimeException; +import groovy.lang.MissingPropertyException; + public class ExpressionFormat extends Format { private static ScriptEngine engine; diff --git a/source/net/filebot/format/ExpressionFormatFunctions.java b/source/net/filebot/format/ExpressionFormatFunctions.java index 790a0836..85eb192f 100644 --- a/source/net/filebot/format/ExpressionFormatFunctions.java +++ b/source/net/filebot/format/ExpressionFormatFunctions.java @@ -1,7 +1,5 @@ package net.filebot.format; -import groovy.lang.Closure; - import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -11,6 +9,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import groovy.lang.Closure; + /** * Global functions available in the {@link ExpressionFormat} */ diff --git a/source/net/filebot/media/MediaDetection.java b/source/net/filebot/media/MediaDetection.java index bff7a703..ca8a6b66 100644 --- a/source/net/filebot/media/MediaDetection.java +++ b/source/net/filebot/media/MediaDetection.java @@ -5,7 +5,7 @@ import static java.util.regex.Pattern.*; import static java.util.stream.Collectors.*; import static net.filebot.Logging.*; import static net.filebot.MediaTypes.*; -import static net.filebot.Settings.*; +import static net.filebot.media.XattrMetaInfo.*; import static net.filebot.similarity.CommonSequenceMatcher.*; import static net.filebot.similarity.Normalization.*; import static net.filebot.util.FileUtilities.*; @@ -300,7 +300,7 @@ public class MediaDetection { // try xattr metadata if enabled for (File it : files) { - Object metaObject = readMetaInfo(it); + Object metaObject = xattr.readMetaInfo(it); if (metaObject instanceof Episode) { unids.add(((Episode) metaObject).getSeriesName()); } @@ -575,7 +575,7 @@ public class MediaDetection { List options = new ArrayList(); // try xattr metadata if enabled - Object metaObject = readMetaInfo(movieFile); + Object metaObject = xattr.readMetaInfo(movieFile); if (metaObject instanceof Movie) { options.add((Movie) metaObject); } @@ -1492,74 +1492,6 @@ public class MediaDetection { return singletonList(folder); } - public static Object readMetaInfo(File file) { - if (useExtendedFileAttributes()) { - try { - MetaAttributes xattr = new MetaAttributes(file); - Object metaObject = xattr.getObject(); - if (metaObject instanceof Episode || metaObject instanceof Movie) { - return metaObject; - } - } catch (Throwable e) { - debug.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()) { - try { - MetaAttributes xattr = new MetaAttributes(file); - - // set creation date to episode / movie release date - if (useCreationDate) { - try { - if (model instanceof Episode) { - Episode episode = (Episode) model; - if (episode.getAirdate() != null) { - xattr.setCreationDate(episode.getAirdate().getTimeStamp()); - } - } else if (model instanceof Movie) { - Movie movie = (Movie) model; - if (movie.getYear() > 0 && movie.getTmdbId() > 0) { - SimpleDate releaseDate = WebServices.TheMovieDB.getMovieInfo(movie, Locale.ENGLISH, false).getReleased(); - if (releaseDate != null) { - xattr.setCreationDate(releaseDate.getTimeStamp()); - } - } - } - } catch (Exception e) { - if (e instanceof RuntimeException && e.getCause() instanceof IOException) { - e = (IOException) e.getCause(); - } - debug.warning("Failed to set creation date: " + e.getMessage()); - } - } - - // store original name and model as xattr - if (useExtendedFileAttributes) { - try { - if (model instanceof Episode || model instanceof Movie) { - xattr.setObject(model); - } - if (xattr.getOriginalName() == null && original != null) { - xattr.setOriginalName(original); - } - } catch (Exception e) { - if (e instanceof RuntimeException && e.getCause() instanceof IOException) { - e = (IOException) e.getCause(); - } - debug.warning("Failed to set xattr: " + e.getMessage()); - } - } - } catch (Throwable t) { - debug.warning("Unable to store xattr: " + t.getMessage()); - } - } - } - public static void warmupCachedResources() throws Exception { // load filter data MediaDetection.getClutterFileFilter(); diff --git a/source/net/filebot/media/MetaAttributes.java b/source/net/filebot/media/MetaAttributes.java index a300bbce..7c3f88b6 100644 --- a/source/net/filebot/media/MetaAttributes.java +++ b/source/net/filebot/media/MetaAttributes.java @@ -6,11 +6,11 @@ import java.nio.file.Files; import java.nio.file.attribute.BasicFileAttributeView; import java.nio.file.attribute.FileTime; -import net.filebot.MetaAttributeView; - import com.cedarsoftware.util.io.JsonReader; import com.cedarsoftware.util.io.JsonWriter; +import net.filebot.MetaAttributeView; + public class MetaAttributes { private static final String FILENAME_KEY = "net.filebot.filename"; diff --git a/source/net/filebot/media/XattrMetaInfo.java b/source/net/filebot/media/XattrMetaInfo.java new file mode 100644 index 00000000..50141a71 --- /dev/null +++ b/source/net/filebot/media/XattrMetaInfo.java @@ -0,0 +1,107 @@ +package net.filebot.media; + +import static net.filebot.Logging.*; +import static net.filebot.Settings.*; + +import java.io.File; +import java.io.IOException; +import java.util.Locale; + +import net.filebot.WebServices; +import net.filebot.web.Episode; +import net.filebot.web.Movie; +import net.filebot.web.SimpleDate; + +public class XattrMetaInfo { + + public static final XattrMetaInfo xattr = new XattrMetaInfo(useExtendedFileAttributes(), useCreationDate()); + + private final boolean useExtendedFileAttributes; + private final boolean useCreationDate; + + public XattrMetaInfo(boolean useExtendedFileAttributes, boolean useCreationDate) { + this.useExtendedFileAttributes = useExtendedFileAttributes; + this.useCreationDate = useCreationDate; + } + + public boolean isMetaInfo(Object object) { + return object instanceof Episode || object instanceof Movie; + } + + public long getTimeStamp(Object object) throws Exception { + if (object instanceof Episode) { + Episode episode = (Episode) object; + if (episode.getAirdate() != null) { + return episode.getAirdate().getTimeStamp(); + } + } else if (object instanceof Movie) { + Movie movie = (Movie) object; + if (movie.getYear() > 0 && movie.getTmdbId() > 0) { + SimpleDate releaseDate = WebServices.TheMovieDB.getMovieInfo(movie, Locale.ENGLISH, false).getReleased(); + if (releaseDate != null) { + return releaseDate.getTimeStamp(); + } + } + } + return -1; + } + + public Object readMetaInfo(File file) { + if (useExtendedFileAttributes) { + try { + MetaAttributes attr = new MetaAttributes(file); + Object metadata = attr.getObject(); + if (isMetaInfo(metadata)) { + return metadata; + } + } catch (Throwable e) { + debug.warning("Failed to read xattr: " + e.getMessage()); + } + } + return null; + } + + public void storeMetaInfo(File file, Object model, String original) { + // only for Episode / Movie objects + if ((useExtendedFileAttributes || useCreationDate) && isMetaInfo(model) && file.isFile()) { + try { + MetaAttributes attr = new MetaAttributes(file); + + // set creation date to episode / movie release date + if (useCreationDate) { + try { + long t = getTimeStamp(model); + if (t > 0) { + attr.setCreationDate(t); + } + } catch (Throwable e) { + if (e.getCause() instanceof IOException) { + e = e.getCause(); + } + debug.warning("Failed to set creation date: " + e.getMessage()); + } + } + + // store original name and model as xattr + if (useExtendedFileAttributes) { + try { + if (isMetaInfo(model)) { + attr.setObject(model); + } + if (attr.getOriginalName() == null && original != null && original.length() > 0) { + attr.setOriginalName(original); + } + } catch (Throwable e) { + if (e.getCause() instanceof IOException) { + e = e.getCause(); + } + debug.warning("Failed to set xattr: " + e.getMessage()); + } + } + } catch (Throwable t) { + debug.warning("Failed to store xattr: " + t.getMessage()); + } + } + } + +} diff --git a/source/net/filebot/media/XattrMetaInfoProvider.java b/source/net/filebot/media/XattrMetaInfoProvider.java index b012b671..0240523a 100644 --- a/source/net/filebot/media/XattrMetaInfoProvider.java +++ b/source/net/filebot/media/XattrMetaInfoProvider.java @@ -1,20 +1,32 @@ package net.filebot.media; +import static net.filebot.media.XattrMetaInfo.*; + import java.io.File; import java.util.LinkedHashMap; import java.util.Map; -public class XattrMetaInfoProvider { +import javax.swing.Icon; +import net.filebot.web.Datasource; + +public class XattrMetaInfoProvider implements Datasource { + + @Override public String getName() { return "xattr"; } + @Override + public Icon getIcon() { + return null; + } + public Map getMetaData(Iterable files) { Map result = new LinkedHashMap(); for (File f : files) { - Object metaObject = MediaDetection.readMetaInfo(f); + Object metaObject = xattr.readMetaInfo(f); if (metaObject != null) { result.put(f, metaObject); } diff --git a/source/net/filebot/similarity/EpisodeMetrics.java b/source/net/filebot/similarity/EpisodeMetrics.java index 944f3e1f..66f4cdb9 100644 --- a/source/net/filebot/similarity/EpisodeMetrics.java +++ b/source/net/filebot/similarity/EpisodeMetrics.java @@ -5,6 +5,7 @@ import static java.util.Collections.*; import static java.util.regex.Pattern.*; import static net.filebot.Logging.*; import static net.filebot.media.MediaDetection.*; +import static net.filebot.media.XattrMetaInfo.*; import static net.filebot.similarity.Normalization.*; import static net.filebot.util.FileUtilities.*; import static net.filebot.util.StringUtilities.*; @@ -678,7 +679,7 @@ public enum EpisodeMetrics implements SimilarityMetric { // deserialize MetaAttributes if enabled and available if (object instanceof File) { - Object metaObject = readMetaInfo((File) object); + Object metaObject = xattr.readMetaInfo((File) object); if (metaObject != null) { return super.getProperties(metaObject); } diff --git a/source/net/filebot/similarity/NameSimilarityMetric.java b/source/net/filebot/similarity/NameSimilarityMetric.java index 7ae73ef1..f744306f 100644 --- a/source/net/filebot/similarity/NameSimilarityMetric.java +++ b/source/net/filebot/similarity/NameSimilarityMetric.java @@ -3,12 +3,13 @@ package net.filebot.similarity; import static net.filebot.similarity.Normalization.*; + +import com.ibm.icu.text.Transliterator; + import uk.ac.shef.wit.simmetrics.similaritymetrics.AbstractStringMetric; import uk.ac.shef.wit.simmetrics.similaritymetrics.QGramsDistance; import uk.ac.shef.wit.simmetrics.tokenisers.TokeniserQGram3; -import com.ibm.icu.text.Transliterator; - public class NameSimilarityMetric implements SimilarityMetric { diff --git a/source/net/filebot/ui/rename/BindingDialog.java b/source/net/filebot/ui/rename/BindingDialog.java index 19f929f0..3eead0d8 100644 --- a/source/net/filebot/ui/rename/BindingDialog.java +++ b/source/net/filebot/ui/rename/BindingDialog.java @@ -3,6 +3,7 @@ package net.filebot.ui.rename; import static net.filebot.Logging.*; import static net.filebot.MediaTypes.*; import static net.filebot.UserFiles.*; +import static net.filebot.media.XattrMetaInfo.*; import static net.filebot.util.ui.SwingUI.*; import java.awt.Color; @@ -52,7 +53,6 @@ import javax.swing.table.TableRowSorter; import net.filebot.ResourceManager; import net.filebot.format.ExpressionFormat; import net.filebot.format.MediaBindingBean; -import net.filebot.media.MediaDetection; import net.filebot.mediainfo.MediaInfo; import net.filebot.mediainfo.MediaInfo.StreamKind; import net.filebot.util.DefaultThreadFactory; @@ -378,7 +378,7 @@ class BindingDialog extends JDialog { mediaFileTextField.setText(file.get(0).getAbsolutePath()); // set info object from xattr if possible - Object object = MediaDetection.readMetaInfo(file.get(0)); + Object object = xattr.readMetaInfo(file.get(0)); if (object != null && infoObjectFormat.format(object) != null) { setInfoObject(object); } diff --git a/source/net/filebot/ui/rename/MatchModel.java b/source/net/filebot/ui/rename/MatchModel.java index d57a22a3..c9421c1d 100644 --- a/source/net/filebot/ui/rename/MatchModel.java +++ b/source/net/filebot/ui/rename/MatchModel.java @@ -8,11 +8,11 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; -import net.filebot.similarity.Match; import ca.odell.glazedlists.BasicEventList; import ca.odell.glazedlists.EventList; import ca.odell.glazedlists.TransformedList; import ca.odell.glazedlists.event.ListEvent; +import net.filebot.similarity.Match; public class MatchModel { diff --git a/source/net/filebot/ui/rename/RenameAction.java b/source/net/filebot/ui/rename/RenameAction.java index 3a93495b..040c07cc 100644 --- a/source/net/filebot/ui/rename/RenameAction.java +++ b/source/net/filebot/ui/rename/RenameAction.java @@ -4,6 +4,7 @@ import static java.util.Collections.*; import static javax.swing.JOptionPane.*; import static net.filebot.Logging.*; import static net.filebot.Settings.*; +import static net.filebot.media.XattrMetaInfo.*; import static net.filebot.util.ExceptionUtilities.*; import static net.filebot.util.FileUtilities.*; import static net.filebot.util.ui.SwingUI.*; @@ -46,7 +47,6 @@ import net.filebot.NativeRenameAction; import net.filebot.ResourceManager; import net.filebot.StandardRenameAction; import net.filebot.mac.MacAppUtilities; -import net.filebot.media.MediaDetection; import net.filebot.similarity.Match; import net.filebot.util.ui.ProgressDialog; import net.filebot.util.ui.ProgressDialog.Cancellable; @@ -118,19 +118,15 @@ class RenameAction extends AbstractAction { // write metadata into xattr if xattr is enabled if (useExtendedFileAttributes() || useCreationDate()) { - try { - for (Match match : matches) { - File file = match.getCandidate(); - Object meta = match.getValue(); - if (renameMap.containsKey(file) && meta != null) { - File destination = resolveDestination(file, renameMap.get(file), false); - if (destination.isFile()) { - MediaDetection.storeMetaInfo(destination, meta, file.getName(), useExtendedFileAttributes(), useCreationDate()); - } + for (Match match : matches) { + File file = match.getCandidate(); + Object meta = match.getValue(); + if (renameMap.containsKey(file) && meta != null) { + File destination = resolveDestination(file, renameMap.get(file), false); + if (destination.isFile()) { + xattr.storeMetaInfo(destination, meta, file.getName()); } } - } catch (Throwable e) { - debug.warning("Failed to write xattr: " + e.getMessage()); } } } catch (ExecutionException e) { diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index dd1915b5..ceeeb715 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -6,6 +6,7 @@ import static javax.swing.KeyStroke.*; import static javax.swing.SwingUtilities.*; import static net.filebot.Logging.*; import static net.filebot.Settings.*; +import static net.filebot.media.XattrMetaInfo.*; import static net.filebot.util.ExceptionUtilities.*; import static net.filebot.util.ui.LoadingOverlayPane.*; import static net.filebot.util.ui.SwingUI.*; @@ -64,7 +65,6 @@ import net.filebot.UserFiles; import net.filebot.WebServices; import net.filebot.format.MediaBindingBean; import net.filebot.mac.MacAppUtilities; -import net.filebot.media.MediaDetection; import net.filebot.similarity.Match; import net.filebot.ui.rename.FormatDialog.Mode; import net.filebot.ui.rename.RenameModel.FormattedFuture; @@ -333,7 +333,7 @@ public class RenamePanel extends JComponent { List objects = new ArrayList(files.size()); List objectsTail = new ArrayList(); for (File file : files) { - Object metaObject = MediaDetection.readMetaInfo(file); + Object metaObject = xattr.readMetaInfo(file); if (metaObject != null) { objects.add(metaObject); // upper list is based on xattr metadata } else {