From 5dd26ba3475402e545e985212660000fb1c8a7a4 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Fri, 11 Nov 2016 03:27:38 +0800 Subject: [PATCH] Make sure that {model} works even for simple -list calls (useful for testing --filter expressions) --- source/net/filebot/cli/CmdlineOperations.java | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/source/net/filebot/cli/CmdlineOperations.java b/source/net/filebot/cli/CmdlineOperations.java index 56dba619..35313742 100644 --- a/source/net/filebot/cli/CmdlineOperations.java +++ b/source/net/filebot/cli/CmdlineOperations.java @@ -1027,32 +1027,30 @@ public class CmdlineOperations implements CmdlineInterface { @Override public List fetchEpisodeList(String query, String expression, String db, String sortOrderName, String filterExpression, String languageName) throws Exception { - if (query == null || query.isEmpty()) + if (query == null || query.isEmpty()) { throw new IllegalArgumentException("query is not defined"); + } // find series on the web and fetch episode list - ExpressionFormat format = (expression != null) ? new ExpressionFormat(expression) : null; - ExpressionFilter filter = (filterExpression != null) ? new ExpressionFilter(filterExpression) : null; - EpisodeListProvider service = (db == null) ? TheTVDB : getEpisodeListProvider(db); + ExpressionFormat format = expression == null ? null : new ExpressionFormat(expression); + ExpressionFilter filter = filterExpression == null ? null : new ExpressionFilter(filterExpression); + EpisodeListProvider service = db == null ? TheTVDB : getEpisodeListProvider(db); SortOrder sortOrder = SortOrder.forName(sortOrderName); Locale locale = getLanguage(languageName).getLocale(); - // fetch episode data + // search and select search result List options = selectSearchResult(query, service.search(query, locale), false, false); - if (options.isEmpty()) + if (options.isEmpty()) { throw new CmdlineException(service.getName() + ": no results"); - - List episodes = service.getEpisodeList(options.get(0), sortOrder, locale); - - // apply filter - episodes = applyExpressionFilter(episodes, filter); - - List names = new ArrayList(); - for (Episode it : episodes) { - String name = (format != null) ? format.format(new MediaBindingBean(it, null, null)) : EpisodeFormat.SeasonEpisode.format(it); - names.add(name); } - return names; + + // fetch episodes and apply filter + List episodes = applyExpressionFilter(service.getEpisodeList(options.get(0), sortOrder, locale), filter); + Map context = new EntryList(null, episodes); + + return episodes.stream().map(episode -> { + return format != null ? format.format(new MediaBindingBean(episode, null, context)) : EpisodeFormat.SeasonEpisode.format(episode); + }).collect(toList()); } @Override