mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-11 11:55:03 -05:00
* make it easier to reference the original database in the format expression
This commit is contained in:
parent
54854d3098
commit
7d814d7b77
@ -21,11 +21,13 @@ import java.util.logging.Logger;
|
||||
import net.sourceforge.filebot.web.AcoustID;
|
||||
import net.sourceforge.filebot.web.AnidbClient;
|
||||
import net.sourceforge.filebot.web.AnidbSearchResult;
|
||||
import net.sourceforge.filebot.web.AudioTrack;
|
||||
import net.sourceforge.filebot.web.EpisodeListProvider;
|
||||
import net.sourceforge.filebot.web.FanartTV;
|
||||
import net.sourceforge.filebot.web.ID3Lookup;
|
||||
import net.sourceforge.filebot.web.IMDbClient;
|
||||
import net.sourceforge.filebot.web.LocalSearch;
|
||||
import net.sourceforge.filebot.web.Movie;
|
||||
import net.sourceforge.filebot.web.MovieIdentificationService;
|
||||
import net.sourceforge.filebot.web.MusicIdentificationService;
|
||||
import net.sourceforge.filebot.web.OpenSubtitlesClient;
|
||||
@ -34,6 +36,7 @@ import net.sourceforge.filebot.web.SerienjunkiesClient;
|
||||
import net.sourceforge.filebot.web.SubtitleProvider;
|
||||
import net.sourceforge.filebot.web.TMDbClient;
|
||||
import net.sourceforge.filebot.web.TVRageClient;
|
||||
import net.sourceforge.filebot.web.TVRageSearchResult;
|
||||
import net.sourceforge.filebot.web.TheTVDBClient;
|
||||
import net.sourceforge.filebot.web.TheTVDBSearchResult;
|
||||
import net.sourceforge.filebot.web.VideoHashSubtitleService;
|
||||
@ -109,6 +112,21 @@ public final class WebServices {
|
||||
return null; // default
|
||||
}
|
||||
|
||||
public static Object getServiceBySearchResult(Object r) {
|
||||
if (r instanceof TheTVDBSearchResult)
|
||||
return WebServices.TheTVDB;
|
||||
if (r instanceof AnidbSearchResult)
|
||||
return WebServices.AniDB;
|
||||
if (r instanceof TVRageSearchResult)
|
||||
return WebServices.TVRage;
|
||||
if (r instanceof Movie)
|
||||
return WebServices.TMDb;
|
||||
if (r instanceof AudioTrack)
|
||||
return WebServices.AcoustID;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class TheTVDBClientWithLocalSearch extends TheTVDBClient {
|
||||
|
||||
public TheTVDBClientWithLocalSearch(String apikey) {
|
||||
|
@ -41,10 +41,12 @@ import net.sourceforge.filebot.web.AnidbSearchResult;
|
||||
import net.sourceforge.filebot.web.AudioTrack;
|
||||
import net.sourceforge.filebot.web.Date;
|
||||
import net.sourceforge.filebot.web.Episode;
|
||||
import net.sourceforge.filebot.web.EpisodeListProvider;
|
||||
import net.sourceforge.filebot.web.Movie;
|
||||
import net.sourceforge.filebot.web.MoviePart;
|
||||
import net.sourceforge.filebot.web.MultiEpisode;
|
||||
import net.sourceforge.filebot.web.SearchResult;
|
||||
import net.sourceforge.filebot.web.SortOrder;
|
||||
import net.sourceforge.filebot.web.TheTVDBSearchResult;
|
||||
import net.sourceforge.tuned.FileUtilities;
|
||||
import net.sourceforge.tuned.FileUtilities.ExtensionFileFilter;
|
||||
@ -521,13 +523,21 @@ public class MediaBindingBean {
|
||||
|
||||
@Define("episodelist")
|
||||
public Object getEpisodeList() throws Exception {
|
||||
if (getSeriesObject() instanceof TheTVDBSearchResult) {
|
||||
return WebServices.TheTVDB.getEpisodeList(getSeriesObject());
|
||||
return ((EpisodeListProvider) getDatabase()).getEpisodeList(getSeriesObject(), SortOrder.Airdate, Locale.ENGLISH);
|
||||
}
|
||||
if (getSeriesObject() instanceof AnidbSearchResult) {
|
||||
return WebServices.AniDB.getEpisodeList(getSeriesObject());
|
||||
|
||||
@Define("database")
|
||||
public Object getDatabase() {
|
||||
if (infoObject instanceof Episode) {
|
||||
return WebServices.getServiceBySearchResult(getSeriesObject());
|
||||
}
|
||||
return null; // default to original search result
|
||||
if (infoObject instanceof Movie) {
|
||||
return WebServices.getServiceBySearchResult(getMovie());
|
||||
}
|
||||
if (infoObject instanceof AudioTrack) {
|
||||
return WebServices.getServiceBySearchResult(getMusic());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Define("duration")
|
||||
|
@ -1,7 +1,5 @@
|
||||
|
||||
package net.sourceforge.filebot.web;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@ -11,7 +9,6 @@ import java.util.logging.Logger;
|
||||
import net.sourceforge.filebot.Cache;
|
||||
import net.sourceforge.filebot.Cache.Key;
|
||||
|
||||
|
||||
public abstract class AbstractEpisodeListProvider implements EpisodeListProvider {
|
||||
|
||||
@Override
|
||||
@ -19,24 +16,19 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasLocaleSupport() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected abstract List<SearchResult> fetchSearchResult(String query, Locale locale) throws Exception;
|
||||
|
||||
|
||||
protected abstract List<Episode> fetchEpisodeList(SearchResult searchResult, SortOrder sortOrder, Locale locale) throws Exception;
|
||||
|
||||
|
||||
public List<SearchResult> search(String query) throws Exception {
|
||||
return search(query, getDefaultLocale());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<SearchResult> search(String query, Locale locale) throws Exception {
|
||||
ResultCache cache = getCache();
|
||||
@ -52,12 +44,14 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
||||
return (cache != null) ? cache.putSearchResult(query, locale, results) : results;
|
||||
}
|
||||
|
||||
public List<Episode> getEpisodeList(SearchResult searchResult, String sortOrder, String locale) throws Exception {
|
||||
return getEpisodeList(searchResult, sortOrder == null ? SortOrder.Airdate : SortOrder.forName(sortOrder), new Locale(locale));
|
||||
}
|
||||
|
||||
public List<Episode> getEpisodeList(SearchResult searchResult) throws Exception {
|
||||
return getEpisodeList(searchResult, SortOrder.Airdate, getDefaultLocale());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Episode> getEpisodeList(SearchResult searchResult, SortOrder sortOrder, Locale locale) throws Exception {
|
||||
ResultCache cache = getCache();
|
||||
@ -73,34 +67,28 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
||||
return (cache != null) ? cache.putEpisodeList(searchResult, sortOrder, locale, episodes) : episodes;
|
||||
}
|
||||
|
||||
|
||||
public Locale getDefaultLocale() {
|
||||
return Locale.ENGLISH;
|
||||
}
|
||||
|
||||
|
||||
public ResultCache getCache() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected static class ResultCache {
|
||||
|
||||
private final String id;
|
||||
private final Cache cache;
|
||||
|
||||
|
||||
public ResultCache(String id, Cache cache) {
|
||||
this.id = id;
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
|
||||
protected String normalize(String query) {
|
||||
return query == null ? null : query.trim().toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
public <T extends SearchResult> List<T> putSearchResult(String query, Locale locale, List<T> value) {
|
||||
try {
|
||||
cache.put(new Key(id, normalize(query), locale), value.toArray(new SearchResult[0]));
|
||||
@ -111,7 +99,6 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
public List<SearchResult> getSearchResult(String query, Locale locale) {
|
||||
try {
|
||||
SearchResult[] results = cache.get(new Key(id, normalize(query), locale), SearchResult[].class);
|
||||
@ -125,7 +112,6 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public List<Episode> putEpisodeList(SearchResult key, SortOrder sortOrder, Locale locale, List<Episode> episodes) {
|
||||
try {
|
||||
cache.put(new Key(id, key, sortOrder, locale), episodes.toArray(new Episode[0]));
|
||||
@ -136,7 +122,6 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
||||
return episodes;
|
||||
}
|
||||
|
||||
|
||||
public List<Episode> getEpisodeList(SearchResult key, SortOrder sortOrder, Locale locale) {
|
||||
try {
|
||||
Episode[] episodes = cache.get(new Key(id, key, sortOrder, locale), Episode[].class);
|
||||
@ -150,7 +135,6 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void putData(Object category, Object key, Locale locale, Object object) {
|
||||
try {
|
||||
cache.put(new Key(id, category, locale, key), object);
|
||||
@ -159,7 +143,6 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public <T> T getData(Object category, Object key, Locale locale, Class<T> type) {
|
||||
try {
|
||||
T value = cache.get(new Key(id, category, locale, key), type);
|
||||
|
Loading…
Reference in New Issue
Block a user