* support File "datasource" to allow advanced users to create generic file rename presets

This commit is contained in:
Reinhard Pointner 2015-07-25 22:47:39 +00:00
parent 0d314b786c
commit 3bb317cad0
7 changed files with 95 additions and 31 deletions

View File

@ -111,22 +111,6 @@ public final class WebServices {
return null; // default
}
public static Datasource getDatasourceByName(String name) {
EpisodeListProvider sdb = WebServices.getEpisodeListProvider(name);
if (sdb != null) {
return sdb;
}
MovieIdentificationService mdb = WebServices.getMovieIdentificationService(name);
if (mdb != null) {
return mdb;
}
MusicIdentificationService adb = WebServices.getMusicIdentificationService(name);
if (adb != null) {
return adb;
}
return null;
}
public static final ExecutorService requestThreadPool = Executors.newCachedThreadPool();
public static class TheTVDBClientWithLocalSearch extends TheTVDBClient {

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

View File

@ -452,7 +452,7 @@ public class FormatDialog extends JDialog {
String sample = bundle.getString(mode.key() + ".sample");
info = JsonReader.jsonToJava(sample);
} catch (Exception illegalSample) {
throw new RuntimeException(illegalSample); // won't happen
Logger.getLogger(RenamePanel.class.getName()).log(Level.SEVERE, "Illegal Sample", e);
}
}

View File

@ -0,0 +1,39 @@
package net.filebot.ui.rename;
import java.awt.Component;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import javax.swing.Icon;
import net.filebot.ResourceManager;
import net.filebot.similarity.Match;
import net.filebot.web.Datasource;
import net.filebot.web.SortOrder;
public class PlainFileMatcher implements Datasource, AutoCompleteMatcher {
public static final PlainFileMatcher INSTANCE = new PlainFileMatcher();
@Override
public String getName() {
return "File";
}
@Override
public Icon getIcon() {
return ResourceManager.getIcon("file.text");
}
@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;
}
}

View File

@ -8,7 +8,6 @@ import net.filebot.StandardRenameAction;
import net.filebot.WebServices;
import net.filebot.format.ExpressionFilter;
import net.filebot.format.ExpressionFormat;
import net.filebot.ui.rename.FormatDialog.Mode;
import net.filebot.web.Datasource;
import net.filebot.web.EpisodeListProvider;
import net.filebot.web.MovieIdentificationService;
@ -63,26 +62,44 @@ public class Preset {
}
}
public Datasource getDatasource() {
return WebServices.getDatasourceByName(database);
}
public AutoCompleteMatcher getAutoCompleteMatcher() {
EpisodeListProvider sdb = WebServices.getEpisodeListProvider(database);
if (sdb != null) {
return new EpisodeListMatcher(sdb, sdb != WebServices.AniDB, sdb == WebServices.AniDB);
}
MovieIdentificationService mdb = WebServices.getMovieIdentificationService(database);
if (mdb != null) {
return new MovieHashMatcher(mdb);
}
MusicIdentificationService adb = WebServices.getMusicIdentificationService(database);
if (adb != null) {
return new AudioFingerprintMatcher(adb);
}
if (PlainFileMatcher.INSTANCE.getName().equals(database)) {
return PlainFileMatcher.INSTANCE;
}
throw new IllegalStateException(database);
}
public Datasource getDatasource() {
if (database == null || database.isEmpty()) {
return null;
}
EpisodeListProvider sdb = WebServices.getEpisodeListProvider(database);
if (sdb != null) {
return sdb;
}
MovieIdentificationService mdb = WebServices.getMovieIdentificationService(database);
if (mdb != null) {
return mdb;
}
MusicIdentificationService adb = WebServices.getMusicIdentificationService(database);
if (adb != null) {
return adb;
}
if (PlainFileMatcher.INSTANCE.getName().equals(database)) {
return PlainFileMatcher.INSTANCE;
}
throw new IllegalStateException(database);
}

View File

@ -11,6 +11,7 @@ import java.awt.Window;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.EnumSet;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.Action;
@ -37,9 +38,10 @@ import net.filebot.UserFiles;
import net.filebot.WebServices;
import net.filebot.format.ExpressionFilter;
import net.filebot.format.ExpressionFormat;
import net.filebot.format.MediaBindingBean;
import net.filebot.ui.HeaderPanel;
import net.filebot.util.FileUtilities.ExtensionFileFilter;
import net.filebot.web.Datasource;
import net.filebot.web.EpisodeListProvider;
import net.filebot.web.SortOrder;
import net.miginfocom.swing.MigLayout;
@ -76,7 +78,7 @@ public class PresetEditor extends JDialog {
presetNameHeader = new HeaderPanel();
inheritRadio = new JRadioButton("<html>Use <b>Original Files</b> selection</html>");
selectRadio = new JRadioButton("<html>Do <b>Select</b></html>");
selectRadio = new JRadioButton("<html>Do <b>Select</b> files</html>");
pathInput = new JTextField(40);
filterEditor = createEditor();
@ -134,9 +136,6 @@ public class PresetEditor extends JDialog {
selectRadio.addItemListener((evt) -> {
inputPanel.setVisible(selectRadio.isSelected());
});
providerCombo.addItemListener((evt) -> {
sortOrderCombo.setEnabled(evt.getItem() instanceof EpisodeListProvider);
});
setSize(650, 570);
}
@ -218,6 +217,7 @@ public class PresetEditor extends JDialog {
providers.addElement(it);
}
}
providers.addElement(PlainFileMatcher.INSTANCE);
JComboBox<Datasource> combo = new JComboBox<Datasource>(providers);
combo.setRenderer(new ListCellRenderer<Object>() {
@ -328,7 +328,16 @@ public class PresetEditor extends JDialog {
@Override
public void actionPerformed(ActionEvent evt) {
FormatDialog.Mode mode = FormatDialog.Mode.getMode((Datasource) providerCombo.getSelectedItem());
FormatDialog dialog = new FormatDialog(getWindow(evt.getSource()), mode, null);
MediaBindingBean lockOnBinding = null;
if (mode == FormatDialog.Mode.File) {
List<File> files = UserFiles.showLoadDialogSelectFiles(false, false, null, new ExtensionFileFilter(ExtensionFileFilter.WILDCARD), "Select Sample File", evt);
if (files.isEmpty()) {
return;
}
lockOnBinding = new MediaBindingBean(files.get(0), files.get(0));
}
FormatDialog dialog = new FormatDialog(getWindow(evt.getSource()), mode, lockOnBinding);
dialog.setFormatCode(formatEditor.getText());
dialog.setLocation(getOffsetLocation(dialog.getOwner()));
dialog.setVisible(true);

View File

@ -1,6 +1,7 @@
package net.filebot.ui.rename;
import static java.awt.event.KeyEvent.*;
import static java.util.Collections.*;
import static javax.swing.JOptionPane.*;
import static javax.swing.KeyStroke.*;
import static javax.swing.SwingUtilities.*;
@ -421,6 +422,7 @@ public class RenamePanel extends JComponent {
}
PresetEditor presetEditor = new PresetEditor(getWindow(evt.getSource()));
presetEditor.setLocation(getOffsetLocation(presetEditor.getOwner()));
presetEditor.setPreset(preset);
presetEditor.setVisible(true);
@ -698,6 +700,11 @@ public class RenamePanel extends JComponent {
public List<File> getFiles(ActionEvent evt) {
List<File> input = new ArrayList<File>();
if (preset.getInputFolder() != null) {
if (isMacSandbox()) {
if (!MacAppUtilities.askUnlockFolders(getWindow(RenamePanel.this), singleton(preset.getInputFolder()))) {
throw new IllegalStateException("Unable to access folder: " + preset.getInputFolder());
}
}
input.addAll(FileUtilities.listFiles(preset.getInputFolder()));
ExpressionFilter filter = preset.getIncludeFilter();
if (filter != null) {
@ -715,6 +722,10 @@ public class RenamePanel extends JComponent {
} else {
input.addAll(super.getFiles(evt));
}
if (input.isEmpty()) {
throw new IllegalStateException("No files selected.");
}
return input;
}
@ -755,7 +766,11 @@ public class RenamePanel extends JComponent {
new SetRenameAction(preset.getRenameAction(), preset.getRenameAction().getDisplayName(), ResourceManager.getIcon("rename.action." + preset.getRenameAction().toString().toLowerCase())).actionPerformed(evt);
}
super.actionPerformed(evt);
try {
super.actionPerformed(evt);
} catch (Exception e) {
UILogger.info(e.getMessage());
}
}
}