mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-17 06:45:06 -05:00
* allow to use xattr metaobject as template for testing format expressions against
This commit is contained in:
parent
130fd657c0
commit
06edf38d3f
@ -3,6 +3,7 @@ package net.sourceforge.filebot.ui.rename;
|
|||||||
|
|
||||||
|
|
||||||
import static net.sourceforge.filebot.MediaTypes.*;
|
import static net.sourceforge.filebot.MediaTypes.*;
|
||||||
|
import static net.sourceforge.filebot.Settings.*;
|
||||||
import static net.sourceforge.filebot.ui.NotificationLogging.*;
|
import static net.sourceforge.filebot.ui.NotificationLogging.*;
|
||||||
import static net.sourceforge.tuned.ui.TunedUtilities.*;
|
import static net.sourceforge.tuned.ui.TunedUtilities.*;
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ import java.util.concurrent.Future;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.script.Compilable;
|
import javax.script.Compilable;
|
||||||
import javax.script.ScriptException;
|
import javax.script.ScriptException;
|
||||||
@ -57,6 +59,8 @@ import net.miginfocom.swing.MigLayout;
|
|||||||
import net.sourceforge.filebot.ResourceManager;
|
import net.sourceforge.filebot.ResourceManager;
|
||||||
import net.sourceforge.filebot.format.ExpressionFormat;
|
import net.sourceforge.filebot.format.ExpressionFormat;
|
||||||
import net.sourceforge.filebot.format.MediaBindingBean;
|
import net.sourceforge.filebot.format.MediaBindingBean;
|
||||||
|
import net.sourceforge.filebot.media.MediaDetection;
|
||||||
|
import net.sourceforge.filebot.media.MetaAttributes;
|
||||||
import net.sourceforge.filebot.mediainfo.MediaInfo;
|
import net.sourceforge.filebot.mediainfo.MediaInfo;
|
||||||
import net.sourceforge.filebot.mediainfo.MediaInfo.StreamKind;
|
import net.sourceforge.filebot.mediainfo.MediaInfo.StreamKind;
|
||||||
import net.sourceforge.filebot.mediainfo.MediaInfoException;
|
import net.sourceforge.filebot.mediainfo.MediaInfoException;
|
||||||
@ -243,6 +247,13 @@ class BindingDialog extends JDialog {
|
|||||||
|
|
||||||
public Object getInfoObject() {
|
public Object getInfoObject() {
|
||||||
try {
|
try {
|
||||||
|
// try known object
|
||||||
|
Object model = infoTextField.getClientProperty("model");
|
||||||
|
if (model != null) {
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
// or parse user input
|
||||||
return infoObjectFormat.parseObject(infoTextField.getText());
|
return infoObjectFormat.parseObject(infoTextField.getText());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
@ -257,7 +268,6 @@ class BindingDialog extends JDialog {
|
|||||||
return file.isAbsolute() ? file : null;
|
return file.isAbsolute() ? file : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected final Action approveAction = new AbstractAction("Use Bindings", ResourceManager.getIcon("dialog.continue")) {
|
protected final Action approveAction = new AbstractAction("Use Bindings", ResourceManager.getIcon("dialog.continue")) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -383,7 +393,31 @@ class BindingDialog extends JDialog {
|
|||||||
|
|
||||||
if (chooser.showOpenDialog(getWindow(evt.getSource())) == JFileChooser.APPROVE_OPTION) {
|
if (chooser.showOpenDialog(getWindow(evt.getSource())) == JFileChooser.APPROVE_OPTION) {
|
||||||
// update text field
|
// update text field
|
||||||
mediaFileTextField.setText(chooser.getSelectedFile().getAbsolutePath());
|
File file = chooser.getSelectedFile();
|
||||||
|
|
||||||
|
// set file
|
||||||
|
mediaFileTextField.setText(file.getAbsolutePath());
|
||||||
|
|
||||||
|
// reset known model
|
||||||
|
infoTextField.putClientProperty("model", null);
|
||||||
|
infoTextField.setEnabled(true);
|
||||||
|
|
||||||
|
// set info object from xattr if possible
|
||||||
|
if (useExtendedFileAttributes()) {
|
||||||
|
try {
|
||||||
|
MetaAttributes xattr = new MetaAttributes(file);
|
||||||
|
try {
|
||||||
|
Object object = xattr.getMetaData();
|
||||||
|
infoTextField.setText(infoObjectFormat.format(object));
|
||||||
|
infoTextField.putClientProperty("model", object);
|
||||||
|
infoTextField.setEnabled(false);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ignore invalid data
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Failed to read xattr: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user