mirror of
https://github.com/mitb-archive/filebot
synced 2025-01-10 21:38:04 -05:00
Support dynamic SortOrder binding {order}
e.g. {order.Airdate.SxE}
This commit is contained in:
parent
8745f1ccfe
commit
5334fb38ef
@ -1,7 +1,6 @@
|
||||
package net.filebot.format;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import groovy.lang.GroovyObjectSupport;
|
||||
@ -9,16 +8,23 @@ import groovy.lang.GroovyObjectSupport;
|
||||
public class DynamicBindings extends GroovyObjectSupport {
|
||||
|
||||
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.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
@ -26,4 +32,9 @@ public class DynamicBindings extends GroovyObjectSupport {
|
||||
return keys.get().toString();
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Get<T, R> {
|
||||
R get(T t) throws Exception;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -683,15 +683,15 @@ public class MediaBindingBean {
|
||||
public DynamicBindings getSortOrderObject() {
|
||||
return new DynamicBindings(SortOrder::names, k -> {
|
||||
if (infoObject instanceof Episode) {
|
||||
try {
|
||||
SortOrder order = SortOrder.forName(k);
|
||||
SeriesInfo info = getSeriesInfo();
|
||||
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);
|
||||
} catch (Exception e) {
|
||||
throw new BindingException(k, e);
|
||||
}
|
||||
SortOrder order = SortOrder.forName(k);
|
||||
SeriesInfo info = getSeriesInfo();
|
||||
|
||||
List<Episode> episodeList = getEpisodeListProvider(info.getDatabase()).getEpisodeList(info.getId(), order, new Locale(info.getLanguage()));
|
||||
Episode episode = createEpisode(episodeList.stream().filter(e -> getEpisodes().contains(e)));
|
||||
|
||||
return createBindingObject(null, episode, null);
|
||||
}
|
||||
|
||||
return undefined(k);
|
||||
});
|
||||
}
|
||||
@ -700,23 +700,17 @@ public class MediaBindingBean {
|
||||
public DynamicBindings getLocalizedInfoObject() {
|
||||
return new DynamicBindings(Language::availableLanguages, 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 (infoObject instanceof Movie) {
|
||||
MovieInfo m = getMovieInfo(language.getLocale(), true);
|
||||
return createPropertyBindings(m); // 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);
|
||||
if (language != null && 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
|
||||
}
|
||||
|
||||
return undefined(k);
|
||||
|
Loading…
Reference in New Issue
Block a user