Support -non-strict in -list --q mode to fetch episodes for multiple results at once
This commit is contained in:
parent
2608cd7860
commit
b28e81ca1e
|
@ -55,7 +55,7 @@ public class ArgumentProcessor {
|
||||||
|
|
||||||
// print episode info
|
// print episode info
|
||||||
if (args.list) {
|
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
|
// print media info
|
||||||
|
|
|
@ -34,7 +34,7 @@ public interface CmdlineInterface {
|
||||||
|
|
||||||
File compute(Collection<File> files, File output, HashType hash, Charset encoding) throws Exception;
|
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;
|
List<String> getMediaInfo(Collection<File> files, FileFilter filter, ExpressionFormat format) throws Exception;
|
||||||
|
|
||||||
|
|
|
@ -831,10 +831,10 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
|
|
||||||
private <T> List<T> applyExpressionFilter(List<T> input, ExpressionFilter filter) throws Exception {
|
private <T> List<T> applyExpressionFilter(List<T> input, ExpressionFilter filter) throws Exception {
|
||||||
if (filter == null) {
|
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);
|
Map<File, T> context = new EntryList<File, T>(null, input);
|
||||||
List<T> output = new ArrayList<T>(input.size());
|
List<T> output = new ArrayList<T>(input.size());
|
||||||
for (T it : input) {
|
for (T it : input) {
|
||||||
|
@ -986,7 +986,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
if (query == null) {
|
||||||
throw new IllegalArgumentException("query is not defined");
|
throw new IllegalArgumentException("query is not defined");
|
||||||
}
|
}
|
||||||
|
@ -995,13 +995,22 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
EpisodeListProvider service = db instanceof EpisodeListProvider ? (EpisodeListProvider) db : TheTVDB;
|
EpisodeListProvider service = db instanceof EpisodeListProvider ? (EpisodeListProvider) db : TheTVDB;
|
||||||
|
|
||||||
// search and select search result
|
// search and select search result
|
||||||
SearchResult option = selectSearchResult(query, service.search(query, locale));
|
List<SearchResult> results = service.search(query, locale);
|
||||||
if (option == null) {
|
if (results.isEmpty()) {
|
||||||
throw new CmdlineException(service.getName() + ": no results");
|
throw new CmdlineException(String.format("%s: no results", service.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch episodes and apply filter
|
List<SearchResult> options = selectSearchResult(query, results, false, false, false, strict ? 1 : 5);
|
||||||
List<Episode> episodes = applyExpressionFilter(service.getEpisodeList(option, order, locale), filter);
|
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);
|
Map<File, Episode> context = new EntryList<File, Episode>(null, episodes);
|
||||||
|
|
||||||
// lazy format
|
// lazy format
|
||||||
|
|
|
@ -171,7 +171,7 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||||
|
|
||||||
// define global variable: _def
|
// define global variable: _def
|
||||||
public Map<String, String> get_def() {
|
public Map<String, String> get_def() {
|
||||||
return getArgumentBean().defines;
|
return unmodifiableMap(getArgumentBean().defines);
|
||||||
}
|
}
|
||||||
|
|
||||||
// define global variable: _system
|
// define global variable: _system
|
||||||
|
@ -421,10 +421,10 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> fetchEpisodeList(Map<String, ?> parameters) throws Exception {
|
public List<String> fetchEpisodeList(Map<String, ?> parameters) throws Exception {
|
||||||
ArgumentBean args = getArgumentBean();
|
ArgumentBean args = getArgumentBean(parameters);
|
||||||
|
|
||||||
try {
|
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) {
|
} catch (Exception e) {
|
||||||
printException(e);
|
printException(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue