diff --git a/source/net/sourceforge/filebot/ui/rename/BindingDialog.java b/source/net/sourceforge/filebot/ui/rename/BindingDialog.java index d7d24150..2370569a 100644 --- a/source/net/sourceforge/filebot/ui/rename/BindingDialog.java +++ b/source/net/sourceforge/filebot/ui/rename/BindingDialog.java @@ -128,6 +128,7 @@ class BindingDialog extends JDialog { mediaFileTextField.getDocument().addDocumentListener(changeListener); // disabled by default + infoTextField.setEnabled(false); mediaInfoAction.setEnabled(false); // disable media info action if media file is invalid @@ -236,6 +237,7 @@ class BindingDialog extends JDialog { public void setInfoObject(Object info) { + infoTextField.putClientProperty("model", info); infoTextField.setText(info == null ? "" : infoObjectFormat.format(info)); } @@ -246,18 +248,7 @@ class BindingDialog extends JDialog { public Object getInfoObject() { - try { - // try known object - Object model = infoTextField.getClientProperty("model"); - if (model != null) { - return model; - } - - // or parse user input - return infoObjectFormat.parseObject(infoTextField.getText()); - } catch (Exception e) { - return null; - } + return infoTextField.getClientProperty("model"); } @@ -398,19 +389,15 @@ class BindingDialog extends JDialog { // 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); + if (infoObjectFormat.format(object) != null) { + setInfoObject(object); + } } catch (Exception e) { // ignore invalid data } diff --git a/source/net/sourceforge/filebot/ui/rename/FormatDialog.java b/source/net/sourceforge/filebot/ui/rename/FormatDialog.java index 8e6e4b2c..707bbdbe 100644 --- a/source/net/sourceforge/filebot/ui/rename/FormatDialog.java +++ b/source/net/sourceforge/filebot/ui/rename/FormatDialog.java @@ -22,7 +22,6 @@ import java.beans.PropertyChangeListener; import java.io.File; import java.net.URI; import java.text.Format; -import java.text.ParseException; import java.util.LinkedHashSet; import java.util.List; import java.util.ResourceBundle; @@ -79,6 +78,9 @@ import net.sourceforge.tuned.ui.TunedUtilities; import net.sourceforge.tuned.ui.notification.SeparatorBorder; import net.sourceforge.tuned.ui.notification.SeparatorBorder.Position; +import com.cedarsoftware.util.io.JsonReader; +import com.cedarsoftware.util.io.JsonWriter; + class FormatDialog extends JDialog { @@ -386,14 +388,17 @@ class FormatDialog extends JDialog { try { // restore sample from user preferences String sample = mode.persistentSample().getValue(); - info = mode.getFormat().parseObject(sample); + info = JsonReader.toJava(sample); + if (info == null) { + throw new NullPointerException(); + } } catch (Exception e) { try { // restore sample from application properties ResourceBundle bundle = ResourceBundle.getBundle(getClass().getName()); String sample = bundle.getString(mode.key() + ".sample"); - info = mode.getFormat().parseObject(sample); - } catch (ParseException illegalSample) { + info = JsonReader.toJava(sample); + } catch (Exception illegalSample) { throw new RuntimeException(illegalSample); // won't happen } } @@ -613,7 +618,7 @@ class FormatDialog extends JDialog { sample = new MediaBindingBean(info, file, null); // remember - mode.persistentSample().setValue(info == null ? "" : mode.getFormat().format(info)); + mode.persistentSample().setValue(info == null ? "" : JsonWriter.toJson(info)); persistentSampleFile.setValue(file == null ? "" : sample.getMediaFile().getAbsolutePath()); // reevaluate everything diff --git a/source/net/sourceforge/filebot/ui/rename/FormatDialog.properties b/source/net/sourceforge/filebot/ui/rename/FormatDialog.properties index 1aaa6022..30104f27 100644 --- a/source/net/sourceforge/filebot/ui/rename/FormatDialog.properties +++ b/source/net/sourceforge/filebot/ui/rename/FormatDialog.properties @@ -2,11 +2,11 @@ help.url = http://filebot.sourceforge.net/naming.html episode.syntax: { } \u2026 expression, n \u2026 name, s \u2026 season, e \u2026 episode, t \u2026 title movie.syntax: { } \u2026 expression, n \u2026 name, y \u2026 year -music.syntax: { } \u2026 expression, n \u2026 artist, t \u2026 title, album \u2026 album +music.syntax: { } \u2026 expression, n \u2026 album artist, t \u2026 title, album \u2026 album, pi \u2026 track -episode.sample: Dark Angel - 3x01 - Labyrinth [2009-06-01] -movie.sample: Avatar (2009) Part 1 -music.sample: Leona Lewis - I See You +episode.sample: {"@type":"net.sourceforge.filebot.web.Episode","seriesName":"Firefly","seriesStartDate":{"year":2002,"month":9,"day":20},"season":1,"episode":1,"title":"Serenity","absolute":1,"special":null,"airdate":{"year":2002,"month":12,"day":20}} +movie.sample: {"@type":"net.sourceforge.filebot.web.MoviePart","partIndex":1,"partCount":2,"year":2009,"imdbId":-1,"tmdbId":19995,"name":"Avatar"} +music.sample: {"@type":"net.sourceforge.filebot.web.AudioTrack","artist":"Leona Lewis","title":"I See You","album":"Avatar","albumArtist":"James Horner","trackTitle":null,"albumReleaseDate":{"year":2009,"month":12,"day":11},"mediumIndex":1,"mediumCount":1,"trackIndex":14,"trackCount":14} # basic 1.01 episode.example[0]: {n} - {s}.{e} - {t} @@ -27,7 +27,7 @@ movie.example[2]: {n} {[y, certification, rating]} movie.example[3]: {n.space('.')}.{y}{'.'+source}.{vc} # simple artist - title -music.example[0]: {n} - {t} +music.example[0]: {artist} - {t} # simple artist - album - title music.example[1]: {n} - {album} - {t} # artist - title [crc32]