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;
|
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")
|
@Define("localize")
|
||||||
public Object 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) {
|
if (language == null) {
|
||||||
|
@ -690,13 +707,13 @@ public class MediaBindingBean {
|
||||||
try {
|
try {
|
||||||
if (infoObject instanceof Movie) {
|
if (infoObject instanceof Movie) {
|
||||||
MovieInfo m = getMovieInfo(language.getLocale(), true);
|
MovieInfo m = getMovieInfo(language.getLocale(), true);
|
||||||
return createPropertyBindings(m);
|
return createPropertyBindings(m); // TODO use createBindingObject -> BREAKING CHANGE
|
||||||
}
|
}
|
||||||
if (infoObject instanceof Episode) {
|
if (infoObject instanceof Episode) {
|
||||||
SeriesInfo i = getSeriesInfo();
|
SeriesInfo i = getSeriesInfo();
|
||||||
List<Episode> es = getEpisodeListProvider(i.getDatabase()).getEpisodeList(i.getId(), SortOrder.forName(i.getOrder()), language.getLocale());
|
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();
|
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) {
|
} catch (Exception e) {
|
||||||
throw new BindingException(k, e);
|
throw new BindingException(k, e);
|
||||||
|
@ -725,18 +742,6 @@ public class MediaBindingBean {
|
||||||
return getEpisodes().stream().anyMatch(it -> isRegular(it));
|
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")
|
@Define("episodelist")
|
||||||
public List<Episode> getEpisodeList() throws Exception {
|
public List<Episode> getEpisodeList() throws Exception {
|
||||||
SeriesInfo i = getSeriesInfo();
|
SeriesInfo i = getSeriesInfo();
|
||||||
|
@ -1036,6 +1041,17 @@ public class MediaBindingBean {
|
||||||
return getMediaFile();
|
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() {
|
public SeriesInfo getPrimarySeriesInfo() {
|
||||||
if (TheTVDB.getIdentifier().equals(getSeriesInfo().getDatabase())) {
|
if (TheTVDB.getIdentifier().equals(getSeriesInfo().getDatabase())) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -8,13 +8,25 @@ import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import net.filebot.WebServices;
|
import net.filebot.WebServices;
|
||||||
|
|
||||||
public final class EpisodeUtilities {
|
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) {
|
public static List<Episode> getMultiEpisodeList(Episode e) {
|
||||||
return e instanceof MultiEpisode ? ((MultiEpisode) e).getEpisodes() : singletonList(e);
|
return e instanceof MultiEpisode ? ((MultiEpisode) e).getEpisodes() : singletonList(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,10 @@ public class MultiEpisode extends Episode {
|
||||||
return episodes[0].getAirdate();
|
return episodes[0].getAirdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return episodes[0].getId();
|
||||||
|
}
|
||||||
|
|
||||||
public SeriesInfo getSeriesInfo() {
|
public SeriesInfo getSeriesInfo() {
|
||||||
return episodes[0].getSeriesInfo();
|
return episodes[0].getSeriesInfo();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,23 @@
|
||||||
package net.filebot.web;
|
package net.filebot.web;
|
||||||
|
|
||||||
|
import static java.util.Arrays.*;
|
||||||
|
import static java.util.stream.Collectors.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public enum SortOrder {
|
public enum SortOrder {
|
||||||
|
|
||||||
Airdate, DVD, Absolute;
|
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) {
|
public static SortOrder forName(String name) {
|
||||||
for (SortOrder order : SortOrder.values()) {
|
for (SortOrder order : SortOrder.values()) {
|
||||||
if (order.name().equalsIgnoreCase(name)) {
|
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