From 7f1b5b290c791524d3f1addf0ed60ea92cfe61d6 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 7 Apr 2016 08:23:17 +0000 Subject: [PATCH] + Remove {videos} {audios} etc bindings and replace with {video} {audio} etc bindings which represent a list for all streams. e.g. {videos} becomes {video} {video} becomes {video[0]} --- .../net/filebot/format/MediaBindingBean.java | 72 ++++++------------- 1 file changed, 20 insertions(+), 52 deletions(-) diff --git a/source/net/filebot/format/MediaBindingBean.java b/source/net/filebot/format/MediaBindingBean.java index b0c1ec72..bdd2666c 100644 --- a/source/net/filebot/format/MediaBindingBean.java +++ b/source/net/filebot/format/MediaBindingBean.java @@ -626,7 +626,7 @@ public class MediaBindingBean { throw new UnsupportedOperationException("Extended metadata not available"); } - return createMapBindings(new PropertyBindings(metaInfo, null)); + return createPropertyBindings(metaInfo); } @Define("omdb") @@ -660,7 +660,7 @@ public class MediaBindingBean { throw new UnsupportedOperationException("Extended metadata not available"); } - return createMapBindings(new PropertyBindings(metaInfo, null)); + return createPropertyBindings(metaInfo); } @Define("az") @@ -696,7 +696,7 @@ public class MediaBindingBean { } if (localizedInfo != null) { - return createMapBindings(new PropertyBindings(localizedInfo, null)); + return createPropertyBindings(localizedInfo); } } return undefined(key); @@ -725,62 +725,37 @@ public class MediaBindingBean { @Define("media") public AssociativeScriptObject getGeneralMediaInfo() { - return createMapBindings(getMediaInfo().snapshot(StreamKind.General, 0)); - } - - @Define("video") - public AssociativeScriptObject getVideoInfo() { - return createMapBindings(getMediaInfo().snapshot(StreamKind.Video, 0)); - } - - @Define("audio") - public AssociativeScriptObject getAudioInfo() { - return createMapBindings(getMediaInfo().snapshot(StreamKind.Audio, 0)); - } - - @Define("text") - public AssociativeScriptObject getTextInfo() { - return createMapBindings(getMediaInfo().snapshot(StreamKind.Text, 0)); + return createMediaInfoBindings(StreamKind.General).get(0); } @Define("menu") public AssociativeScriptObject getMenuInfo() { - return createMapBindings(getMediaInfo().snapshot(StreamKind.Menu, 0)); + return createMediaInfoBindings(StreamKind.Menu).get(0); } @Define("image") public AssociativeScriptObject getImageInfo() { - return createMapBindings(getMediaInfo().snapshot(StreamKind.Image, 0)); + return createMediaInfoBindings(StreamKind.Image).get(0); } - @Define("videos") + @Define("video") public List getVideoInfoList() { - return createMapBindingsList(getMediaInfo().snapshot().get(StreamKind.Video)); + return createMediaInfoBindings(StreamKind.Video); } - @Define("audios") + @Define("audio") public List getAudioInfoList() { - return createMapBindingsList(getMediaInfo().snapshot().get(StreamKind.Audio)); + return createMediaInfoBindings(StreamKind.Audio); } - @Define("texts") + @Define("text") public List getTextInfoList() { - return createMapBindingsList(getMediaInfo().snapshot().get(StreamKind.Text)); - } - - @Define("menus") - public List getMenuInfoList() { - return createMapBindingsList(getMediaInfo().snapshot().get(StreamKind.Menu)); + return createMediaInfoBindings(StreamKind.Text); } @Define("chapters") public List getChaptersInfoList() { - return createMapBindingsList(getMediaInfo().snapshot().get(StreamKind.Chapters)); - } - - @Define("images") - public List getImageInfoList() { - return createMapBindingsList(getMediaInfo().snapshot().get(StreamKind.Image)); + return createMediaInfoBindings(StreamKind.Chapters); } @Define("artist") @@ -1034,6 +1009,7 @@ public class MediaBindingBean { private AssociativeScriptObject createBindingObject(File file, Object info, Map context) { MediaBindingBean mediaBindingBean = new MediaBindingBean(info, file, context) { + @Override @Define(undefined) public T undefined(String name) { @@ -1043,33 +1019,25 @@ public class MediaBindingBean { return new AssociativeScriptObject(new ExpressionBindings(mediaBindingBean)); } - private AssociativeScriptObject createMapBindings(Map map) { - return new AssociativeScriptObject(map) { + private AssociativeScriptObject createPropertyBindings(Object object) { + return new AssociativeScriptObject(new PropertyBindings(object, null)) { @Override public Object getProperty(String name) { Object value = super.getProperty(name); - if (value == null) { - undefined(name); + return undefined(name); } - - // auto-clean value of path separators if (value instanceof CharSequence) { - return replacePathSeparators(value.toString()).trim(); + return replacePathSeparators(value.toString()).trim(); // auto-clean value of path separators } - return value; } }; } - private List createMapBindingsList(List> mapList) { - List bindings = new ArrayList(); - for (Map it : mapList) { - bindings.add(createMapBindings(it)); - } - return bindings; + private List createMediaInfoBindings(StreamKind kind) { + return getMediaInfo().snapshot().get(kind).stream().map(AssociativeScriptObject::new).collect(toList()); } private String getOriginalFileName(File file) {