Support -non-strict in -list --q mode to fetch episodes for multiple results at once

This commit is contained in:
Reinhard Pointner 2017-02-12 19:56:39 +08:00
parent 2608cd7860
commit b28e81ca1e
4 changed files with 22 additions and 13 deletions

View File

@ -55,7 +55,7 @@ public class ArgumentProcessor {
// print episode info
if (args.list) {
return print(cli.fetchEpisodeList(args.getDatasource(), args.getSearchQuery(), args.getExpressionFormat(), args.getExpressionFilter(), args.getSortOrder(), args.getLanguage().getLocale()));
return print(cli.fetchEpisodeList(args.getDatasource(), args.getSearchQuery(), args.getExpressionFormat(), args.getExpressionFilter(), args.getSortOrder(), args.getLanguage().getLocale(), args.isStrict()));
}
// print media info

View File

@ -34,7 +34,7 @@ public interface CmdlineInterface {
File compute(Collection<File> files, File output, HashType hash, Charset encoding) throws Exception;
List<String> fetchEpisodeList(Datasource db, String query, ExpressionFormat format, ExpressionFilter filter, SortOrder order, Locale locale) throws Exception;
List<String> fetchEpisodeList(Datasource db, String query, ExpressionFormat format, ExpressionFilter filter, SortOrder order, Locale locale, boolean strict) throws Exception;
List<String> getMediaInfo(Collection<File> files, FileFilter filter, ExpressionFormat format) throws Exception;

View File

@ -831,10 +831,10 @@ public class CmdlineOperations implements CmdlineInterface {
private <T> List<T> applyExpressionFilter(List<T> input, ExpressionFilter filter) throws Exception {
if (filter == null) {
return new ArrayList<T>(input);
return input;
}
log.fine(format("Apply Filter: {%s}", filter.getExpression()));
log.fine(format("Apply filter [%s] on [%d] items", filter.getExpression(), input.size()));
Map<File, T> context = new EntryList<File, T>(null, input);
List<T> output = new ArrayList<T>(input.size());
for (T it : input) {
@ -986,7 +986,7 @@ public class CmdlineOperations implements CmdlineInterface {
}
@Override
public List<String> fetchEpisodeList(Datasource db, String query, ExpressionFormat format, ExpressionFilter filter, SortOrder order, Locale locale) throws Exception {
public List<String> fetchEpisodeList(Datasource db, String query, ExpressionFormat format, ExpressionFilter filter, SortOrder order, Locale locale, boolean strict) throws Exception {
if (query == null) {
throw new IllegalArgumentException("query is not defined");
}
@ -995,13 +995,22 @@ public class CmdlineOperations implements CmdlineInterface {
EpisodeListProvider service = db instanceof EpisodeListProvider ? (EpisodeListProvider) db : TheTVDB;
// search and select search result
SearchResult option = selectSearchResult(query, service.search(query, locale));
if (option == null) {
throw new CmdlineException(service.getName() + ": no results");
List<SearchResult> results = service.search(query, locale);
if (results.isEmpty()) {
throw new CmdlineException(String.format("%s: no results", service.getName()));
}
// fetch episodes and apply filter
List<Episode> episodes = applyExpressionFilter(service.getEpisodeList(option, order, locale), filter);
List<SearchResult> options = selectSearchResult(query, results, false, false, false, strict ? 1 : 5);
List<Episode> episodes = new ArrayList<Episode>();
// fetch episodes
for (SearchResult option : options) {
episodes.addAll(service.getEpisodeList(option, order, locale));
}
// apply filter
episodes = applyExpressionFilter(episodes, filter);
Map<File, Episode> context = new EntryList<File, Episode>(null, episodes);
// lazy format

View File

@ -171,7 +171,7 @@ public abstract class ScriptShellBaseClass extends Script {
// define global variable: _def
public Map<String, String> get_def() {
return getArgumentBean().defines;
return unmodifiableMap(getArgumentBean().defines);
}
// define global variable: _system
@ -421,10 +421,10 @@ public abstract class ScriptShellBaseClass extends Script {
}
public List<String> fetchEpisodeList(Map<String, ?> parameters) throws Exception {
ArgumentBean args = getArgumentBean();
ArgumentBean args = getArgumentBean(parameters);
try {
return getCLI().fetchEpisodeList(args.getDatasource(), args.getSearchQuery(), args.getExpressionFormat(), args.getExpressionFilter(), args.getSortOrder(), args.getLanguage().getLocale());
return getCLI().fetchEpisodeList(args.getDatasource(), args.getSearchQuery(), args.getExpressionFormat(), args.getExpressionFilter(), args.getSortOrder(), args.getLanguage().getLocale(), args.isStrict());
} catch (Exception e) {
printException(e);
}