+ 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]}
This commit is contained in:
Reinhard Pointner 2016-04-07 08:23:17 +00:00
parent 51c4bc7a9d
commit 7f1b5b290c
1 changed files with 20 additions and 52 deletions

View File

@ -626,7 +626,7 @@ public class MediaBindingBean {
throw new UnsupportedOperationException("Extended metadata not available"); throw new UnsupportedOperationException("Extended metadata not available");
} }
return createMapBindings(new PropertyBindings(metaInfo, null)); return createPropertyBindings(metaInfo);
} }
@Define("omdb") @Define("omdb")
@ -660,7 +660,7 @@ public class MediaBindingBean {
throw new UnsupportedOperationException("Extended metadata not available"); throw new UnsupportedOperationException("Extended metadata not available");
} }
return createMapBindings(new PropertyBindings(metaInfo, null)); return createPropertyBindings(metaInfo);
} }
@Define("az") @Define("az")
@ -696,7 +696,7 @@ public class MediaBindingBean {
} }
if (localizedInfo != null) { if (localizedInfo != null) {
return createMapBindings(new PropertyBindings(localizedInfo, null)); return createPropertyBindings(localizedInfo);
} }
} }
return undefined(key); return undefined(key);
@ -725,62 +725,37 @@ public class MediaBindingBean {
@Define("media") @Define("media")
public AssociativeScriptObject getGeneralMediaInfo() { public AssociativeScriptObject getGeneralMediaInfo() {
return createMapBindings(getMediaInfo().snapshot(StreamKind.General, 0)); return createMediaInfoBindings(StreamKind.General).get(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));
} }
@Define("menu") @Define("menu")
public AssociativeScriptObject getMenuInfo() { public AssociativeScriptObject getMenuInfo() {
return createMapBindings(getMediaInfo().snapshot(StreamKind.Menu, 0)); return createMediaInfoBindings(StreamKind.Menu).get(0);
} }
@Define("image") @Define("image")
public AssociativeScriptObject getImageInfo() { public AssociativeScriptObject getImageInfo() {
return createMapBindings(getMediaInfo().snapshot(StreamKind.Image, 0)); return createMediaInfoBindings(StreamKind.Image).get(0);
} }
@Define("videos") @Define("video")
public List<AssociativeScriptObject> getVideoInfoList() { public List<AssociativeScriptObject> getVideoInfoList() {
return createMapBindingsList(getMediaInfo().snapshot().get(StreamKind.Video)); return createMediaInfoBindings(StreamKind.Video);
} }
@Define("audios") @Define("audio")
public List<AssociativeScriptObject> getAudioInfoList() { public List<AssociativeScriptObject> getAudioInfoList() {
return createMapBindingsList(getMediaInfo().snapshot().get(StreamKind.Audio)); return createMediaInfoBindings(StreamKind.Audio);
} }
@Define("texts") @Define("text")
public List<AssociativeScriptObject> getTextInfoList() { public List<AssociativeScriptObject> getTextInfoList() {
return createMapBindingsList(getMediaInfo().snapshot().get(StreamKind.Text)); return createMediaInfoBindings(StreamKind.Text);
}
@Define("menus")
public List<AssociativeScriptObject> getMenuInfoList() {
return createMapBindingsList(getMediaInfo().snapshot().get(StreamKind.Menu));
} }
@Define("chapters") @Define("chapters")
public List<AssociativeScriptObject> getChaptersInfoList() { public List<AssociativeScriptObject> getChaptersInfoList() {
return createMapBindingsList(getMediaInfo().snapshot().get(StreamKind.Chapters)); return createMediaInfoBindings(StreamKind.Chapters);
}
@Define("images")
public List<AssociativeScriptObject> getImageInfoList() {
return createMapBindingsList(getMediaInfo().snapshot().get(StreamKind.Image));
} }
@Define("artist") @Define("artist")
@ -1034,6 +1009,7 @@ public class MediaBindingBean {
private AssociativeScriptObject createBindingObject(File file, Object info, Map<File, ?> context) { private AssociativeScriptObject createBindingObject(File file, Object info, Map<File, ?> context) {
MediaBindingBean mediaBindingBean = new MediaBindingBean(info, file, context) { MediaBindingBean mediaBindingBean = new MediaBindingBean(info, file, context) {
@Override @Override
@Define(undefined) @Define(undefined)
public <T> T undefined(String name) { public <T> T undefined(String name) {
@ -1043,33 +1019,25 @@ public class MediaBindingBean {
return new AssociativeScriptObject(new ExpressionBindings(mediaBindingBean)); return new AssociativeScriptObject(new ExpressionBindings(mediaBindingBean));
} }
private AssociativeScriptObject createMapBindings(Map<?, ?> map) { private AssociativeScriptObject createPropertyBindings(Object object) {
return new AssociativeScriptObject(map) { return new AssociativeScriptObject(new PropertyBindings(object, null)) {
@Override @Override
public Object getProperty(String name) { public Object getProperty(String name) {
Object value = super.getProperty(name); Object value = super.getProperty(name);
if (value == null) { if (value == null) {
undefined(name); return undefined(name);
} }
// auto-clean value of path separators
if (value instanceof CharSequence) { if (value instanceof CharSequence) {
return replacePathSeparators(value.toString()).trim(); return replacePathSeparators(value.toString()).trim(); // auto-clean value of path separators
} }
return value; return value;
} }
}; };
} }
private List<AssociativeScriptObject> createMapBindingsList(List<Map<String, String>> mapList) { private List<AssociativeScriptObject> createMediaInfoBindings(StreamKind kind) {
List<AssociativeScriptObject> bindings = new ArrayList<AssociativeScriptObject>(); return getMediaInfo().snapshot().get(kind).stream().map(AssociativeScriptObject::new).collect(toList());
for (Map<?, ?> it : mapList) {
bindings.add(createMapBindings(it));
}
return bindings;
} }
private String getOriginalFileName(File file) { private String getOriginalFileName(File file) {