1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-12 04:15:00 -05:00

Add anime-lists parser

* https://github.com/ScudLee/anime-lists
This commit is contained in:
Reinhard Pointner 2019-06-08 04:32:00 +07:00
parent 2fb9c4cfd9
commit 480c16b0f8

View File

@ -3,6 +3,7 @@ package net.filebot.web;
import static java.util.Arrays.*; import static java.util.Arrays.*;
import static java.util.stream.Collectors.*; import static java.util.stream.Collectors.*;
import static net.filebot.CachedResource.*; import static net.filebot.CachedResource.*;
import static net.filebot.Logging.*;
import static net.filebot.util.StringUtilities.*; import static net.filebot.util.StringUtilities.*;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -31,25 +32,30 @@ public enum AnimeLists {
public Optional<Episode> map(Episode episode, AnimeLists destination) throws Exception { public Optional<Episode> map(Episode episode, AnimeLists destination) throws Exception {
return find(episode.getSeriesInfo().getId()).map(a -> { return find(episode.getSeriesInfo().getId()).map(a -> {
Integer s = destination.getSeason(a); if (destination == TheTVDB && a.defaulttvdbseason == null) {
Integer e = destination.getEpisodeNumber(a, episode.getEpisode()); // auto-align mode
try {
return WebServices.TheTVDB.getEpisodeList(a.tvdbid, SortOrder.Airdate, Locale.ENGLISH).stream().filter(e -> {
return episode.getEpisode() != null && episode.getEpisode().equals(e.getAbsolute());
}).findFirst().orElse(null);
} catch (Exception e) {
debug.warning(e::toString);
return null;
}
} else {
// offset mode
Integer s = this == AniDB ? null : a.defaulttvdbseason;
Integer e = episode.getEpisode();
return episode.derive(s, e); if (a.episodeoffset != null) {
e = this == AniDB ? e - a.episodeoffset : e + a.episodeoffset;
}
return episode.derive(s, e);
}
}); });
} }
protected Integer getSeason(Entry a) {
return this == AniDB ? null : a.defaulttvdbseason;
}
protected Integer getEpisodeNumber(Entry a, Integer e) {
if (a.episodeoffset != null) {
return this == AniDB ? e - a.episodeoffset : e + a.episodeoffset;
}
return e;
}
public Optional<Integer> map(int id, AnimeLists destination) throws Exception { public Optional<Integer> map(int id, AnimeLists destination) throws Exception {
return find(id).map(destination::getId); return find(id).map(destination::getId);
} }