mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-21 15:28:52 -05:00
Simplify db checks
This commit is contained in:
parent
cf48247601
commit
f732978eff
@ -9,6 +9,7 @@ import static net.filebot.format.ExpressionFormatFunctions.*;
|
||||
import static net.filebot.media.MediaDetection.*;
|
||||
import static net.filebot.similarity.Normalization.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
import static net.filebot.web.EpisodeUtilities.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -629,14 +630,14 @@ public class ExpressionFormatMethods {
|
||||
* Episode utilities
|
||||
*/
|
||||
public static EpisodeInfo getInfo(Episode self) throws Exception {
|
||||
if (TheTVDB.getIdentifier().equals(self.getSeriesInfo().getDatabase())) {
|
||||
if (isInstance(TheTVDB, self)) {
|
||||
return TheTVDB.getEpisodeInfo(self.getId(), Locale.ENGLISH);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<String> getActors(SeriesInfo self) throws Exception {
|
||||
if (TheTVDB.getIdentifier().equals(self.getDatabase())) {
|
||||
if (isInstance(TheTVDB, self)) {
|
||||
return TheTVDB.getActors(self.getId(), Locale.ENGLISH).stream().map(Person::getName).collect(toList());
|
||||
}
|
||||
return null;
|
||||
|
@ -796,7 +796,7 @@ public class MediaBindingBean {
|
||||
return createBindingObject(e); // do nothing
|
||||
}
|
||||
|
||||
if (AniDB.getIdentifier().equals(e.getSeriesInfo().getDatabase())) {
|
||||
if (isInstance(AniDB, e)) {
|
||||
return AnimeList.map(e, AnimeLists.getDB(e), AnimeLists.DB.TheTVDB).map(this::createBindingObject).orElse(null); // map AniDB to TheTVDB bindings
|
||||
}
|
||||
|
||||
@ -1188,7 +1188,7 @@ public class MediaBindingBean {
|
||||
}
|
||||
|
||||
public SeriesInfo getPrimarySeriesInfo() {
|
||||
if (TheTVDB.getIdentifier().equals(getSeriesInfo().getDatabase())) {
|
||||
if (isInstance(TheTVDB, getSeriesInfo())) {
|
||||
try {
|
||||
return TheTVDB.getSeriesInfo(getSeriesInfo().getId(), Locale.ENGLISH);
|
||||
} catch (Exception e) {
|
||||
|
@ -13,6 +13,7 @@ import static net.filebot.media.XattrMetaInfo.*;
|
||||
import static net.filebot.similarity.Normalization.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
import static net.filebot.web.EpisodeUtilities.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
@ -102,7 +103,7 @@ public class AutoDetection {
|
||||
|
||||
Object metaInfo = xattr.getMetaInfo(f);
|
||||
if (metaInfo instanceof Episode) {
|
||||
return !AniDB.getIdentifier().equals(((Episode) metaInfo).getSeriesInfo().getDatabase()); // return true for known non-Anime Episode objects
|
||||
return !isInstance(AniDB, (Episode) metaInfo); // return true for known non-Anime Episode objects
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -127,7 +128,7 @@ public class AutoDetection {
|
||||
}
|
||||
|
||||
Object metaInfo = xattr.getMetaInfo(f);
|
||||
return metaInfo instanceof Episode && AniDB.getIdentifier().equals(((Episode) metaInfo).getSeriesInfo().getDatabase());
|
||||
return metaInfo instanceof Episode && isInstance(AniDB, (Episode) metaInfo);
|
||||
}
|
||||
|
||||
private boolean findEpisodeNumbers(String s, boolean strict) {
|
||||
|
@ -1,5 +1,8 @@
|
||||
package net.filebot.web;
|
||||
|
||||
import static net.filebot.WebServices.*;
|
||||
import static net.filebot.web.EpisodeUtilities.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Objects;
|
||||
@ -107,7 +110,7 @@ public class Episode implements Serializable {
|
||||
}
|
||||
|
||||
public boolean isAnime() {
|
||||
return seriesInfo != null && (Objects.equals(seriesInfo.getType(), SeriesInfo.TYPE_ANIME) || Objects.equals(seriesInfo.getDatabase(), "AniDB")); // HACK: check database == AniDB for backward compatibility
|
||||
return seriesInfo != null && (Objects.equals(seriesInfo.getType(), SeriesInfo.TYPE_ANIME) || isInstance(AniDB, seriesInfo)); // HACK: check database == AniDB for backward compatibility
|
||||
}
|
||||
|
||||
public boolean isRegular() {
|
||||
|
@ -15,6 +15,14 @@ import java.util.stream.Stream;
|
||||
|
||||
public final class EpisodeUtilities {
|
||||
|
||||
public static boolean isInstance(Datasource db, Episode e) {
|
||||
return e != null && isInstance(db, e.getSeriesInfo());
|
||||
}
|
||||
|
||||
public static boolean isInstance(Datasource db, SeriesInfo i) {
|
||||
return i != null && db.getIdentifier().equals(i.getDatabase());
|
||||
}
|
||||
|
||||
public static Episode mapEpisode(Episode episode, Function<Episode, Episode> mapper) {
|
||||
return createEpisode(streamMultiEpisode(episode).map(mapper).sorted(EPISODE_NUMBERS_COMPARATOR).toArray(Episode[]::new));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user