Refactor AutoCompleteMatcher
This commit is contained in:
parent
451424153f
commit
e48ecf4fa2
|
@ -2,6 +2,7 @@ package net.filebot.ui.rename;
|
|||
|
||||
import java.awt.Component;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -10,5 +11,5 @@ import net.filebot.web.SortOrder;
|
|||
|
||||
interface AutoCompleteMatcher {
|
||||
|
||||
List<Match<File, ?>> match(List<File> files, boolean strict, SortOrder order, Locale locale, boolean autodetection, Component parent) throws Exception;
|
||||
List<Match<File, ?>> match(Collection<File> files, boolean strict, SortOrder order, Locale locale, boolean autodetection, Component parent) throws Exception;
|
||||
}
|
||||
|
|
|
@ -184,28 +184,28 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Match<File, ?>> match(List<File> files, final boolean strict, final SortOrder sortOrder, final Locale locale, final boolean autodetection, final Component parent) throws Exception {
|
||||
public List<Match<File, ?>> match(Collection<File> files, boolean strict, SortOrder sortOrder, Locale locale, boolean autodetection, Component parent) throws Exception {
|
||||
if (files.isEmpty()) {
|
||||
return justFetchEpisodeList(sortOrder, locale, parent);
|
||||
}
|
||||
|
||||
// ignore sample files
|
||||
final List<File> fileset = autodetection ? filter(files, not(getClutterFileFilter())) : files;
|
||||
List<File> fileset = autodetection ? filter(files, not(getClutterFileFilter())) : new ArrayList<File>(files);
|
||||
|
||||
// focus on movie and subtitle files
|
||||
final List<File> mediaFiles = filter(fileset, VIDEO_FILES, SUBTITLE_FILES);
|
||||
List<File> mediaFiles = filter(fileset, VIDEO_FILES, SUBTITLE_FILES);
|
||||
|
||||
// assume that many shows will be matched, do it folder by folder
|
||||
List<Callable<List<Match<File, ?>>>> tasks = new ArrayList<Callable<List<Match<File, ?>>>>();
|
||||
|
||||
// remember user decisions and only bother user once
|
||||
final Map<String, SearchResult> selectionMemory = new TreeMap<String, SearchResult>(CommonSequenceMatcher.getLenientCollator(Locale.ENGLISH));
|
||||
final Map<String, List<String>> inputMemory = new TreeMap<String, List<String>>(CommonSequenceMatcher.getLenientCollator(Locale.ENGLISH));
|
||||
Map<String, SearchResult> selectionMemory = new TreeMap<String, SearchResult>(CommonSequenceMatcher.getLenientCollator(Locale.ENGLISH));
|
||||
Map<String, List<String>> inputMemory = new TreeMap<String, List<String>>(CommonSequenceMatcher.getLenientCollator(Locale.ENGLISH));
|
||||
|
||||
// detect series names and create episode list fetch tasks
|
||||
if (strict) {
|
||||
// in strict mode simply process file-by-file (ignoring all files that don't contain clear SxE patterns)
|
||||
for (final File file : mediaFiles) {
|
||||
for (File file : mediaFiles) {
|
||||
if (parseEpisodeNumber(file, false) != null || parseDate(file) != null) {
|
||||
tasks.add(new Callable<List<Match<File, ?>>>() {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.filebot.ui.rename;
|
||||
|
||||
import static java.util.Collections.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static net.filebot.Logging.*;
|
||||
import static net.filebot.MediaTypes.*;
|
||||
import static net.filebot.Settings.*;
|
||||
|
@ -15,7 +15,6 @@ import java.awt.Dimension;
|
|||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
|
@ -35,6 +34,7 @@ import java.util.concurrent.Executors;
|
|||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.RunnableFuture;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.swing.Action;
|
||||
|
@ -60,13 +60,13 @@ class MovieHashMatcher implements AutoCompleteMatcher {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Match<File, ?>> match(final List<File> files, final boolean strict, final SortOrder sortOrder, final Locale locale, final boolean autodetect, final Component parent) throws Exception {
|
||||
public List<Match<File, ?>> match(Collection<File> files, boolean strict, SortOrder sortOrder, Locale locale, boolean autodetect, Component parent) throws Exception {
|
||||
if (files.isEmpty()) {
|
||||
return justFetchMovieInfo(locale, parent);
|
||||
}
|
||||
|
||||
// ignore sample files
|
||||
List<File> fileset = autodetect ? filter(files, not(getClutterFileFilter())) : files;
|
||||
List<File> fileset = autodetect ? filter(files, not(getClutterFileFilter())) : new ArrayList<File>(files);
|
||||
|
||||
// handle movie files
|
||||
Set<File> movieFiles = new TreeSet<File>(filter(fileset, VIDEO_FILES));
|
||||
|
@ -255,14 +255,9 @@ class MovieHashMatcher implements AutoCompleteMatcher {
|
|||
}
|
||||
|
||||
// restore original order
|
||||
sort(matches, new Comparator<Match<File, ?>>() {
|
||||
|
||||
@Override
|
||||
public int compare(Match<File, ?> o1, Match<File, ?> o2) {
|
||||
return files.indexOf(o1.getValue()) - files.indexOf(o2.getValue());
|
||||
}
|
||||
});
|
||||
|
||||
AtomicInteger index = new AtomicInteger(0);
|
||||
Map<File, Integer> indexMap = files.stream().collect(toMap(f -> f, f -> index.getAndIncrement()));
|
||||
matches.sort((a, b) -> indexMap.get(a.getValue()).compareTo(indexMap.get(b.getValue())));
|
||||
return matches;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package net.filebot.ui.rename;
|
||||
|
||||
import static java.util.stream.Collectors.*;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -30,12 +32,10 @@ public class PlainFileMatcher implements Datasource, AutoCompleteMatcher {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Match<File, ?>> match(List<File> files, boolean strict, SortOrder order, Locale locale, boolean autodetection, Component parent) throws Exception {
|
||||
List<Match<File, ?>> matches = new ArrayList<>();
|
||||
for (File f : files) {
|
||||
matches.add(new Match<File, File>(f, f));
|
||||
}
|
||||
return matches;
|
||||
public List<Match<File, ?>> match(Collection<File> files, boolean strict, SortOrder order, Locale locale, boolean autodetection, Component parent) throws Exception {
|
||||
return files.stream().map(f -> {
|
||||
return new Match<File, File>(f, f);
|
||||
}).collect(toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ public class AcoustIDClient implements MusicIdentificationService {
|
|||
List<String> command = new ArrayList<String>();
|
||||
command.add(getChromaprintCommand());
|
||||
for (File f : files) {
|
||||
command.add(f.toString());
|
||||
command.add(f.getPath());
|
||||
}
|
||||
|
||||
Process process = null;
|
||||
|
|
Loading…
Reference in New Issue