+ added {localize} binding to allow just-in-time localization of movie/episode data

Episode Format Example: {localize.German.Title}
Movie Format Example: {localize.Chinese.Name}
This commit is contained in:
Reinhard Pointner 2016-01-17 07:01:53 +00:00
parent 000bd92325
commit a226a4de0f
2 changed files with 46 additions and 5 deletions

View File

@ -0,0 +1,20 @@
package net.filebot.format;
import groovy.lang.GroovyObjectSupport;
import java.util.function.Function;
public class DynamicBindings extends GroovyObjectSupport {
private Function<String, Object> map;
public DynamicBindings(Function<String, Object> map) {
this.map = map;
}
@Override
public Object getProperty(String property) {
return map.apply(property);
}
}

View File

@ -612,12 +612,33 @@ public class MediaBindingBean {
@Define("episodelist") @Define("episodelist")
public Object getEpisodeList() throws Exception { public Object getEpisodeList() throws Exception {
for (EpisodeListProvider service : WebServices.getEpisodeListProviders()) { return WebServices.getEpisodeListProvider(getSeriesInfo().getDatabase()).getEpisodeList(getSeriesInfo().getId(), SortOrder.forName(getSeriesInfo().getOrder()), new Locale(getSeriesInfo().getLanguage()));
if (getSeriesInfo().getDatabase().equals(service.getName())) { }
return service.getEpisodeList(getSeriesInfo().getId(), SortOrder.forName(getSeriesInfo().getOrder()), new Locale(getSeriesInfo().getLanguage()));
@Define("localize")
public Object getLocalizedInfoObject() throws Exception {
return new DynamicBindings(key -> {
Language language = Language.findLanguage(key);
if (language != null) {
Object localizedInfo = null;
try {
if (infoObject instanceof Movie) {
localizedInfo = WebServices.TheMovieDB.getMovieInfo(getMovie(), language.getLocale(), false);
} else if (infoObject instanceof Episode) {
EpisodeListProvider db = WebServices.getEpisodeListProvider(getSeriesInfo().getDatabase());
List<Episode> episodes = db.getEpisodeList(getSeriesInfo().getId(), SortOrder.forName(getSeriesInfo().getOrder()), language.getLocale());
localizedInfo = episodes.stream().filter(it -> getEpisode().getNumbers().equals(it.getNumbers())).findFirst().orElse(null);
}
} catch (Exception e) {
throw new BindingException(key, e);
}
if (localizedInfo != null) {
return createMapBindings(new PropertyBindings(localizedInfo, null));
}
} }
} return undefined(key);
return null; });
} }
@Define("bitrate") @Define("bitrate")