* refactoring
This commit is contained in:
parent
3162b3e7bc
commit
7601be3b46
|
@ -2,13 +2,10 @@
|
|||
package net.sourceforge.filebot;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.sourceforge.tuned.FileUtilities;
|
||||
|
||||
|
||||
public final class FileBotUtilities {
|
||||
|
||||
|
@ -66,17 +63,6 @@ public final class FileBotUtilities {
|
|||
public static final FileFilter SUBTITLE_FILES = MediaTypes.getDefault().filter("subtitle");
|
||||
public static final FileFilter SFV_FILES = MediaTypes.getDefault().filter("verification/sfv");
|
||||
|
||||
/**
|
||||
* This filter will accept all video files larger than 20 MB.
|
||||
*/
|
||||
public static final FileFilter MOVIE_FILES = new FileFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
return VIDEO_FILES.accept(file) && file.length() > 20 * FileUtilities.MEGA;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Dummy constructor to prevent instantiation.
|
||||
|
|
|
@ -18,6 +18,7 @@ import javax.swing.JFrame;
|
|||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import net.sourceforge.filebot.format.ExpressionFormat;
|
||||
import net.sourceforge.filebot.ui.MainFrame;
|
||||
import net.sourceforge.filebot.ui.NotificationLoggingHandler;
|
||||
|
@ -51,6 +52,7 @@ public class Main {
|
|||
|
||||
initializeLogging();
|
||||
initializeSettings();
|
||||
initializeCache();
|
||||
initializeSecurityManager();
|
||||
|
||||
try {
|
||||
|
@ -109,6 +111,21 @@ public class Main {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shutdown {@link CacheManager} in case there are any persistent caches that need to be stored.
|
||||
*/
|
||||
private static void initializeCache() {
|
||||
// shutdown CacheManager
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
CacheManager.getInstance().shutdown();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize default SecurityManager and grant all permissions via security policy.
|
||||
* Initialization is required in order to run {@link ExpressionFormat} in a secure sandbox.
|
||||
|
|
|
@ -200,7 +200,7 @@ public class EpisodeFormatBindingBean {
|
|||
String name = FileUtilities.getName(mediaFile);
|
||||
|
||||
// find corresponding movie file
|
||||
for (File movie : mediaFile.getParentFile().listFiles(MOVIE_FILES)) {
|
||||
for (File movie : mediaFile.getParentFile().listFiles(VIDEO_FILES)) {
|
||||
if (name.startsWith(FileUtilities.getName(movie))) {
|
||||
return movie;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ String.prototype.pad = Number.prototype.pad = function(length, padding) {
|
|||
* e.g. "Doctor Who" -> "Doctor_Who"
|
||||
*/
|
||||
String.prototype.space = function(replacement) {
|
||||
return this.replace(/\s/g, replacement);
|
||||
return this.replace(/\s+/g, replacement);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -55,7 +55,6 @@ public abstract class AbstractSearchPanel<S, E> extends JComponent {
|
|||
|
||||
|
||||
public AbstractSearchPanel() {
|
||||
|
||||
historyPanel.setColumnHeader(2, "Duration");
|
||||
|
||||
JScrollPane historyScrollPane = new JScrollPane(historyPanel, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER);
|
||||
|
|
|
@ -44,7 +44,7 @@ public class ListPanel extends JComponent {
|
|||
|
||||
private FileBotList<String> list = new FileBotList<String>();
|
||||
|
||||
private JTextField textField = new JTextField("Name - {i}", 25);
|
||||
private JTextField textField = new JTextField("Name - {i}", 30);
|
||||
private SpinnerNumberModel fromSpinnerModel = new SpinnerNumberModel(1, 0, Integer.MAX_VALUE, 1);
|
||||
private SpinnerNumberModel toSpinnerModel = new SpinnerNumberModel(20, 0, Integer.MAX_VALUE, 1);
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -113,7 +113,7 @@ class AutoFetchEpisodeListMatcher extends SwingWorker<List<Match<File, Episode>>
|
|||
protected List<Match<File, Episode>> doInBackground() throws Exception {
|
||||
|
||||
// focus on movie and subtitle files
|
||||
List<File> mediaFiles = FileUtilities.filter(files, MOVIE_FILES, SUBTITLE_FILES);
|
||||
List<File> mediaFiles = FileUtilities.filter(files, VIDEO_FILES, SUBTITLE_FILES);
|
||||
|
||||
// detect series name and fetch episode list
|
||||
List<Episode> episodes = fetchEpisodeList(detectSeriesNames(mediaFiles));
|
||||
|
@ -121,7 +121,7 @@ class AutoFetchEpisodeListMatcher extends SwingWorker<List<Match<File, Episode>>
|
|||
List<Match<File, Episode>> matches = new ArrayList<Match<File, Episode>>();
|
||||
|
||||
// group by subtitles first and then by files in general
|
||||
for (List<File> filesPerType : mapByFileType(mediaFiles, MOVIE_FILES, SUBTITLE_FILES).values()) {
|
||||
for (List<File> filesPerType : mapByFileType(mediaFiles, VIDEO_FILES, SUBTITLE_FILES).values()) {
|
||||
Matcher<File, Episode> matcher = new Matcher<File, Episode>(filesPerType, episodes, metrics);
|
||||
matches.addAll(matcher.match());
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ class AutoFetchEpisodeListMatcher extends SwingWorker<List<Match<File, Episode>>
|
|||
|
||||
protected Map<FileFilter, List<File>> mapByFileType(Collection<File> files, FileFilter... filters) {
|
||||
// initialize map, keep filter order
|
||||
Map<FileFilter, List<File>> map = new HashMap<FileFilter, List<File>>(filters.length);
|
||||
Map<FileFilter, List<File>> map = new LinkedHashMap<FileFilter, List<File>>(filters.length);
|
||||
|
||||
// initialize value lists
|
||||
for (FileFilter filter : filters) {
|
||||
|
@ -156,8 +156,9 @@ class AutoFetchEpisodeListMatcher extends SwingWorker<List<Match<File, Episode>>
|
|||
for (File file : files) {
|
||||
for (FileFilter filter : filters) {
|
||||
if (filter.accept(file)) {
|
||||
// put each value into one group only
|
||||
map.get(filter).add(file);
|
||||
|
||||
// put each value into one group only
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue