This commit is contained in:
Reinhard Pointner 2016-03-27 13:52:59 +00:00
parent 0d7741d692
commit b9fdfcbe10
21 changed files with 191 additions and 143 deletions

View File

@ -13,8 +13,6 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import net.filebot.Language;
import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException; import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser; import org.kohsuke.args4j.CmdLineParser;
@ -22,6 +20,8 @@ import org.kohsuke.args4j.Option;
import org.kohsuke.args4j.ParserProperties; import org.kohsuke.args4j.ParserProperties;
import org.kohsuke.args4j.spi.ExplicitBooleanOptionHandler; import org.kohsuke.args4j.spi.ExplicitBooleanOptionHandler;
import net.filebot.Language;
public class ArgumentBean { public class ArgumentBean {
@Option(name = "--mode", usage = "Open GUI in single panel mode", metaVar = "[Rename, Subtitles, SFV]") @Option(name = "--mode", usage = "Open GUI in single panel mode", metaVar = "[Rename, Subtitles, SFV]")

View File

@ -10,6 +10,7 @@ import static net.filebot.Settings.*;
import static net.filebot.WebServices.*; import static net.filebot.WebServices.*;
import static net.filebot.hash.VerificationUtilities.*; import static net.filebot.hash.VerificationUtilities.*;
import static net.filebot.media.MediaDetection.*; import static net.filebot.media.MediaDetection.*;
import static net.filebot.media.XattrMetaInfo.*;
import static net.filebot.subtitle.SubtitleUtilities.*; import static net.filebot.subtitle.SubtitleUtilities.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.StringUtilities.*; import static net.filebot.util.StringUtilities.*;
@ -660,19 +661,15 @@ public class CmdlineOperations implements CmdlineInterface {
// write metadata into xattr if xattr is enabled // write metadata into xattr if xattr is enabled
if (matches != null && renameLog.size() > 0 && (useExtendedFileAttributes() || useCreationDate()) && renameAction != StandardRenameAction.TEST) { if (matches != null && renameLog.size() > 0 && (useExtendedFileAttributes() || useCreationDate()) && renameAction != StandardRenameAction.TEST) {
try { for (Match<File, ?> match : matches) {
for (Match<File, ?> match : matches) { File source = match.getValue();
File source = match.getValue(); Object infoObject = match.getCandidate();
Object infoObject = match.getCandidate(); if (infoObject != null) {
if (infoObject != null) { File destination = renameLog.get(source);
File destination = renameLog.get(source); if (destination != null && destination.isFile()) {
if (destination != null && destination.isFile()) { xattr.storeMetaInfo(destination, infoObject, source.getName());
MediaDetection.storeMetaInfo(destination, infoObject, source.getName(), useExtendedFileAttributes(), useCreationDate());
}
} }
} }
} catch (Throwable e) {
log.warning("Failed to write xattr: " + e.getMessage());
} }
} }
@ -1079,7 +1076,7 @@ public class CmdlineOperations implements CmdlineInterface {
List<String> output = new ArrayList<String>(); List<String> output = new ArrayList<String>();
for (File file : filter(files, fileFilter)) { 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); output.add(line);
} }
return output; return output;

View File

@ -31,17 +31,17 @@ import javax.swing.SwingWorker;
import javax.swing.text.BadLocationException; import javax.swing.text.BadLocationException;
import javax.swing.text.JTextComponent; 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.ResourceManager;
import net.filebot.Settings; import net.filebot.Settings;
import net.filebot.Settings.ApplicationFolder; import net.filebot.Settings.ApplicationFolder;
import net.filebot.cli.ArgumentProcessor.DefaultScriptProvider; import net.filebot.cli.ArgumentProcessor.DefaultScriptProvider;
import net.filebot.util.TeePrintStream; 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 class GroovyPad extends JFrame {
public GroovyPad() throws IOException { public GroovyPad() throws IOException {

View File

@ -1,7 +1,5 @@
package net.filebot.cli; package net.filebot.cli;
import groovy.lang.GroovyClassLoader;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.ResourceBundle; 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.jsr223.GroovyScriptEngineImpl;
import org.codehaus.groovy.runtime.StackTraceUtils; import org.codehaus.groovy.runtime.StackTraceUtils;
import groovy.lang.GroovyClassLoader;
public class ScriptShell { public class ScriptShell {
public static final String ARGV_BINDING_NAME = "args"; public static final String ARGV_BINDING_NAME = "args";

View File

@ -3,11 +3,8 @@ package net.filebot.cli;
import static java.util.Arrays.*; import static java.util.Arrays.*;
import static java.util.Collections.*; import static java.util.Collections.*;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.media.XattrMetaInfo.*;
import static net.filebot.util.StringUtilities.*; 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.File;
import java.io.FileFilter; import java.io.FileFilter;
@ -33,6 +30,15 @@ import java.util.logging.Logger;
import javax.script.Bindings; import javax.script.Bindings;
import javax.script.SimpleBindings; 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.HistorySpooler;
import net.filebot.RenameAction; import net.filebot.RenameAction;
import net.filebot.StandardRenameAction; import net.filebot.StandardRenameAction;
@ -43,11 +49,6 @@ import net.filebot.similarity.SeasonEpisodeMatcher.SxE;
import net.filebot.util.FileUtilities; import net.filebot.util.FileUtilities;
import net.filebot.web.Movie; 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 { public abstract class ScriptShellBaseClass extends Script {
private final Map<String, Object> defaultValues = synchronizedMap(new LinkedHashMap<String, Object>()); private final Map<String, Object> defaultValues = synchronizedMap(new LinkedHashMap<String, Object>());
@ -226,7 +227,7 @@ public abstract class ScriptShellBaseClass extends Script {
public Movie detectMovie(File file, boolean strict) { public Movie detectMovie(File file, boolean strict) {
// 1. xattr // 1. xattr
Object metaObject = MediaDetection.readMetaInfo(file); Object metaObject = xattr.readMetaInfo(file);
if (metaObject instanceof Movie) { if (metaObject instanceof Movie) {
return (Movie) metaObject; return (Movie) metaObject;
} }

View File

@ -4,7 +4,6 @@ import static java.nio.charset.StandardCharsets.*;
import static java.util.Arrays.*; import static java.util.Arrays.*;
import static java.util.Collections.*; import static java.util.Collections.*;
import static net.filebot.MediaTypes.*; import static net.filebot.MediaTypes.*;
import groovy.lang.Closure;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -20,6 +19,12 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; 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.MediaTypes;
import net.filebot.MetaAttributeView; import net.filebot.MetaAttributeView;
import net.filebot.media.MediaDetection; import net.filebot.media.MediaDetection;
@ -31,11 +36,6 @@ import net.filebot.util.FastFile;
import net.filebot.util.FileUtilities; import net.filebot.util.FileUtilities;
import net.filebot.web.WebRequest; 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 class ScriptShellMethods {
public static File plus(File self, String name) { public static File plus(File self, String name) {

View File

@ -2,8 +2,6 @@
package net.filebot.format; package net.filebot.format;
import groovy.lang.GroovyObjectSupport;
import java.util.AbstractMap; import java.util.AbstractMap;
import java.util.AbstractSet; import java.util.AbstractSet;
import java.util.HashMap; import java.util.HashMap;
@ -13,6 +11,8 @@ import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import groovy.lang.GroovyObjectSupport;
public class AssociativeScriptObject extends GroovyObjectSupport implements Iterable<Entry<Object, Object>> { public class AssociativeScriptObject extends GroovyObjectSupport implements Iterable<Entry<Object, Object>> {

View File

@ -1,11 +1,11 @@
package net.filebot.format; package net.filebot.format;
import groovy.lang.GroovyObjectSupport;
import java.util.Arrays; import java.util.Arrays;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Stream; import java.util.stream.Stream;
import groovy.lang.GroovyObjectSupport;
public class DynamicBindings extends GroovyObjectSupport { public class DynamicBindings extends GroovyObjectSupport {
private Function<String, Object> map; private Function<String, Object> map;

View File

@ -1,7 +1,7 @@
package net.filebot.format; package net.filebot.format;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.media.MediaDetection.*; import static net.filebot.media.XattrMetaInfo.*;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
@ -23,7 +23,7 @@ public class ExpressionFileFilter implements FileFilter {
@Override @Override
public boolean accept(File f) { public boolean accept(File f) {
try { try {
return filter.matches(new MediaBindingBean(readMetaInfo(f), f, null)); return filter.matches(new MediaBindingBean(xattr.readMetaInfo(f), f, null));
} catch (Exception e) { } catch (Exception e) {
debug.warning(format("Expression failed: %s", e)); debug.warning(format("Expression failed: %s", e));
return error; return error;

View File

@ -3,9 +3,6 @@ package net.filebot.format;
import static net.filebot.similarity.Normalization.*; import static net.filebot.similarity.Normalization.*;
import static net.filebot.util.ExceptionUtilities.*; import static net.filebot.util.ExceptionUtilities.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyRuntimeException;
import groovy.lang.MissingPropertyException;
import java.security.AccessController; import java.security.AccessController;
import java.text.FieldPosition; 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.control.customizers.ImportCustomizer;
import org.codehaus.groovy.jsr223.GroovyScriptEngineImpl; import org.codehaus.groovy.jsr223.GroovyScriptEngineImpl;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyRuntimeException;
import groovy.lang.MissingPropertyException;
public class ExpressionFormat extends Format { public class ExpressionFormat extends Format {
private static ScriptEngine engine; private static ScriptEngine engine;

View File

@ -1,7 +1,5 @@
package net.filebot.format; package net.filebot.format;
import groovy.lang.Closure;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
@ -11,6 +9,8 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import groovy.lang.Closure;
/** /**
* Global functions available in the {@link ExpressionFormat} * Global functions available in the {@link ExpressionFormat}
*/ */

View File

@ -5,7 +5,7 @@ import static java.util.regex.Pattern.*;
import static java.util.stream.Collectors.*; import static java.util.stream.Collectors.*;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.MediaTypes.*; 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.CommonSequenceMatcher.*;
import static net.filebot.similarity.Normalization.*; import static net.filebot.similarity.Normalization.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
@ -300,7 +300,7 @@ public class MediaDetection {
// try xattr metadata if enabled // try xattr metadata if enabled
for (File it : files) { for (File it : files) {
Object metaObject = readMetaInfo(it); Object metaObject = xattr.readMetaInfo(it);
if (metaObject instanceof Episode) { if (metaObject instanceof Episode) {
unids.add(((Episode) metaObject).getSeriesName()); unids.add(((Episode) metaObject).getSeriesName());
} }
@ -575,7 +575,7 @@ public class MediaDetection {
List<Movie> options = new ArrayList<Movie>(); List<Movie> options = new ArrayList<Movie>();
// try xattr metadata if enabled // try xattr metadata if enabled
Object metaObject = readMetaInfo(movieFile); Object metaObject = xattr.readMetaInfo(movieFile);
if (metaObject instanceof Movie) { if (metaObject instanceof Movie) {
options.add((Movie) metaObject); options.add((Movie) metaObject);
} }
@ -1492,74 +1492,6 @@ public class MediaDetection {
return singletonList(folder); 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 { public static void warmupCachedResources() throws Exception {
// load filter data // load filter data
MediaDetection.getClutterFileFilter(); MediaDetection.getClutterFileFilter();

View File

@ -6,11 +6,11 @@ import java.nio.file.Files;
import java.nio.file.attribute.BasicFileAttributeView; import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.FileTime; import java.nio.file.attribute.FileTime;
import net.filebot.MetaAttributeView;
import com.cedarsoftware.util.io.JsonReader; import com.cedarsoftware.util.io.JsonReader;
import com.cedarsoftware.util.io.JsonWriter; import com.cedarsoftware.util.io.JsonWriter;
import net.filebot.MetaAttributeView;
public class MetaAttributes { public class MetaAttributes {
private static final String FILENAME_KEY = "net.filebot.filename"; private static final String FILENAME_KEY = "net.filebot.filename";

View File

@ -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());
}
}
}
}

View File

@ -1,20 +1,32 @@
package net.filebot.media; package net.filebot.media;
import static net.filebot.media.XattrMetaInfo.*;
import java.io.File; import java.io.File;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; 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() { public String getName() {
return "xattr"; return "xattr";
} }
@Override
public Icon getIcon() {
return null;
}
public Map<File, Object> getMetaData(Iterable<File> files) { public Map<File, Object> getMetaData(Iterable<File> files) {
Map<File, Object> result = new LinkedHashMap<File, Object>(); Map<File, Object> result = new LinkedHashMap<File, Object>();
for (File f : files) { for (File f : files) {
Object metaObject = MediaDetection.readMetaInfo(f); Object metaObject = xattr.readMetaInfo(f);
if (metaObject != null) { if (metaObject != null) {
result.put(f, metaObject); result.put(f, metaObject);
} }

View File

@ -5,6 +5,7 @@ import static java.util.Collections.*;
import static java.util.regex.Pattern.*; import static java.util.regex.Pattern.*;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.media.MediaDetection.*; import static net.filebot.media.MediaDetection.*;
import static net.filebot.media.XattrMetaInfo.*;
import static net.filebot.similarity.Normalization.*; import static net.filebot.similarity.Normalization.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.StringUtilities.*; import static net.filebot.util.StringUtilities.*;
@ -678,7 +679,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
// deserialize MetaAttributes if enabled and available // deserialize MetaAttributes if enabled and available
if (object instanceof File) { if (object instanceof File) {
Object metaObject = readMetaInfo((File) object); Object metaObject = xattr.readMetaInfo((File) object);
if (metaObject != null) { if (metaObject != null) {
return super.getProperties(metaObject); return super.getProperties(metaObject);
} }

View File

@ -3,12 +3,13 @@ package net.filebot.similarity;
import static net.filebot.similarity.Normalization.*; 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.AbstractStringMetric;
import uk.ac.shef.wit.simmetrics.similaritymetrics.QGramsDistance; import uk.ac.shef.wit.simmetrics.similaritymetrics.QGramsDistance;
import uk.ac.shef.wit.simmetrics.tokenisers.TokeniserQGram3; import uk.ac.shef.wit.simmetrics.tokenisers.TokeniserQGram3;
import com.ibm.icu.text.Transliterator;
public class NameSimilarityMetric implements SimilarityMetric { public class NameSimilarityMetric implements SimilarityMetric {

View File

@ -3,6 +3,7 @@ package net.filebot.ui.rename;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.MediaTypes.*; import static net.filebot.MediaTypes.*;
import static net.filebot.UserFiles.*; import static net.filebot.UserFiles.*;
import static net.filebot.media.XattrMetaInfo.*;
import static net.filebot.util.ui.SwingUI.*; import static net.filebot.util.ui.SwingUI.*;
import java.awt.Color; import java.awt.Color;
@ -52,7 +53,6 @@ import javax.swing.table.TableRowSorter;
import net.filebot.ResourceManager; import net.filebot.ResourceManager;
import net.filebot.format.ExpressionFormat; import net.filebot.format.ExpressionFormat;
import net.filebot.format.MediaBindingBean; import net.filebot.format.MediaBindingBean;
import net.filebot.media.MediaDetection;
import net.filebot.mediainfo.MediaInfo; import net.filebot.mediainfo.MediaInfo;
import net.filebot.mediainfo.MediaInfo.StreamKind; import net.filebot.mediainfo.MediaInfo.StreamKind;
import net.filebot.util.DefaultThreadFactory; import net.filebot.util.DefaultThreadFactory;
@ -378,7 +378,7 @@ class BindingDialog extends JDialog {
mediaFileTextField.setText(file.get(0).getAbsolutePath()); mediaFileTextField.setText(file.get(0).getAbsolutePath());
// set info object from xattr if possible // 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) { if (object != null && infoObjectFormat.format(object) != null) {
setInfoObject(object); setInfoObject(object);
} }

View File

@ -8,11 +8,11 @@ import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import net.filebot.similarity.Match;
import ca.odell.glazedlists.BasicEventList; import ca.odell.glazedlists.BasicEventList;
import ca.odell.glazedlists.EventList; import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.TransformedList; import ca.odell.glazedlists.TransformedList;
import ca.odell.glazedlists.event.ListEvent; import ca.odell.glazedlists.event.ListEvent;
import net.filebot.similarity.Match;
public class MatchModel<Value, Candidate> { public class MatchModel<Value, Candidate> {

View File

@ -4,6 +4,7 @@ import static java.util.Collections.*;
import static javax.swing.JOptionPane.*; import static javax.swing.JOptionPane.*;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.Settings.*; import static net.filebot.Settings.*;
import static net.filebot.media.XattrMetaInfo.*;
import static net.filebot.util.ExceptionUtilities.*; import static net.filebot.util.ExceptionUtilities.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.ui.SwingUI.*; import static net.filebot.util.ui.SwingUI.*;
@ -46,7 +47,6 @@ import net.filebot.NativeRenameAction;
import net.filebot.ResourceManager; import net.filebot.ResourceManager;
import net.filebot.StandardRenameAction; import net.filebot.StandardRenameAction;
import net.filebot.mac.MacAppUtilities; import net.filebot.mac.MacAppUtilities;
import net.filebot.media.MediaDetection;
import net.filebot.similarity.Match; import net.filebot.similarity.Match;
import net.filebot.util.ui.ProgressDialog; import net.filebot.util.ui.ProgressDialog;
import net.filebot.util.ui.ProgressDialog.Cancellable; import net.filebot.util.ui.ProgressDialog.Cancellable;
@ -118,19 +118,15 @@ class RenameAction extends AbstractAction {
// write metadata into xattr if xattr is enabled // write metadata into xattr if xattr is enabled
if (useExtendedFileAttributes() || useCreationDate()) { if (useExtendedFileAttributes() || useCreationDate()) {
try { for (Match<Object, File> match : matches) {
for (Match<Object, File> match : matches) { File file = match.getCandidate();
File file = match.getCandidate(); Object meta = match.getValue();
Object meta = match.getValue(); if (renameMap.containsKey(file) && meta != null) {
if (renameMap.containsKey(file) && meta != null) { File destination = resolveDestination(file, renameMap.get(file), false);
File destination = resolveDestination(file, renameMap.get(file), false); if (destination.isFile()) {
if (destination.isFile()) { xattr.storeMetaInfo(destination, meta, file.getName());
MediaDetection.storeMetaInfo(destination, meta, file.getName(), useExtendedFileAttributes(), useCreationDate());
}
} }
} }
} catch (Throwable e) {
debug.warning("Failed to write xattr: " + e.getMessage());
} }
} }
} catch (ExecutionException e) { } catch (ExecutionException e) {

View File

@ -6,6 +6,7 @@ import static javax.swing.KeyStroke.*;
import static javax.swing.SwingUtilities.*; import static javax.swing.SwingUtilities.*;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.Settings.*; import static net.filebot.Settings.*;
import static net.filebot.media.XattrMetaInfo.*;
import static net.filebot.util.ExceptionUtilities.*; import static net.filebot.util.ExceptionUtilities.*;
import static net.filebot.util.ui.LoadingOverlayPane.*; import static net.filebot.util.ui.LoadingOverlayPane.*;
import static net.filebot.util.ui.SwingUI.*; import static net.filebot.util.ui.SwingUI.*;
@ -64,7 +65,6 @@ import net.filebot.UserFiles;
import net.filebot.WebServices; import net.filebot.WebServices;
import net.filebot.format.MediaBindingBean; import net.filebot.format.MediaBindingBean;
import net.filebot.mac.MacAppUtilities; import net.filebot.mac.MacAppUtilities;
import net.filebot.media.MediaDetection;
import net.filebot.similarity.Match; import net.filebot.similarity.Match;
import net.filebot.ui.rename.FormatDialog.Mode; import net.filebot.ui.rename.FormatDialog.Mode;
import net.filebot.ui.rename.RenameModel.FormattedFuture; import net.filebot.ui.rename.RenameModel.FormattedFuture;
@ -333,7 +333,7 @@ public class RenamePanel extends JComponent {
List<Object> objects = new ArrayList<Object>(files.size()); List<Object> objects = new ArrayList<Object>(files.size());
List<File> objectsTail = new ArrayList<File>(); List<File> objectsTail = new ArrayList<File>();
for (File file : files) { for (File file : files) {
Object metaObject = MediaDetection.readMetaInfo(file); Object metaObject = xattr.readMetaInfo(file);
if (metaObject != null) { if (metaObject != null) {
objects.add(metaObject); // upper list is based on xattr metadata objects.add(metaObject); // upper list is based on xattr metadata
} else { } else {