mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 08:48:51 -05:00
+ 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:
parent
000bd92325
commit
a226a4de0f
20
source/net/filebot/format/DynamicBindings.java
Normal file
20
source/net/filebot/format/DynamicBindings.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
@ -612,12 +612,33 @@ public class MediaBindingBean {
|
||||
|
||||
@Define("episodelist")
|
||||
public Object getEpisodeList() throws Exception {
|
||||
for (EpisodeListProvider service : WebServices.getEpisodeListProviders()) {
|
||||
if (getSeriesInfo().getDatabase().equals(service.getName())) {
|
||||
return service.getEpisodeList(getSeriesInfo().getId(), SortOrder.forName(getSeriesInfo().getOrder()), new Locale(getSeriesInfo().getLanguage()));
|
||||
return WebServices.getEpisodeListProvider(getSeriesInfo().getDatabase()).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 null;
|
||||
return undefined(key);
|
||||
});
|
||||
}
|
||||
|
||||
@Define("bitrate")
|
||||
|
Loading…
Reference in New Issue
Block a user