Unify SearchResult classes
This commit is contained in:
parent
fd2ee64c9f
commit
1c74c2ef39
|
@ -385,14 +385,14 @@ new File('anime-list.xml').eachLine('UTF-8') {
|
|||
}
|
||||
|
||||
def anidb_index = anidb.findResults{
|
||||
if (animeExcludes.contains(it.animeId))
|
||||
if (animeExcludes.contains(it.id))
|
||||
return null
|
||||
|
||||
def names = it.effectiveNames*.replaceAll(/\s+/, ' ')*.trim()*.replaceAll(/['`´‘’ʻ]+/, /'/)
|
||||
names = getNamePermutations(names)
|
||||
names = names.findAll{ stripReleaseInfo(it)?.length() > 0 }
|
||||
|
||||
return names.empty ? null : [it.animeId.pad(5)] + names.take(4)
|
||||
return names.empty ? null : [it.id.pad(5)] + names.take(4)
|
||||
}
|
||||
|
||||
// join and sort
|
||||
|
|
|
@ -21,7 +21,6 @@ import net.filebot.media.XattrMetaInfoProvider;
|
|||
import net.filebot.similarity.MetricAvg;
|
||||
import net.filebot.web.AcoustIDClient;
|
||||
import net.filebot.web.AnidbClient;
|
||||
import net.filebot.web.AnidbSearchResult;
|
||||
import net.filebot.web.Datasource;
|
||||
import net.filebot.web.EpisodeListProvider;
|
||||
import net.filebot.web.FanartTVClient;
|
||||
|
@ -38,7 +37,6 @@ import net.filebot.web.SubtitleSearchResult;
|
|||
import net.filebot.web.TMDbClient;
|
||||
import net.filebot.web.TVMazeClient;
|
||||
import net.filebot.web.TheTVDBClient;
|
||||
import net.filebot.web.TheTVDBSearchResult;
|
||||
import net.filebot.web.VideoHashSubtitleService;
|
||||
import one.util.streamex.StreamEx;
|
||||
|
||||
|
@ -120,7 +118,7 @@ public final class WebServices {
|
|||
public synchronized LocalSearch<SearchResult> getLocalIndex() throws Exception {
|
||||
if (localIndex == null) {
|
||||
// fetch data dump
|
||||
TheTVDBSearchResult[] data = releaseInfo.getTheTVDBIndex();
|
||||
SearchResult[] data = releaseInfo.getTheTVDBIndex();
|
||||
|
||||
// index data dump
|
||||
localIndex = new LocalSearch<SearchResult>(asList(data)) {
|
||||
|
@ -142,7 +140,7 @@ public final class WebServices {
|
|||
int id = prime.getId();
|
||||
String name = prime.getName();
|
||||
String[] aliasNames = StreamEx.of(group).flatMap(it -> stream(it.getAliasNames())).remove(name::equals).distinct().toArray(String[]::new);
|
||||
return new TheTVDBSearchResult(name, aliasNames, id);
|
||||
return new SearchResult(id, name, aliasNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -165,7 +163,7 @@ public final class WebServices {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<AnidbSearchResult> getAnimeTitles() throws Exception {
|
||||
public List<SearchResult> getAnimeTitles() throws Exception {
|
||||
return asList(releaseInfo.getAnidbIndex());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,6 @@ import net.filebot.web.MovieIdentificationService;
|
|||
import net.filebot.web.SearchResult;
|
||||
import net.filebot.web.SeriesInfo;
|
||||
import net.filebot.web.SimpleDate;
|
||||
import net.filebot.web.TheTVDBSearchResult;
|
||||
|
||||
public class MediaDetection {
|
||||
|
||||
|
@ -1221,14 +1220,14 @@ public class MediaDetection {
|
|||
String text = new String(readFile(nfo), "UTF-8");
|
||||
|
||||
for (int imdbid : grepImdbId(text)) {
|
||||
TheTVDBSearchResult series = WebServices.TheTVDB.lookupByIMDbID(imdbid, language);
|
||||
SearchResult series = WebServices.TheTVDB.lookupByIMDbID(imdbid, language);
|
||||
if (series != null) {
|
||||
names.add(series);
|
||||
}
|
||||
}
|
||||
|
||||
for (int tvdbid : grepTheTvdbId(text)) {
|
||||
TheTVDBSearchResult series = WebServices.TheTVDB.lookupByID(tvdbid, language);
|
||||
SearchResult series = WebServices.TheTVDB.lookupByID(tvdbid, language);
|
||||
if (series != null) {
|
||||
names.add(series);
|
||||
}
|
||||
|
|
|
@ -44,10 +44,9 @@ import net.filebot.CacheType;
|
|||
import net.filebot.Resource;
|
||||
import net.filebot.util.FileUtilities.RegexFileFilter;
|
||||
import net.filebot.util.SystemProperty;
|
||||
import net.filebot.web.AnidbSearchResult;
|
||||
import net.filebot.web.Movie;
|
||||
import net.filebot.web.SearchResult;
|
||||
import net.filebot.web.SubtitleSearchResult;
|
||||
import net.filebot.web.TheTVDBSearchResult;
|
||||
|
||||
public class ReleaseInfo {
|
||||
|
||||
|
@ -337,11 +336,11 @@ public class ReleaseInfo {
|
|||
return seriesMappings.get();
|
||||
}
|
||||
|
||||
public TheTVDBSearchResult[] getTheTVDBIndex() throws Exception {
|
||||
public SearchResult[] getTheTVDBIndex() throws Exception {
|
||||
return tvdbIndex.get();
|
||||
}
|
||||
|
||||
public AnidbSearchResult[] getAnidbIndex() throws Exception {
|
||||
public SearchResult[] getAnidbIndex() throws Exception {
|
||||
return anidbIndex.get();
|
||||
}
|
||||
|
||||
|
@ -405,26 +404,19 @@ public class ReleaseInfo {
|
|||
protected final Resource<String[]> queryBlacklist = lines("url.query-blacklist", Cache.ONE_WEEK);
|
||||
protected final Resource<String[]> excludeBlacklist = lines("url.exclude-blacklist", Cache.ONE_WEEK);
|
||||
|
||||
protected final Resource<TheTVDBSearchResult[]> tvdbIndex = tsv("url.thetvdb-index", Cache.ONE_WEEK, this::parseSeries, TheTVDBSearchResult[]::new);
|
||||
protected final Resource<AnidbSearchResult[]> anidbIndex = tsv("url.anidb-index", Cache.ONE_WEEK, this::parseAnime, AnidbSearchResult[]::new);
|
||||
protected final Resource<SearchResult[]> tvdbIndex = tsv("url.thetvdb-index", Cache.ONE_WEEK, this::parseSeries, SearchResult[]::new);
|
||||
protected final Resource<SearchResult[]> anidbIndex = tsv("url.anidb-index", Cache.ONE_WEEK, this::parseSeries, SearchResult[]::new);
|
||||
|
||||
protected final Resource<Movie[]> movieIndex = tsv("url.movie-list", Cache.ONE_MONTH, this::parseMovie, Movie[]::new);
|
||||
protected final Resource<SubtitleSearchResult[]> osdbIndex = tsv("url.osdb-index", Cache.ONE_MONTH, this::parseSubtitle, SubtitleSearchResult[]::new);
|
||||
|
||||
protected final SystemProperty<Duration> refreshDuration = SystemProperty.of("url.refresh", Duration::parse, null);
|
||||
|
||||
private TheTVDBSearchResult parseSeries(String[] v) {
|
||||
private SearchResult parseSeries(String[] v) {
|
||||
int id = parseInt(v[0]);
|
||||
String name = v[1];
|
||||
String[] aliasNames = copyOfRange(v, 2, v.length);
|
||||
return new TheTVDBSearchResult(name, aliasNames, id);
|
||||
}
|
||||
|
||||
private AnidbSearchResult parseAnime(String[] v) {
|
||||
int aid = parseInt(v[0]);
|
||||
String primaryTitle = v[1];
|
||||
String[] aliasNames = copyOfRange(v, 2, v.length);
|
||||
return new AnidbSearchResult(aid, primaryTitle, aliasNames);
|
||||
return new SearchResult(id, name, aliasNames);
|
||||
}
|
||||
|
||||
private Movie parseMovie(String[] v) {
|
||||
|
|
|
@ -16,12 +16,6 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
|||
|
||||
protected abstract SeriesData fetchSeriesData(SearchResult searchResult, SortOrder sortOrder, Locale locale) throws Exception;
|
||||
|
||||
protected abstract SearchResult createSearchResult(int id);
|
||||
|
||||
protected abstract SortOrder vetoRequestParameter(SortOrder order);
|
||||
|
||||
protected abstract Locale vetoRequestParameter(Locale language);
|
||||
|
||||
@Override
|
||||
public List<SearchResult> search(String query, Locale language) throws Exception {
|
||||
return getSearchCache(language).computeIfAbsent(query, it -> {
|
||||
|
@ -29,6 +23,14 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
|||
});
|
||||
}
|
||||
|
||||
protected SortOrder vetoRequestParameter(SortOrder order) {
|
||||
return order == null ? SortOrder.Airdate : order;
|
||||
}
|
||||
|
||||
protected Locale vetoRequestParameter(Locale language) {
|
||||
return language == null || language.getLanguage().isEmpty() ? Locale.ENGLISH : language;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Episode> getEpisodeList(SearchResult searchResult, SortOrder sortOrder, Locale language) throws Exception {
|
||||
return getSeriesData(searchResult, sortOrder, language).getEpisodeList();
|
||||
|
@ -36,7 +38,7 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
|||
|
||||
@Override
|
||||
public List<Episode> getEpisodeList(int id, SortOrder order, Locale language) throws Exception {
|
||||
return getEpisodeList(createSearchResult(id), order, language);
|
||||
return getEpisodeList(new SearchResult(id, null), order, language);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,7 +48,7 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
|||
|
||||
@Override
|
||||
public SeriesInfo getSeriesInfo(int id, Locale language) throws Exception {
|
||||
return getSeriesInfo(createSearchResult(id), language);
|
||||
return getSeriesInfo(new SearchResult(id, null), language);
|
||||
}
|
||||
|
||||
protected SeriesData getSeriesData(SearchResult searchResult, SortOrder order, Locale language) throws Exception {
|
||||
|
|
|
@ -69,11 +69,6 @@ public class AnidbClient extends AbstractEpisodeListProvider {
|
|||
return SortOrder.Absolute;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Locale vetoRequestParameter(Locale language) {
|
||||
return language != null ? language : Locale.ENGLISH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Cache getCache(String section) {
|
||||
return Cache.getCache(getName() + "_" + section, CacheType.Weekly);
|
||||
|
@ -98,11 +93,9 @@ public class AnidbClient extends AbstractEpisodeListProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected SeriesData fetchSeriesData(SearchResult searchResult, SortOrder sortOrder, Locale locale) throws Exception {
|
||||
AnidbSearchResult anime = (AnidbSearchResult) searchResult;
|
||||
|
||||
protected SeriesData fetchSeriesData(SearchResult anime, SortOrder sortOrder, Locale locale) throws Exception {
|
||||
// e.g. http://api.anidb.net:9001/httpapi?request=anime&client=filebot&clientver=1&protover=1&aid=4521
|
||||
URL url = new URL("http://api.anidb.net:9001/httpapi?request=anime&client=" + client + "&clientver=" + clientver + "&protover=1&aid=" + anime.getAnimeId());
|
||||
URL url = new URL("http://api.anidb.net:9001/httpapi?request=anime&client=" + client + "&clientver=" + clientver + "&protover=1&aid=" + anime.getId());
|
||||
|
||||
// respect flood protection limits
|
||||
REQUEST_LIMIT.acquirePermit();
|
||||
|
@ -112,7 +105,7 @@ public class AnidbClient extends AbstractEpisodeListProvider {
|
|||
|
||||
// parse series info
|
||||
SeriesInfo seriesInfo = new SeriesInfo(getName(), sortOrder, locale, anime.getId());
|
||||
seriesInfo.setAliasNames(searchResult.getAliasNames());
|
||||
seriesInfo.setAliasNames(anime.getAliasNames());
|
||||
|
||||
// AniDB types: Movie, Music Video, Other, OVA, TV Series, TV Special, Web, unknown
|
||||
String animeType = selectString("//type", dom);
|
||||
|
@ -178,11 +171,6 @@ public class AnidbClient extends AbstractEpisodeListProvider {
|
|||
return new SeriesData(seriesInfo, episodes);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SearchResult createSearchResult(int id) {
|
||||
return new AnidbSearchResult(id, null, new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getEpisodeListLink(SearchResult searchResult) {
|
||||
try {
|
||||
|
@ -195,7 +183,7 @@ public class AnidbClient extends AbstractEpisodeListProvider {
|
|||
/**
|
||||
* This method is overridden in {@link net.filebot.WebServices.AnidbClientWithLocalSearch} to fetch the Anime Index from our own host and not anidb.net
|
||||
*/
|
||||
public synchronized List<AnidbSearchResult> getAnimeTitles() throws Exception {
|
||||
public synchronized List<SearchResult> getAnimeTitles() throws Exception {
|
||||
// get data file (unzip and cache)
|
||||
byte[] bytes = getCache("root").bytes("anime-titles.dat.gz", n -> new URL("http://anidb.net/api/" + n)).get();
|
||||
|
||||
|
@ -242,7 +230,7 @@ public class AnidbClient extends AbstractEpisodeListProvider {
|
|||
}
|
||||
|
||||
// build up a list of all possible AniDB search results
|
||||
List<AnidbSearchResult> anime = new ArrayList<AnidbSearchResult>(entriesByAnime.size());
|
||||
List<SearchResult> anime = new ArrayList<SearchResult>(entriesByAnime.size());
|
||||
|
||||
entriesByAnime.forEach((aid, triples) -> {
|
||||
List<String> names = triples.stream().sorted((a, b) -> {
|
||||
|
@ -255,8 +243,8 @@ public class AnidbClient extends AbstractEpisodeListProvider {
|
|||
}).map(it -> (String) it[2]).collect(toList());
|
||||
|
||||
String primaryTitle = names.get(0);
|
||||
String[] aliasNames = names.subList(1, names.size()).toArray(new String[0]);
|
||||
anime.add(new AnidbSearchResult(aid, primaryTitle, aliasNames));
|
||||
List<String> aliasNames = names.subList(1, names.size());
|
||||
anime.add(new SearchResult(aid, primaryTitle, aliasNames));
|
||||
});
|
||||
|
||||
return anime;
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package net.filebot.web;
|
||||
|
||||
public class AnidbSearchResult extends SearchResult {
|
||||
|
||||
protected AnidbSearchResult() {
|
||||
// used by serializer
|
||||
}
|
||||
|
||||
public AnidbSearchResult(int aid, String primaryTitle, String[] aliasNames) {
|
||||
super(aid, primaryTitle, aliasNames);
|
||||
}
|
||||
|
||||
public int getAnimeId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getPrimaryTitle() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnidbSearchResult clone() {
|
||||
return new AnidbSearchResult(id, name, aliasNames);
|
||||
}
|
||||
|
||||
}
|
|
@ -4,9 +4,10 @@ import static java.util.Collections.*;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.util.AbstractList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class SearchResult implements Serializable {
|
||||
public class SearchResult implements Serializable {
|
||||
|
||||
protected int id;
|
||||
protected String name;
|
||||
|
@ -17,9 +18,11 @@ public abstract class SearchResult implements Serializable {
|
|||
}
|
||||
|
||||
public SearchResult(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.aliasNames = EMPTY_STRING_ARRAY;
|
||||
this(id, name, EMPTY_STRING_ARRAY);
|
||||
}
|
||||
|
||||
public SearchResult(int id, String name, Collection<String> aliasNames) {
|
||||
this(id, name, aliasNames.toArray(EMPTY_STRING_ARRAY));
|
||||
}
|
||||
|
||||
public SearchResult(int id, String name, String[] aliasNames) {
|
||||
|
@ -80,8 +83,10 @@ public abstract class SearchResult implements Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public abstract SearchResult clone();
|
||||
public SearchResult clone() {
|
||||
return new SearchResult(id, name, aliasNames);
|
||||
}
|
||||
|
||||
protected static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
|
||||
}
|
||||
|
|
|
@ -44,11 +44,6 @@ public class TVMazeClient extends AbstractEpisodeListProvider {
|
|||
return Locale.ENGLISH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SearchResult createSearchResult(int id) {
|
||||
return new TVMazeSearchResult(id, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SearchResult> fetchSearchResult(String query, Locale locale) throws Exception {
|
||||
// e.g. http://api.tvmaze.com/search/shows?q=girls
|
||||
|
@ -60,11 +55,11 @@ public class TVMazeClient extends AbstractEpisodeListProvider {
|
|||
Integer id = getInteger(show, "id");
|
||||
String name = getString(show, "name");
|
||||
|
||||
return new TVMazeSearchResult(id, name);
|
||||
return new SearchResult(id, name);
|
||||
}).collect(toList());
|
||||
}
|
||||
|
||||
protected SeriesInfo fetchSeriesInfo(TVMazeSearchResult show, SortOrder sortOrder, Locale locale) throws Exception {
|
||||
protected SeriesInfo fetchSeriesInfo(SearchResult show, SortOrder sortOrder, Locale locale) throws Exception {
|
||||
// e.g. http://api.tvmaze.com/shows/1
|
||||
Object response = request("shows/" + show.getId());
|
||||
|
||||
|
@ -88,7 +83,7 @@ public class TVMazeClient extends AbstractEpisodeListProvider {
|
|||
|
||||
@Override
|
||||
protected SeriesData fetchSeriesData(SearchResult searchResult, SortOrder sortOrder, Locale locale) throws Exception {
|
||||
SeriesInfo seriesInfo = fetchSeriesInfo((TVMazeSearchResult) searchResult, sortOrder, locale);
|
||||
SeriesInfo seriesInfo = fetchSeriesInfo(searchResult, sortOrder, locale);
|
||||
|
||||
// e.g. http://api.tvmaze.com/shows/1/episodes
|
||||
Object response = request("shows/" + seriesInfo.getId() + "/episodes");
|
||||
|
@ -116,7 +111,7 @@ public class TVMazeClient extends AbstractEpisodeListProvider {
|
|||
|
||||
@Override
|
||||
public URI getEpisodeListLink(SearchResult searchResult) {
|
||||
return URI.create("http://www.tvmaze.com/shows/" + ((TVMazeSearchResult) searchResult).getId());
|
||||
return URI.create("http://www.tvmaze.com/shows/" + searchResult.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
package net.filebot.web;
|
||||
|
||||
public class TVMazeSearchResult extends SearchResult {
|
||||
|
||||
protected TVMazeSearchResult() {
|
||||
// used by serializer
|
||||
}
|
||||
|
||||
public TVMazeSearchResult(int id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TVMazeSearchResult clone() {
|
||||
return new TVMazeSearchResult(id, name);
|
||||
}
|
||||
|
||||
}
|
|
@ -61,16 +61,6 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SortOrder vetoRequestParameter(SortOrder order) {
|
||||
return order != null ? order : SortOrder.Airdate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Locale vetoRequestParameter(Locale language) {
|
||||
return language != null ? language : Locale.ENGLISH;
|
||||
}
|
||||
|
||||
public String getLanguageCode(Locale locale) {
|
||||
String code = locale.getLanguage();
|
||||
|
||||
|
@ -98,7 +88,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||
// perform online search
|
||||
Document dom = getXmlResource(MirrorType.SEARCH, "GetSeries.php?seriesname=" + encode(query, true) + "&language=" + getLanguageCode(locale));
|
||||
|
||||
Map<Integer, TheTVDBSearchResult> resultSet = new LinkedHashMap<Integer, TheTVDBSearchResult>();
|
||||
Map<Integer, SearchResult> resultSet = new LinkedHashMap<Integer, SearchResult>();
|
||||
|
||||
for (Node node : selectNodes("Data/Series", dom)) {
|
||||
int sid = matchInteger(getTextContent("seriesid", node));
|
||||
|
@ -119,7 +109,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||
}
|
||||
|
||||
if (!resultSet.containsKey(sid)) {
|
||||
resultSet.put(sid, new TheTVDBSearchResult(seriesName, aliasNames.toArray(new String[0]), sid));
|
||||
resultSet.put(sid, new SearchResult(sid, seriesName, aliasNames));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,14 +117,13 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected SeriesData fetchSeriesData(SearchResult searchResult, SortOrder sortOrder, Locale locale) throws Exception {
|
||||
TheTVDBSearchResult series = (TheTVDBSearchResult) searchResult;
|
||||
Document dom = getXmlResource(MirrorType.XML, "series/" + series.getSeriesId() + "/all/" + getLanguageCode(locale) + ".xml");
|
||||
protected SeriesData fetchSeriesData(SearchResult series, SortOrder sortOrder, Locale locale) throws Exception {
|
||||
Document dom = getXmlResource(MirrorType.XML, "series/" + series.getId() + "/all/" + getLanguageCode(locale) + ".xml");
|
||||
|
||||
// parse series info
|
||||
Node seriesNode = selectNode("Data/Series", dom);
|
||||
TheTVDBSeriesInfo seriesInfo = new TheTVDBSeriesInfo(getName(), sortOrder, locale, series.getId());
|
||||
seriesInfo.setAliasNames(searchResult.getAliasNames());
|
||||
seriesInfo.setAliasNames(series.getAliasNames());
|
||||
|
||||
seriesInfo.setName(getTextContent("SeriesName", seriesNode));
|
||||
seriesInfo.setAirsDayOfWeek(getTextContent("Airs_DayOfWeek", seriesNode));
|
||||
|
@ -218,7 +207,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||
return new SeriesData(seriesInfo, episodes);
|
||||
}
|
||||
|
||||
public TheTVDBSearchResult lookupByID(int id, Locale language) throws Exception {
|
||||
public SearchResult lookupByID(int id, Locale language) throws Exception {
|
||||
if (id <= 0) {
|
||||
throw new IllegalArgumentException("Illegal TheTVDB ID: " + id);
|
||||
}
|
||||
|
@ -227,11 +216,11 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||
Document dom = getXmlResource(MirrorType.XML, "series/" + id + "/all/" + getLanguageCode(language) + ".xml");
|
||||
String name = selectString("//SeriesName", dom);
|
||||
|
||||
return new TheTVDBSearchResult(name, id);
|
||||
return new SearchResult(id, name);
|
||||
});
|
||||
}
|
||||
|
||||
public TheTVDBSearchResult lookupByIMDbID(int imdbid, Locale locale) throws Exception {
|
||||
public SearchResult lookupByIMDbID(int imdbid, Locale locale) throws Exception {
|
||||
if (imdbid <= 0) {
|
||||
throw new IllegalArgumentException("Illegal IMDbID ID: " + imdbid);
|
||||
}
|
||||
|
@ -245,7 +234,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||
if (id.isEmpty() || name.isEmpty())
|
||||
return null;
|
||||
|
||||
return new TheTVDBSearchResult(name, Integer.parseInt(id));
|
||||
return new SearchResult(Integer.parseInt(id), name);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -334,14 +323,9 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||
return getSeriesInfo(lookupByIMDbID(imdbid, locale), locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SearchResult createSearchResult(int id) {
|
||||
return new TheTVDBSearchResult(null, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getEpisodeListLink(SearchResult searchResult) {
|
||||
return URI.create("http://www.thetvdb.com/?tab=seasonall&id=" + ((TheTVDBSearchResult) searchResult).getSeriesId());
|
||||
return URI.create("http://www.thetvdb.com/?tab=seasonall&id=" + searchResult.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -349,7 +333,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||
*
|
||||
* @see http://thetvdb.com/wiki/index.php/API:banners.xml
|
||||
*/
|
||||
public BannerDescriptor getBanner(TheTVDBSearchResult series, Map<?, ?> filterDescriptor) throws Exception {
|
||||
public BannerDescriptor getBanner(SearchResult series, Map<?, ?> filterDescriptor) throws Exception {
|
||||
EnumMap<BannerProperty, String> filter = new EnumMap<BannerProperty, String>(BannerProperty.class);
|
||||
for (Entry<?, ?> it : filterDescriptor.entrySet()) {
|
||||
if (it.getValue() != null) {
|
||||
|
@ -367,7 +351,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||
return null;
|
||||
}
|
||||
|
||||
public List<BannerDescriptor> getBannerList(TheTVDBSearchResult series) throws Exception {
|
||||
public List<BannerDescriptor> getBannerList(SearchResult series) throws Exception {
|
||||
return getBannerCache().computeIfAbsent(series.getId(), it -> {
|
||||
Document dom = getXmlResource(MirrorType.XML, "series/" + series.getId() + "/banners.xml");
|
||||
|
||||
|
@ -382,9 +366,9 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||
});
|
||||
}
|
||||
|
||||
protected TypedCache<TheTVDBSearchResult> getLookupCache(String type, Locale language) {
|
||||
protected TypedCache<SearchResult> getLookupCache(String type, Locale language) {
|
||||
// lookup should always yield the same results so we can cache it for longer
|
||||
return Cache.getCache(getName() + "_" + "lookup" + "_" + type + "_" + language, CacheType.Monthly).cast(TheTVDBSearchResult.class);
|
||||
return Cache.getCache(getName() + "_" + "lookup" + "_" + type + "_" + language, CacheType.Monthly).cast(SearchResult.class);
|
||||
}
|
||||
|
||||
protected TypedCache<List<BannerDescriptor>> getBannerCache() {
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package net.filebot.web;
|
||||
|
||||
public class TheTVDBSearchResult extends SearchResult {
|
||||
|
||||
protected TheTVDBSearchResult() {
|
||||
// used by serializer
|
||||
}
|
||||
|
||||
public TheTVDBSearchResult(String seriesName, int seriesId) {
|
||||
super(seriesId, seriesName);
|
||||
}
|
||||
|
||||
public TheTVDBSearchResult(String seriesName, String[] aliasNames, int seriesId) {
|
||||
super(seriesId, seriesName, aliasNames);
|
||||
}
|
||||
|
||||
public int getSeriesId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TheTVDBSearchResult clone() {
|
||||
return new TheTVDBSearchResult(name, aliasNames, id);
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,6 @@ import static org.junit.Assert.*;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AnidbClientTest {
|
||||
|
@ -15,28 +14,21 @@ public class AnidbClientTest {
|
|||
/**
|
||||
* 74 episodes
|
||||
*/
|
||||
static AnidbSearchResult monsterSearchResult;
|
||||
SearchResult monsterSearchResult = new SearchResult(1539, "Monster");
|
||||
|
||||
/**
|
||||
* 45 episodes
|
||||
*/
|
||||
static AnidbSearchResult twelvekingdomsSearchResult;
|
||||
SearchResult twelvekingdomsSearchResult = new SearchResult(26, "Juuni Kokuki");
|
||||
|
||||
/**
|
||||
* 38 episodes, lots of special characters
|
||||
*/
|
||||
static AnidbSearchResult princessTutuSearchResult;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
monsterSearchResult = new AnidbSearchResult(1539, "Monster", null);
|
||||
twelvekingdomsSearchResult = new AnidbSearchResult(26, "Juuni Kokuki", null);
|
||||
princessTutuSearchResult = new AnidbSearchResult(516, "Princess Tutu", null);
|
||||
}
|
||||
SearchResult princessTutuSearchResult = new SearchResult(516, "Princess Tutu");
|
||||
|
||||
@Test
|
||||
public void getAnimeTitles() throws Exception {
|
||||
List<AnidbSearchResult> animeTitles = anidb.getAnimeTitles();
|
||||
List<SearchResult> animeTitles = anidb.getAnimeTitles();
|
||||
assertTrue(animeTitles.size() > 8000);
|
||||
}
|
||||
|
||||
|
@ -44,9 +36,9 @@ public class AnidbClientTest {
|
|||
public void search() throws Exception {
|
||||
List<SearchResult> results = anidb.search("one piece", Locale.ENGLISH);
|
||||
|
||||
AnidbSearchResult result = (AnidbSearchResult) results.get(0);
|
||||
SearchResult result = results.get(0);
|
||||
assertEquals("One Piece", result.getName());
|
||||
assertEquals(69, result.getAnimeId());
|
||||
assertEquals(69, result.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -13,13 +13,13 @@ public class TVMazeClientTest {
|
|||
/**
|
||||
* 145 episodes / 7 seasons
|
||||
*/
|
||||
private static TVMazeSearchResult buffySearchResult = new TVMazeSearchResult(427, "Buffy the Vampire Slayer");
|
||||
SearchResult buffySearchResult = new SearchResult(427, "Buffy the Vampire Slayer");
|
||||
|
||||
@Test
|
||||
public void search() throws Exception {
|
||||
List<SearchResult> results = client.search("Buffy", Locale.ENGLISH);
|
||||
|
||||
TVMazeSearchResult result = (TVMazeSearchResult) results.get(0);
|
||||
SearchResult result = results.get(0);
|
||||
|
||||
assertEquals(buffySearchResult.getName(), result.getName());
|
||||
assertEquals(buffySearchResult.getId(), result.getId());
|
||||
|
|
|
@ -17,6 +17,10 @@ public class TheTVDBClientTest {
|
|||
|
||||
TheTVDBClient thetvdb = new TheTVDBClient("BA864DEE427E384A");
|
||||
|
||||
SearchResult buffy = new SearchResult(70327, "Buffy the Vampire Slayer");
|
||||
SearchResult wonderfalls = new SearchResult(78845, "Wonderfalls");
|
||||
SearchResult firefly = new SearchResult(78874, "Firefly");
|
||||
|
||||
@Test
|
||||
public void search() throws Exception {
|
||||
// test default language and query escaping (blanks)
|
||||
|
@ -24,10 +28,10 @@ public class TheTVDBClientTest {
|
|||
|
||||
assertEquals(2, results.size());
|
||||
|
||||
TheTVDBSearchResult first = (TheTVDBSearchResult) results.get(0);
|
||||
SearchResult first = results.get(0);
|
||||
|
||||
assertEquals("Babylon 5", first.getName());
|
||||
assertEquals(70726, first.getSeriesId());
|
||||
assertEquals(70726, first.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -36,15 +40,15 @@ public class TheTVDBClientTest {
|
|||
|
||||
assertEquals(2, results.size());
|
||||
|
||||
TheTVDBSearchResult first = (TheTVDBSearchResult) results.get(0);
|
||||
SearchResult first = results.get(0);
|
||||
|
||||
assertEquals("Buffy the Vampire Slayer", first.getName());
|
||||
assertEquals(70327, first.getSeriesId());
|
||||
assertEquals(70327, first.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEpisodeListAll() throws Exception {
|
||||
List<Episode> list = thetvdb.getEpisodeList(new TheTVDBSearchResult("Buffy the Vampire Slayer", 70327), SortOrder.Airdate, Locale.ENGLISH);
|
||||
List<Episode> list = thetvdb.getEpisodeList(buffy, SortOrder.Airdate, Locale.ENGLISH);
|
||||
|
||||
assertTrue(list.size() >= 144);
|
||||
|
||||
|
@ -71,7 +75,7 @@ public class TheTVDBClientTest {
|
|||
|
||||
@Test
|
||||
public void getEpisodeListSingleSeason() throws Exception {
|
||||
List<Episode> list = thetvdb.getEpisodeList(new TheTVDBSearchResult("Wonderfalls", 78845), SortOrder.Airdate, Locale.ENGLISH);
|
||||
List<Episode> list = thetvdb.getEpisodeList(wonderfalls, SortOrder.Airdate, Locale.ENGLISH);
|
||||
|
||||
Episode first = list.get(0);
|
||||
|
||||
|
@ -86,7 +90,7 @@ public class TheTVDBClientTest {
|
|||
|
||||
@Test
|
||||
public void getEpisodeListNumbering() throws Exception {
|
||||
List<Episode> list = thetvdb.getEpisodeList(new TheTVDBSearchResult("Firefly", 78874), SortOrder.DVD, Locale.ENGLISH);
|
||||
List<Episode> list = thetvdb.getEpisodeList(firefly, SortOrder.DVD, Locale.ENGLISH);
|
||||
|
||||
Episode first = list.get(0);
|
||||
assertEquals("Firefly", first.getSeriesName());
|
||||
|
@ -98,9 +102,8 @@ public class TheTVDBClientTest {
|
|||
assertEquals("2002-12-20", first.getAirdate().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEpisodeListLink() {
|
||||
assertEquals("http://www.thetvdb.com/?tab=seasonall&id=78874", thetvdb.getEpisodeListLink(new TheTVDBSearchResult("Firefly", 78874)).toString());
|
||||
assertEquals("http://www.thetvdb.com/?tab=seasonall&id=78874", thetvdb.getEpisodeListLink(firefly).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -114,21 +117,21 @@ public class TheTVDBClientTest {
|
|||
|
||||
@Test
|
||||
public void lookupByID() throws Exception {
|
||||
TheTVDBSearchResult series = thetvdb.lookupByID(78874, Locale.ENGLISH);
|
||||
SearchResult series = thetvdb.lookupByID(78874, Locale.ENGLISH);
|
||||
assertEquals("Firefly", series.getName());
|
||||
assertEquals(78874, series.getSeriesId());
|
||||
assertEquals(78874, series.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lookupByIMDbID() throws Exception {
|
||||
TheTVDBSearchResult series = thetvdb.lookupByIMDbID(303461, Locale.ENGLISH);
|
||||
SearchResult series = thetvdb.lookupByIMDbID(303461, Locale.ENGLISH);
|
||||
assertEquals("Firefly", series.getName());
|
||||
assertEquals(78874, series.getSeriesId());
|
||||
assertEquals(78874, series.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSeriesInfo() throws Exception {
|
||||
TheTVDBSeriesInfo it = (TheTVDBSeriesInfo) thetvdb.getSeriesInfo(new TheTVDBSearchResult(null, 80348), Locale.ENGLISH);
|
||||
TheTVDBSeriesInfo it = (TheTVDBSeriesInfo) thetvdb.getSeriesInfo(80348, Locale.ENGLISH);
|
||||
|
||||
assertEquals(80348, it.getId(), 0);
|
||||
assertEquals("TV-PG", it.getContentRating());
|
||||
|
@ -149,7 +152,7 @@ public class TheTVDBClientTest {
|
|||
filter.put("Season", "7");
|
||||
filter.put("Language", "en");
|
||||
|
||||
BannerDescriptor banner = thetvdb.getBanner(new TheTVDBSearchResult("Buffy the Vampire Slayer", 70327), filter);
|
||||
BannerDescriptor banner = thetvdb.getBanner(buffy, filter);
|
||||
|
||||
assertEquals(857660, banner.getId(), 0);
|
||||
assertEquals("season", banner.getBannerType());
|
||||
|
@ -160,7 +163,7 @@ public class TheTVDBClientTest {
|
|||
|
||||
@Test
|
||||
public void getBannerList() throws Exception {
|
||||
List<BannerDescriptor> banners = thetvdb.getBannerList(new TheTVDBSearchResult("Buffy the Vampire Slayer", 70327));
|
||||
List<BannerDescriptor> banners = thetvdb.getBannerList(buffy);
|
||||
|
||||
assertEquals("fanart", banners.get(0).getBannerType());
|
||||
assertEquals("1280x720", banners.get(0).getBannerType2());
|
||||
|
|
Loading…
Reference in New Issue