1
0
mirror of https://github.com/mitb-archive/filebot synced 2025-01-11 05:48:01 -05:00

Support dynamic SortOrder binding {order}

e.g. {order.Airdate.SxE}
This commit is contained in:
Reinhard Pointner 2016-11-23 01:17:59 +08:00
parent 8745f1ccfe
commit 5334fb38ef
2 changed files with 32 additions and 27 deletions

View File

@ -1,7 +1,6 @@
package net.filebot.format; package net.filebot.format;
import java.util.Collection; import java.util.Collection;
import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import groovy.lang.GroovyObjectSupport; import groovy.lang.GroovyObjectSupport;
@ -9,16 +8,23 @@ import groovy.lang.GroovyObjectSupport;
public class DynamicBindings extends GroovyObjectSupport { public class DynamicBindings extends GroovyObjectSupport {
private Supplier<Collection<?>> keys; private Supplier<Collection<?>> keys;
private Function<String, Object> properties; private Get<String, Object> properties;
public DynamicBindings(Supplier<Collection<?>> keys, Function<String, Object> properties) { public DynamicBindings(Supplier<Collection<?>> keys, Get<String, Object> properties) {
this.keys = keys; this.keys = keys;
this.properties = properties; this.properties = properties;
} }
@Override @Override
public Object getProperty(String property) { public Object getProperty(String property) {
return properties.apply(property); try {
return properties.get(property);
} catch (Exception e) {
if (e instanceof BindingException) {
throw (BindingException) e;
}
throw new BindingException(property, e.getMessage(), e);
}
} }
@Override @Override
@ -26,4 +32,9 @@ public class DynamicBindings extends GroovyObjectSupport {
return keys.get().toString(); return keys.get().toString();
} }
@FunctionalInterface
public interface Get<T, R> {
R get(T t) throws Exception;
}
} }

View File

@ -683,15 +683,15 @@ public class MediaBindingBean {
public DynamicBindings getSortOrderObject() { public DynamicBindings getSortOrderObject() {
return new DynamicBindings(SortOrder::names, k -> { return new DynamicBindings(SortOrder::names, k -> {
if (infoObject instanceof Episode) { if (infoObject instanceof Episode) {
try { SortOrder order = SortOrder.forName(k);
SortOrder order = SortOrder.forName(k); SeriesInfo info = getSeriesInfo();
SeriesInfo info = getSeriesInfo();
List<Episode> episodeList = getEpisodeListProvider(info.getDatabase()).getEpisodeList(info.getId(), order, new Locale(info.getLanguage())); List<Episode> episodeList = getEpisodeListProvider(info.getDatabase()).getEpisodeList(info.getId(), order, new Locale(info.getLanguage()));
return createBindingObject(null, createEpisode(episodeList.stream().filter(e -> getEpisodes().contains(e))), null); Episode episode = createEpisode(episodeList.stream().filter(e -> getEpisodes().contains(e)));
} catch (Exception e) {
throw new BindingException(k, e); return createBindingObject(null, episode, null);
}
} }
return undefined(k); return undefined(k);
}); });
} }
@ -700,23 +700,17 @@ public class MediaBindingBean {
public DynamicBindings getLocalizedInfoObject() { public DynamicBindings getLocalizedInfoObject() {
return new DynamicBindings(Language::availableLanguages, k -> { return new DynamicBindings(Language::availableLanguages, k -> {
Language language = Language.findLanguage(k); Language language = Language.findLanguage(k);
if (language == null) {
return undefined(k); if (language != null && infoObject instanceof Movie) {
MovieInfo m = getMovieInfo(language.getLocale(), true);
return createPropertyBindings(m); // TODO use createBindingObject -> BREAKING CHANGE
} }
try { if (language != null && infoObject instanceof Episode) {
if (infoObject instanceof Movie) { SeriesInfo i = getSeriesInfo();
MovieInfo m = getMovieInfo(language.getLocale(), true); List<Episode> es = getEpisodeListProvider(i.getDatabase()).getEpisodeList(i.getId(), SortOrder.forName(i.getOrder()), language.getLocale());
return createPropertyBindings(m); // TODO use createBindingObject -> BREAKING CHANGE Episode e = es.stream().filter(it -> getEpisode().getNumbers().equals(it.getNumbers())).findFirst().get();
} return createPropertyBindings(e); // TODO use createBindingObject -> BREAKING CHANGE
if (infoObject instanceof Episode) {
SeriesInfo i = getSeriesInfo();
List<Episode> es = getEpisodeListProvider(i.getDatabase()).getEpisodeList(i.getId(), SortOrder.forName(i.getOrder()), language.getLocale());
Episode e = es.stream().filter(it -> getEpisode().getNumbers().equals(it.getNumbers())).findFirst().get();
return createPropertyBindings(e); // TODO use createBindingObject -> BREAKING CHANGE
}
} catch (Exception e) {
throw new BindingException(k, e);
} }
return undefined(k); return undefined(k);