From e8652a55938c4d4e783eb8f39f97ac16a9b1487d Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 9 Apr 2016 19:16:30 +0000 Subject: [PATCH] Various bug fixes and cleanup --- source/net/filebot/cli/CmdlineOperations.java | 4 ++-- source/net/filebot/media/AutoDetection.java | 7 ++++++- source/net/filebot/ui/SelectDialog.java | 3 +-- source/net/filebot/ui/rename/AutoDetectMatcher.java | 10 +++++----- source/net/filebot/ui/rename/EpisodeListMatcher.java | 3 ++- source/net/filebot/ui/rename/MovieMatcher.java | 5 +++-- source/net/filebot/ui/rename/RenamePanel.java | 1 - .../filebot/ui/subtitle/SubtitleAutoMatchDialog.java | 2 +- 8 files changed, 20 insertions(+), 15 deletions(-) diff --git a/source/net/filebot/cli/CmdlineOperations.java b/source/net/filebot/cli/CmdlineOperations.java index e823fedd..ffd7688e 100644 --- a/source/net/filebot/cli/CmdlineOperations.java +++ b/source/net/filebot/cli/CmdlineOperations.java @@ -123,8 +123,8 @@ public class CmdlineOperations implements CmdlineInterface { List results = new ArrayList(); for (Entry> it : auto.group().entrySet()) { - if (it.getKey().values().stream().filter(Objects::nonNull).count() == 1) { - for (Type key : it.getKey().keySet()) { + if (it.getKey().types().length == 1) { + for (Type key : it.getKey().types()) { switch (key) { case Movie: results.addAll(renameMovie(it.getValue(), action, conflictAction, outputDir, format, TheMovieDB, query, filter, locale, strict)); diff --git a/source/net/filebot/media/AutoDetection.java b/source/net/filebot/media/AutoDetection.java index 7b1a6624..1f362f06 100644 --- a/source/net/filebot/media/AutoDetection.java +++ b/source/net/filebot/media/AutoDetection.java @@ -6,6 +6,7 @@ import static java.util.regex.Pattern.*; import static java.util.stream.Collectors.*; import static net.filebot.Logging.*; import static net.filebot.MediaTypes.*; +import static net.filebot.Settings.*; import static net.filebot.WebServices.*; import static net.filebot.format.ExpressionFormatMethods.*; import static net.filebot.media.MediaDetection.*; @@ -122,7 +123,7 @@ public class AutoDetection { Map> groups = new TreeMap>(); // 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 { stream(files).collect(toMap(f -> f, f -> workerThreadPool.submit(() -> detectGroup(f)))).forEach((file, group) -> { try { @@ -405,6 +406,10 @@ public class AutoDetection { return this; } + public Type[] types() { + return entrySet().stream().filter(it -> it.getValue() != null).map(it -> it.getKey()).toArray(Type[]::new); + } + @Override public int compareTo(Group other) { if (size() != other.size()) { diff --git a/source/net/filebot/ui/SelectDialog.java b/source/net/filebot/ui/SelectDialog.java index b7e13d6a..ee301c66 100644 --- a/source/net/filebot/ui/SelectDialog.java +++ b/source/net/filebot/ui/SelectDialog.java @@ -69,10 +69,9 @@ public class SelectDialog extends JDialog { list.addMouseListener(mouseListener); JComponent c = (JComponent) getContentPane(); - 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 JButton(selectAction), "align center, id select"); diff --git a/source/net/filebot/ui/rename/AutoDetectMatcher.java b/source/net/filebot/ui/rename/AutoDetectMatcher.java index 3a206a2e..44c5ee06 100644 --- a/source/net/filebot/ui/rename/AutoDetectMatcher.java +++ b/source/net/filebot/ui/rename/AutoDetectMatcher.java @@ -4,6 +4,7 @@ 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.Settings.*; import static net.filebot.WebServices.*; import java.awt.Component; @@ -13,7 +14,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; -import java.util.Objects; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -39,7 +39,7 @@ class AutoDetectMatcher implements AutoCompleteMatcher { Map> 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 - ExecutorService workerThreadPool = Executors.newWorkStealingPool(); + ExecutorService workerThreadPool = Executors.newFixedThreadPool(getPreferredThreadPoolSize()); try { Map>>> matches = groups.entrySet().stream().collect(toMap(Entry::getKey, it -> { return workerThreadPool.submit(() -> match(it.getKey(), it.getValue(), strict, order, locale, autodetection, parent)); @@ -50,7 +50,7 @@ class AutoDetectMatcher implements AutoCompleteMatcher { try { return it.getValue().get().stream(); } 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(); }).collect(toList()); @@ -60,8 +60,8 @@ class AutoDetectMatcher implements AutoCompleteMatcher { } private List> match(Group group, Collection files, boolean strict, SortOrder order, Locale locale, boolean autodetection, Component parent) throws Exception { - if (group.values().stream().filter(Objects::nonNull).count() == 1) { - for (Type key : group.keySet()) { + if (group.types().length == 1) { + for (Type key : group.types()) { switch (key) { case Movie: return movie.match(files, strict, order, locale, autodetection, parent); diff --git a/source/net/filebot/ui/rename/EpisodeListMatcher.java b/source/net/filebot/ui/rename/EpisodeListMatcher.java index c492028a..d31598ce 100644 --- a/source/net/filebot/ui/rename/EpisodeListMatcher.java +++ b/source/net/filebot/ui/rename/EpisodeListMatcher.java @@ -4,6 +4,7 @@ import static java.util.Collections.*; import static java.util.Comparator.*; import static java.util.stream.Collectors.*; import static net.filebot.MediaTypes.*; +import static net.filebot.Settings.*; import static net.filebot.WebServices.*; import static net.filebot.media.MediaDetection.*; import static net.filebot.similarity.CommonSequenceMatcher.*; @@ -175,7 +176,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher { // merge episode matches List> matches = new ArrayList>(); - ExecutorService workerThreadPool = Executors.newWorkStealingPool(); + ExecutorService workerThreadPool = Executors.newFixedThreadPool(getPreferredThreadPoolSize()); try { // detect series names and create episode list fetch tasks List>>> tasks = new ArrayList>>>(); diff --git a/source/net/filebot/ui/rename/MovieMatcher.java b/source/net/filebot/ui/rename/MovieMatcher.java index fd743f51..b4922866 100644 --- a/source/net/filebot/ui/rename/MovieMatcher.java +++ b/source/net/filebot/ui/rename/MovieMatcher.java @@ -5,6 +5,7 @@ import static java.util.Comparator.*; import static java.util.stream.Collectors.*; import static net.filebot.Logging.*; import static net.filebot.MediaTypes.*; +import static net.filebot.Settings.*; import static net.filebot.media.MediaDetection.*; import static net.filebot.similarity.CommonSequenceMatcher.*; 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 // match remaining movies file by file in parallel - ExecutorService workerThreadPool = Executors.newWorkStealingPool(); + ExecutorService workerThreadPool = Executors.newFixedThreadPool(getPreferredThreadPoolSize()); try { List>>> tasks = movieMatchFiles.stream().filter(f -> movieByFile.get(f) == null).map(f -> { return workerThreadPool.submit(() -> { @@ -344,7 +345,7 @@ class MovieMatcher implements AutoCompleteMatcher { // multiple results have been found, user must select one SelectDialog selectDialog = new SelectDialog(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 \"%s\":", fileQuery.length() >= 2 || folderQuery.length() <= 2 ? fileQuery : folderQuery), movieFile)); selectDialog.getCancelAction().putValue(Action.NAME, AutoSelection.Skip.toString()); selectDialog.pack(); diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index 43faed41..0096428c 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -631,7 +631,6 @@ public class RenamePanel extends JComponent { @Subscribe public void handle(Transferable transferable) throws Exception { for (TransferablePolicy handler : new TransferablePolicy[] { filesList.getTransferablePolicy(), namesList.getTransferablePolicy() }) { - System.out.println(handler.accept(transferable)); if (handler != null && handler.accept(transferable)) { handler.handleTransferable(transferable, TransferAction.PUT); return; diff --git a/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java b/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java index 9b9c3494..0650ac8c 100644 --- a/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java +++ b/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java @@ -223,7 +223,7 @@ class SubtitleAutoMatchDialog extends JDialog { } }; - queryService = Executors.newFixedThreadPool(1); + queryService = Executors.newSingleThreadExecutor(); queryService.submit(queryTask); }