Various bug fixes and cleanup

This commit is contained in:
Reinhard Pointner 2016-04-09 19:16:30 +00:00
parent 0ddab83eac
commit e8652a5593
8 changed files with 20 additions and 15 deletions

View File

@ -123,8 +123,8 @@ public class CmdlineOperations implements CmdlineInterface {
List<File> results = new ArrayList<File>(); List<File> results = new ArrayList<File>();
for (Entry<Group, Set<File>> it : auto.group().entrySet()) { for (Entry<Group, Set<File>> it : auto.group().entrySet()) {
if (it.getKey().values().stream().filter(Objects::nonNull).count() == 1) { if (it.getKey().types().length == 1) {
for (Type key : it.getKey().keySet()) { for (Type key : it.getKey().types()) {
switch (key) { switch (key) {
case Movie: case Movie:
results.addAll(renameMovie(it.getValue(), action, conflictAction, outputDir, format, TheMovieDB, query, filter, locale, strict)); results.addAll(renameMovie(it.getValue(), action, conflictAction, outputDir, format, TheMovieDB, query, filter, locale, strict));

View File

@ -6,6 +6,7 @@ import static java.util.regex.Pattern.*;
import static java.util.stream.Collectors.*; import static java.util.stream.Collectors.*;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.MediaTypes.*; import static net.filebot.MediaTypes.*;
import static net.filebot.Settings.*;
import static net.filebot.WebServices.*; import static net.filebot.WebServices.*;
import static net.filebot.format.ExpressionFormatMethods.*; import static net.filebot.format.ExpressionFormatMethods.*;
import static net.filebot.media.MediaDetection.*; import static net.filebot.media.MediaDetection.*;
@ -122,7 +123,7 @@ public class AutoDetection {
Map<Group, Set<File>> groups = new TreeMap<Group, Set<File>>(); Map<Group, Set<File>> groups = new TreeMap<Group, Set<File>>();
// can't use parallel stream because default fork/join pool doesn't play well with the security manager // can't use parallel stream because default fork/join pool doesn't play well with the security manager
ExecutorService workerThreadPool = Executors.newWorkStealingPool(); ExecutorService workerThreadPool = Executors.newFixedThreadPool(getPreferredThreadPoolSize());
try { try {
stream(files).collect(toMap(f -> f, f -> workerThreadPool.submit(() -> detectGroup(f)))).forEach((file, group) -> { stream(files).collect(toMap(f -> f, f -> workerThreadPool.submit(() -> detectGroup(f)))).forEach((file, group) -> {
try { try {
@ -405,6 +406,10 @@ public class AutoDetection {
return this; return this;
} }
public Type[] types() {
return entrySet().stream().filter(it -> it.getValue() != null).map(it -> it.getKey()).toArray(Type[]::new);
}
@Override @Override
public int compareTo(Group other) { public int compareTo(Group other) {
if (size() != other.size()) { if (size() != other.size()) {

View File

@ -69,10 +69,9 @@ public class SelectDialog<T> extends JDialog {
list.addMouseListener(mouseListener); list.addMouseListener(mouseListener);
JComponent c = (JComponent) getContentPane(); JComponent c = (JComponent) getContentPane();
c.setLayout(new MigLayout("insets 1.5mm 1.5mm 2.7mm 1.5mm, nogrid, fill", "", "[pref!][fill][pref!]")); c.setLayout(new MigLayout("insets 1.5mm 1.5mm 2.7mm 1.5mm, nogrid, fill", "", "[pref!][fill][pref!]"));
c.add(headerLabel, "wmin 150px, wrap"); c.add(headerLabel, "wmin 150px, growx, wrap");
c.add(new JScrollPane(list), "wmin 150px, hmin 150px, grow, wrap 2mm"); c.add(new JScrollPane(list), "wmin 150px, hmin 150px, grow, wrap 2mm");
c.add(new JButton(selectAction), "align center, id select"); c.add(new JButton(selectAction), "align center, id select");

View File

@ -4,6 +4,7 @@ package net.filebot.ui.rename;
import static java.util.Collections.*; import static java.util.Collections.*;
import static java.util.stream.Collectors.*; import static java.util.stream.Collectors.*;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.Settings.*;
import static net.filebot.WebServices.*; import static net.filebot.WebServices.*;
import java.awt.Component; import java.awt.Component;
@ -13,7 +14,6 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -39,7 +39,7 @@ class AutoDetectMatcher implements AutoCompleteMatcher {
Map<Group, Set<File>> groups = new AutoDetection(files, false, locale).group(); Map<Group, Set<File>> groups = new AutoDetection(files, false, locale).group();
// can't use parallel stream because default fork/join pool doesn't play well with the security manager // can't use parallel stream because default fork/join pool doesn't play well with the security manager
ExecutorService workerThreadPool = Executors.newWorkStealingPool(); ExecutorService workerThreadPool = Executors.newFixedThreadPool(getPreferredThreadPoolSize());
try { try {
Map<Group, Future<List<Match<File, ?>>>> matches = groups.entrySet().stream().collect(toMap(Entry::getKey, it -> { Map<Group, Future<List<Match<File, ?>>>> matches = groups.entrySet().stream().collect(toMap(Entry::getKey, it -> {
return workerThreadPool.submit(() -> match(it.getKey(), it.getValue(), strict, order, locale, autodetection, parent)); return workerThreadPool.submit(() -> match(it.getKey(), it.getValue(), strict, order, locale, autodetection, parent));
@ -50,7 +50,7 @@ class AutoDetectMatcher implements AutoCompleteMatcher {
try { try {
return it.getValue().get().stream(); return it.getValue().get().stream();
} catch (Exception e) { } catch (Exception e) {
log.log(Level.WARNING, "Failed to process group: %s" + it.getKey(), e); log.log(Level.WARNING, "Failed to process group: " + it.getKey(), e);
} }
return Stream.empty(); return Stream.empty();
}).collect(toList()); }).collect(toList());
@ -60,8 +60,8 @@ class AutoDetectMatcher implements AutoCompleteMatcher {
} }
private List<Match<File, ?>> match(Group group, Collection<File> files, boolean strict, SortOrder order, Locale locale, boolean autodetection, Component parent) throws Exception { private List<Match<File, ?>> match(Group group, Collection<File> files, boolean strict, SortOrder order, Locale locale, boolean autodetection, Component parent) throws Exception {
if (group.values().stream().filter(Objects::nonNull).count() == 1) { if (group.types().length == 1) {
for (Type key : group.keySet()) { for (Type key : group.types()) {
switch (key) { switch (key) {
case Movie: case Movie:
return movie.match(files, strict, order, locale, autodetection, parent); return movie.match(files, strict, order, locale, autodetection, parent);

View File

@ -4,6 +4,7 @@ import static java.util.Collections.*;
import static java.util.Comparator.*; import static java.util.Comparator.*;
import static java.util.stream.Collectors.*; import static java.util.stream.Collectors.*;
import static net.filebot.MediaTypes.*; import static net.filebot.MediaTypes.*;
import static net.filebot.Settings.*;
import static net.filebot.WebServices.*; import static net.filebot.WebServices.*;
import static net.filebot.media.MediaDetection.*; import static net.filebot.media.MediaDetection.*;
import static net.filebot.similarity.CommonSequenceMatcher.*; import static net.filebot.similarity.CommonSequenceMatcher.*;
@ -175,7 +176,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
// merge episode matches // merge episode matches
List<Match<File, ?>> matches = new ArrayList<Match<File, ?>>(); List<Match<File, ?>> matches = new ArrayList<Match<File, ?>>();
ExecutorService workerThreadPool = Executors.newWorkStealingPool(); ExecutorService workerThreadPool = Executors.newFixedThreadPool(getPreferredThreadPoolSize());
try { try {
// detect series names and create episode list fetch tasks // detect series names and create episode list fetch tasks
List<Future<List<Match<File, ?>>>> tasks = new ArrayList<Future<List<Match<File, ?>>>>(); List<Future<List<Match<File, ?>>>> tasks = new ArrayList<Future<List<Match<File, ?>>>>();

View File

@ -5,6 +5,7 @@ import static java.util.Comparator.*;
import static java.util.stream.Collectors.*; import static java.util.stream.Collectors.*;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.MediaTypes.*; import static net.filebot.MediaTypes.*;
import static net.filebot.Settings.*;
import static net.filebot.media.MediaDetection.*; import static net.filebot.media.MediaDetection.*;
import static net.filebot.similarity.CommonSequenceMatcher.*; import static net.filebot.similarity.CommonSequenceMatcher.*;
import static net.filebot.similarity.Normalization.*; import static net.filebot.similarity.Normalization.*;
@ -147,7 +148,7 @@ class MovieMatcher implements AutoCompleteMatcher {
movieMatchFiles.addAll(filter(orphanedFiles, SUBTITLE_FILES)); // run movie detection only on orphaned subtitle files movieMatchFiles.addAll(filter(orphanedFiles, SUBTITLE_FILES)); // run movie detection only on orphaned subtitle files
// match remaining movies file by file in parallel // match remaining movies file by file in parallel
ExecutorService workerThreadPool = Executors.newWorkStealingPool(); ExecutorService workerThreadPool = Executors.newFixedThreadPool(getPreferredThreadPoolSize());
try { try {
List<Future<Map<File, List<Movie>>>> tasks = movieMatchFiles.stream().filter(f -> movieByFile.get(f) == null).map(f -> { List<Future<Map<File, List<Movie>>>> tasks = movieMatchFiles.stream().filter(f -> movieByFile.get(f) == null).map(f -> {
return workerThreadPool.submit(() -> { return workerThreadPool.submit(() -> {
@ -344,7 +345,7 @@ class MovieMatcher implements AutoCompleteMatcher {
// multiple results have been found, user must select one // multiple results have been found, user must select one
SelectDialog<Movie> selectDialog = new SelectDialog<Movie>(parent, options, true, false); SelectDialog<Movie> selectDialog = new SelectDialog<Movie>(parent, options, true, false);
selectDialog.setTitle(folderQuery.isEmpty() ? fileQuery : String.join(" / ", folderQuery, fileQuery)); selectDialog.setTitle(service.getName());
selectDialog.getHeaderLabel().setText(getQueryInputMessage(String.format("Select best match for \"<b>%s</b>\":", fileQuery.length() >= 2 || folderQuery.length() <= 2 ? fileQuery : folderQuery), movieFile)); selectDialog.getHeaderLabel().setText(getQueryInputMessage(String.format("Select best match for \"<b>%s</b>\":", fileQuery.length() >= 2 || folderQuery.length() <= 2 ? fileQuery : folderQuery), movieFile));
selectDialog.getCancelAction().putValue(Action.NAME, AutoSelection.Skip.toString()); selectDialog.getCancelAction().putValue(Action.NAME, AutoSelection.Skip.toString());
selectDialog.pack(); selectDialog.pack();

View File

@ -631,7 +631,6 @@ public class RenamePanel extends JComponent {
@Subscribe @Subscribe
public void handle(Transferable transferable) throws Exception { public void handle(Transferable transferable) throws Exception {
for (TransferablePolicy handler : new TransferablePolicy[] { filesList.getTransferablePolicy(), namesList.getTransferablePolicy() }) { for (TransferablePolicy handler : new TransferablePolicy[] { filesList.getTransferablePolicy(), namesList.getTransferablePolicy() }) {
System.out.println(handler.accept(transferable));
if (handler != null && handler.accept(transferable)) { if (handler != null && handler.accept(transferable)) {
handler.handleTransferable(transferable, TransferAction.PUT); handler.handleTransferable(transferable, TransferAction.PUT);
return; return;

View File

@ -223,7 +223,7 @@ class SubtitleAutoMatchDialog extends JDialog {
} }
}; };
queryService = Executors.newFixedThreadPool(1); queryService = Executors.newSingleThreadExecutor();
queryService.submit(queryTask); queryService.submit(queryTask);
} }