1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-25 09:18:51 -05:00

* make it easier to reference the original database in the format expression

This commit is contained in:
Reinhard Pointner 2014-01-04 20:18:47 +00:00
parent 54854d3098
commit 7d814d7b77
3 changed files with 68 additions and 57 deletions

View File

@ -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) {

View File

@ -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);
}
@Define("database")
public Object getDatabase() {
if (infoObject instanceof Episode) {
return WebServices.getServiceBySearchResult(getSeriesObject());
}
if (getSeriesObject() instanceof AnidbSearchResult) {
return WebServices.AniDB.getEpisodeList(getSeriesObject());
if (infoObject instanceof Movie) {
return WebServices.getServiceBySearchResult(getMovie());
}
return null; // default to original search result
if (infoObject instanceof AudioTrack) {
return WebServices.getServiceBySearchResult(getMusic());
}
return null;
}
@Define("duration")

View File

@ -1,7 +1,5 @@
package net.sourceforge.filebot.web;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
@ -11,32 +9,26 @@ import java.util.logging.Logger;
import net.sourceforge.filebot.Cache;
import net.sourceforge.filebot.Cache.Key;
public abstract class AbstractEpisodeListProvider implements EpisodeListProvider {
@Override
public boolean hasSingleSeasonSupport() {
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();
@ -44,20 +36,22 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
if (results != null) {
return results;
}
// perform actual search
results = fetchSearchResult(query, locale);
// cache results and return
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();
@ -65,53 +59,46 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
if (episodes != null) {
return episodes;
}
// perform actual search
episodes = fetchEpisodeList(searchResult, sortOrder, locale);
// cache results and return
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]));
} catch (Exception e) {
Logger.getLogger(AbstractEpisodeListProvider.class.getName()).log(Level.WARNING, e.getMessage());
}
return value;
}
public List<SearchResult> getSearchResult(String query, Locale locale) {
try {
SearchResult[] results = cache.get(new Key(id, normalize(query), locale), SearchResult[].class);
@ -121,22 +108,20 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
} catch (Exception e) {
Logger.getLogger(AbstractEpisodeListProvider.class.getName()).log(Level.WARNING, e.getMessage(), e);
}
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]));
} catch (Exception e) {
Logger.getLogger(AbstractEpisodeListProvider.class.getName()).log(Level.WARNING, e.getMessage());
}
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);
@ -146,11 +131,10 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
} catch (Exception e) {
Logger.getLogger(AbstractEpisodeListProvider.class.getName()).log(Level.WARNING, e.getMessage(), e);
}
return null;
}
public void putData(Object category, Object key, Locale locale, Object object) {
try {
cache.put(new Key(id, category, locale, key), object);
@ -158,8 +142,7 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
Logger.getLogger(AbstractEpisodeListProvider.class.getName()).log(Level.WARNING, e.getMessage());
}
}
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);
@ -169,10 +152,10 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
} catch (Exception e) {
Logger.getLogger(AbstractEpisodeListProvider.class.getName()).log(Level.WARNING, e.getMessage(), e);
}
return null;
}
}
}