mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-23 16:28:51 -05:00
Refactor common reload-episode-data tasks
This commit is contained in:
parent
5334fb38ef
commit
9667d3d55c
@ -684,14 +684,9 @@ public class MediaBindingBean {
|
||||
return new DynamicBindings(SortOrder::names, k -> {
|
||||
if (infoObject instanceof Episode) {
|
||||
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)));
|
||||
|
||||
Episode episode = fetchEpisode(getEpisode(), order, null);
|
||||
return createBindingObject(null, episode, null);
|
||||
}
|
||||
|
||||
return undefined(k);
|
||||
});
|
||||
}
|
||||
@ -702,15 +697,13 @@ public class MediaBindingBean {
|
||||
Language language = Language.findLanguage(k);
|
||||
|
||||
if (language != null && infoObject instanceof Movie) {
|
||||
MovieInfo m = getMovieInfo(language.getLocale(), true);
|
||||
return createPropertyBindings(m); // TODO use createBindingObject -> BREAKING CHANGE
|
||||
MovieInfo movie = getMovieInfo(language.getLocale(), true);
|
||||
return createPropertyBindings(movie); // TODO use createBindingObject -> BREAKING CHANGE
|
||||
}
|
||||
|
||||
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
|
||||
Episode episode = fetchEpisode(getEpisode(), null, language.getLocale());
|
||||
return createPropertyBindings(episode); // TODO use createBindingObject -> BREAKING CHANGE
|
||||
}
|
||||
|
||||
return undefined(k);
|
||||
@ -738,9 +731,7 @@ public class MediaBindingBean {
|
||||
|
||||
@Define("episodelist")
|
||||
public List<Episode> getEpisodeList() throws Exception {
|
||||
SeriesInfo i = getSeriesInfo();
|
||||
|
||||
return getEpisodeListProvider(i.getDatabase()).getEpisodeList(i.getId(), SortOrder.forName(i.getOrder()), new Locale(i.getLanguage()));
|
||||
return fetchEpisodeList(getEpisode());
|
||||
}
|
||||
|
||||
@Define("sy")
|
||||
|
@ -2,29 +2,24 @@ package net.filebot.web;
|
||||
|
||||
import static java.util.Collections.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static net.filebot.WebServices.*;
|
||||
|
||||
import java.text.Collator;
|
||||
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");
|
||||
public static Episode createEpisode(List<Episode> episode) {
|
||||
if (episode.isEmpty()) {
|
||||
throw new IllegalArgumentException("No such Episode");
|
||||
}
|
||||
|
||||
return es.size() == 1 ? es.get(0) : new MultiEpisode(es);
|
||||
return episode.size() == 1 ? episode.get(0) : new MultiEpisode(episode);
|
||||
}
|
||||
|
||||
public static List<Episode> getMultiEpisodeList(Episode e) {
|
||||
@ -32,7 +27,7 @@ public final class EpisodeUtilities {
|
||||
}
|
||||
|
||||
public static boolean isAnime(Episode e) {
|
||||
return WebServices.AniDB.getIdentifier().equals(e.getSeriesInfo().getDatabase());
|
||||
return AniDB.getIdentifier().equals(e.getSeriesInfo().getDatabase());
|
||||
}
|
||||
|
||||
public static boolean isRegular(Episode e) {
|
||||
@ -43,6 +38,33 @@ public final class EpisodeUtilities {
|
||||
return e.getAbsolute() != null && e.getSeriesInfo().getOrder() != null && SortOrder.Absolute == SortOrder.valueOf(e.getSeriesInfo().getOrder());
|
||||
}
|
||||
|
||||
public static List<Episode> fetchEpisodeList(Episode episode) throws Exception {
|
||||
return fetchEpisodeList(episode, null, null);
|
||||
}
|
||||
|
||||
public static List<Episode> fetchEpisodeList(Episode episode, SortOrder preferredSortOrder, Locale preferredLocale) throws Exception {
|
||||
SeriesInfo info = episode.getSeriesInfo();
|
||||
|
||||
SortOrder order = preferredSortOrder;
|
||||
if (order == null) {
|
||||
order = SortOrder.valueOf(info.getOrder()); // default to original order
|
||||
}
|
||||
|
||||
Locale locale = preferredLocale;
|
||||
if (locale == null) {
|
||||
locale = new Locale(info.getLanguage()); // default to original locale
|
||||
}
|
||||
|
||||
return getEpisodeListProvider(info.getDatabase()).getEpisodeList(info.getId(), order, locale);
|
||||
}
|
||||
|
||||
public static Episode fetchEpisode(Episode episode, SortOrder preferredSortOrder, Locale preferredLocale) throws Exception {
|
||||
List<Episode> episodeList = fetchEpisodeList(episode, preferredSortOrder, preferredLocale);
|
||||
List<Episode> includes = getMultiEpisodeList(episode);
|
||||
|
||||
return createEpisode(episodeList.stream().filter(includes::contains).sorted(EPISODE_NUMBERS_COMPARATOR).collect(toList()));
|
||||
}
|
||||
|
||||
public static Episode getEpisodeByAbsoluteNumber(Episode e, EpisodeListProvider service, SortOrder order) throws Exception {
|
||||
// e.g. match AniDB episode to TheTVDB episode
|
||||
Set<String> seriesNames = getLenientSeriesNameSet(e);
|
||||
@ -70,7 +92,7 @@ public final class EpisodeUtilities {
|
||||
break;
|
||||
}
|
||||
|
||||
return airdateEpisode.size() == 1 ? airdateEpisode.get(0) : new MultiEpisode(airdateEpisode);
|
||||
return createEpisode(airdateEpisode);
|
||||
}
|
||||
|
||||
// return episode object as is by default
|
||||
|
Loading…
Reference in New Issue
Block a user