Support dynamic SortOrder binding {order}
e.g. {order.Airdate.SxE}
This commit is contained in:
parent
029379a650
commit
8745f1ccfe
|
@ -679,8 +679,25 @@ public class MediaBindingBean {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Define("order")
|
||||
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);
|
||||
}
|
||||
}
|
||||
return undefined(k);
|
||||
});
|
||||
}
|
||||
|
||||
@Define("localize")
|
||||
public Object getLocalizedInfoObject() {
|
||||
public DynamicBindings getLocalizedInfoObject() {
|
||||
return new DynamicBindings(Language::availableLanguages, k -> {
|
||||
Language language = Language.findLanguage(k);
|
||||
if (language == null) {
|
||||
|
@ -690,13 +707,13 @@ public class MediaBindingBean {
|
|||
try {
|
||||
if (infoObject instanceof Movie) {
|
||||
MovieInfo m = getMovieInfo(language.getLocale(), true);
|
||||
return createPropertyBindings(m);
|
||||
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);
|
||||
return createPropertyBindings(e); // TODO use createBindingObject -> BREAKING CHANGE
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new BindingException(k, e);
|
||||
|
@ -725,18 +742,6 @@ public class MediaBindingBean {
|
|||
return getEpisodes().stream().anyMatch(it -> isRegular(it));
|
||||
}
|
||||
|
||||
@Define("abs2sxe")
|
||||
public Episode getSeasonEpisode() {
|
||||
if (getEpisodes().stream().allMatch(it -> isAnime(it) && isRegular(it) && !isAbsolute(it))) {
|
||||
try {
|
||||
return getEpisodeByAbsoluteNumber(getEpisode(), TheTVDB, SortOrder.Airdate);
|
||||
} catch (Exception e) {
|
||||
debug.warning(e::toString);
|
||||
}
|
||||
}
|
||||
return getEpisode();
|
||||
}
|
||||
|
||||
@Define("episodelist")
|
||||
public List<Episode> getEpisodeList() throws Exception {
|
||||
SeriesInfo i = getSeriesInfo();
|
||||
|
@ -1036,6 +1041,17 @@ public class MediaBindingBean {
|
|||
return getMediaFile();
|
||||
}
|
||||
|
||||
public Episode getSeasonEpisode() {
|
||||
if (getEpisodes().stream().allMatch(it -> isAnime(it) && isRegular(it) && !isAbsolute(it))) {
|
||||
try {
|
||||
return getEpisodeByAbsoluteNumber(getEpisode(), TheTVDB, SortOrder.Airdate);
|
||||
} catch (Exception e) {
|
||||
debug.warning(e::toString);
|
||||
}
|
||||
}
|
||||
return getEpisode();
|
||||
}
|
||||
|
||||
public SeriesInfo getPrimarySeriesInfo() {
|
||||
if (TheTVDB.getIdentifier().equals(getSeriesInfo().getDatabase())) {
|
||||
try {
|
||||
|
|
|
@ -8,13 +8,25 @@ import java.util.Collection;
|
|||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import net.filebot.WebServices;
|
||||
|
||||
public final class EpisodeUtilities {
|
||||
|
||||
public static Episode createEpisode(Stream<Episode> episode) {
|
||||
List<Episode> es = episode.sorted(EPISODE_NUMBERS_COMPARATOR).collect(toList());
|
||||
|
||||
if (es.isEmpty()) {
|
||||
throw new NoSuchElementException("No such Episode");
|
||||
}
|
||||
|
||||
return es.size() == 1 ? es.get(0) : new MultiEpisode(es);
|
||||
}
|
||||
|
||||
public static List<Episode> getMultiEpisodeList(Episode e) {
|
||||
return e instanceof MultiEpisode ? ((MultiEpisode) e).getEpisodes() : singletonList(e);
|
||||
}
|
||||
|
|
|
@ -55,6 +55,10 @@ public class MultiEpisode extends Episode {
|
|||
return episodes[0].getAirdate();
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return episodes[0].getId();
|
||||
}
|
||||
|
||||
public SeriesInfo getSeriesInfo() {
|
||||
return episodes[0].getSeriesInfo();
|
||||
}
|
||||
|
|
|
@ -1,9 +1,23 @@
|
|||
package net.filebot.web;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public enum SortOrder {
|
||||
|
||||
Airdate, DVD, Absolute;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name() + " Order";
|
||||
}
|
||||
|
||||
public static List<String> names() {
|
||||
return stream(values()).map(SortOrder::name).collect(toList());
|
||||
}
|
||||
|
||||
public static SortOrder forName(String name) {
|
||||
for (SortOrder order : SortOrder.values()) {
|
||||
if (order.name().equalsIgnoreCase(name)) {
|
||||
|
@ -11,11 +25,7 @@ public enum SortOrder {
|
|||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Invalid SortOrder: " + name);
|
||||
throw new IllegalArgumentException("Illegal SortOrder: " + name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s Order", name());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue