From 4f04e5f4ab43c903b0346b989a847a0ad1da446c Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 20 Feb 2012 07:07:06 +0000 Subject: [PATCH] * make commonly used meta-info bindings more easy to use --- .../filebot/format/MediaBindingBean.java | 54 +++++++++++++++---- .../filebot/format/PropertyBindings.java | 5 +- .../ui/rename/BindingDialog.properties | 2 +- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/source/net/sourceforge/filebot/format/MediaBindingBean.java b/source/net/sourceforge/filebot/format/MediaBindingBean.java index 1a27e052..5eda8f02 100644 --- a/source/net/sourceforge/filebot/format/MediaBindingBean.java +++ b/source/net/sourceforge/filebot/format/MediaBindingBean.java @@ -305,16 +305,50 @@ public class MediaBindingBean { } + @Define("actors") + public Object getActors() { + return getMetaInfo().getProperty("actors"); + } + + + @Define("genres") + public Object getGenres() { + return getMetaInfo().getProperty("genres"); + } + + + @Define("director") + public Object getDirector() { + return getMetaInfo().getProperty("director"); + } + + + @Define("certification") + public Object getCertification() { + return getMetaInfo().getProperty("certification"); + } + + + @Define("rating") + public Object getRating() { + return getMetaInfo().getProperty("rating"); + } + + @Define("info") - public synchronized Object getMetaInfo() throws Exception { + public synchronized AssociativeScriptObject getMetaInfo() { if (metaInfo == null) { - if (infoObject instanceof Episode) - metaInfo = WebServices.TheTVDB.getSeriesInfoByName(((Episode) infoObject).getSeriesName(), Locale.ENGLISH); - if (infoObject instanceof Movie) - metaInfo = WebServices.TMDb.getMovieInfo((Movie) infoObject, Locale.ENGLISH); + try { + if (infoObject instanceof Episode) + metaInfo = WebServices.TheTVDB.getSeriesInfoByName(((Episode) infoObject).getSeriesName(), Locale.ENGLISH); + if (infoObject instanceof Movie) + metaInfo = WebServices.TMDb.getMovieInfo((Movie) infoObject, Locale.ENGLISH); + } catch (Exception e) { + throw new RuntimeException("Failed to retrieve metadata: " + infoObject, e); + } } - return metaInfo; + return new AssociativeScriptObject(new PropertyBindings(metaInfo, null)); } @@ -325,25 +359,25 @@ public class MediaBindingBean { @Define("media") - public Object getGeneralMediaInfo() { + public AssociativeScriptObject getGeneralMediaInfo() { return new AssociativeScriptObject(getMediaInfo().snapshot(StreamKind.General, 0)); } @Define("video") - public Object getVideoInfo() { + public AssociativeScriptObject getVideoInfo() { return new AssociativeScriptObject(getMediaInfo().snapshot(StreamKind.Video, 0)); } @Define("audio") - public Object getAudioInfo() { + public AssociativeScriptObject getAudioInfo() { return new AssociativeScriptObject(getMediaInfo().snapshot(StreamKind.Audio, 0)); } @Define("text") - public Object getTextInfo() { + public AssociativeScriptObject getTextInfo() { return new AssociativeScriptObject(getMediaInfo().snapshot(StreamKind.Text, 0)); } diff --git a/source/net/sourceforge/filebot/format/PropertyBindings.java b/source/net/sourceforge/filebot/format/PropertyBindings.java index 4ce2d122..bd2a64c2 100644 --- a/source/net/sourceforge/filebot/format/PropertyBindings.java +++ b/source/net/sourceforge/filebot/format/PropertyBindings.java @@ -26,7 +26,7 @@ public class PropertyBindings extends AbstractMap { this.defaultValue = defaultValue; // get method bindings - for (Method method : object.getClass().getMethods()) { + for (Method method : object.getClass().getDeclaredMethods()) { if (method.getReturnType() != void.class && method.getParameterTypes().length == 0) { // normal properties if (method.getName().length() > 3 && method.getName().substring(0, 3).equalsIgnoreCase("get")) { @@ -37,9 +37,6 @@ public class PropertyBindings extends AbstractMap { if (method.getName().length() > 2 && method.getName().substring(0, 3).equalsIgnoreCase("is")) { properties.put(method.getName().substring(2), method); } - - // just bind all methods to their original name as well - properties.put(method.getName(), method); } } } diff --git a/source/net/sourceforge/filebot/ui/rename/BindingDialog.properties b/source/net/sourceforge/filebot/ui/rename/BindingDialog.properties index 00502756..cba1855a 100644 --- a/source/net/sourceforge/filebot/ui/rename/BindingDialog.properties +++ b/source/net/sourceforge/filebot/ui/rename/BindingDialog.properties @@ -2,4 +2,4 @@ parameter.exclude: ^StreamKind|Count$ # preview expressions (keys are tagged so they can be sorted alphabetically) -expressions: n,y,s,e,t,airdate,startdate,absolute,special,imdb,episode,sxe,s00e00,movie,vc,ac,cf,vf,af,resolution,ws,sdhd,source,group,crc32,fn,ext,file,pi,pn,lang,info,info.actors,info.director,info.genres[0],info.certification,info.rating,info.runtime,info.status,media.title,media.durationString,media.overallBitRateString,video.codecID,video.frameRate,video.displayAspectRatioString,video.height,video.scanType,audio.format,audio.bitRateString,audio.language,text.codecInfo,text.language +expressions: n,y,s,e,t,airdate,startdate,absolute,special,imdb,episode,sxe,s00e00,movie,vc,ac,cf,vf,af,resolution,ws,sdhd,source,group,crc32,fn,ext,file,pi,pn,lang,actors,director,genres,certification,rating,info.runtime,info.status,media.title,media.durationString,media.overallBitRateString,video.codecID,video.frameRate,video.displayAspectRatioString,video.height,video.scanType,audio.format,audio.bitRateString,audio.language,text.codecInfo,text.language