mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-16 06:15:02 -05:00
+ presets & macros (WIP)
This commit is contained in:
parent
cf38e20c19
commit
8e57f48cb7
BIN
source/net/filebot/resources/action.script.png
Executable file
BIN
source/net/filebot/resources/action.script.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 861 B |
BIN
source/net/filebot/resources/script.add.png
Executable file
BIN
source/net/filebot/resources/script.add.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
source/net/filebot/resources/script.remove.png
Executable file
BIN
source/net/filebot/resources/script.remove.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
122
source/net/filebot/ui/rename/Preset.java
Normal file
122
source/net/filebot/ui/rename/Preset.java
Normal file
@ -0,0 +1,122 @@
|
||||
package net.filebot.ui.rename;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.filebot.StandardRenameAction;
|
||||
import net.filebot.WebServices;
|
||||
import net.filebot.format.ExpressionFormat;
|
||||
import net.filebot.ui.rename.FormatDialog.Mode;
|
||||
import net.filebot.web.EpisodeListProvider;
|
||||
import net.filebot.web.MovieIdentificationService;
|
||||
import net.filebot.web.MusicIdentificationService;
|
||||
import net.filebot.web.SortOrder;
|
||||
|
||||
public class Preset {
|
||||
|
||||
public String name;
|
||||
public String path;
|
||||
public String includes;
|
||||
public String format;
|
||||
public String database;
|
||||
public String sortOrder;
|
||||
public String matchMode;
|
||||
public String language;
|
||||
public String action;
|
||||
|
||||
public Preset(String name, String path, String includes, String format, String database, String sortOrder, String matchMode, String language, String action) {
|
||||
this.name = name;
|
||||
this.path = path;
|
||||
this.includes = includes;
|
||||
this.format = format;
|
||||
this.database = database;
|
||||
this.sortOrder = sortOrder;
|
||||
this.matchMode = matchMode;
|
||||
this.language = language;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public File getInputFolder() {
|
||||
return new File(path);
|
||||
}
|
||||
|
||||
public Pattern getIncludePattern() {
|
||||
return includes == null || includes.isEmpty() ? null : Pattern.compile(includes, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CHARACTER_CLASS);
|
||||
}
|
||||
|
||||
public ExpressionFormat getFormat() {
|
||||
try {
|
||||
return new ExpressionFormat(format);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
throw new IllegalStateException(database);
|
||||
}
|
||||
|
||||
public Mode getMode() {
|
||||
EpisodeListProvider sdb = WebServices.getEpisodeListProvider(database);
|
||||
if (sdb != null) {
|
||||
return Mode.Episode;
|
||||
}
|
||||
|
||||
MovieIdentificationService mdb = WebServices.getMovieIdentificationService(database);
|
||||
if (mdb != null) {
|
||||
return Mode.Movie;
|
||||
}
|
||||
|
||||
MusicIdentificationService adb = WebServices.getMusicIdentificationService(database);
|
||||
if (adb != null) {
|
||||
return Mode.Music;
|
||||
}
|
||||
|
||||
return Mode.File;
|
||||
}
|
||||
|
||||
public String getMatchMode() {
|
||||
return matchMode == null || matchMode.isEmpty() ? null : matchMode;
|
||||
}
|
||||
|
||||
public SortOrder getSortOrder() {
|
||||
try {
|
||||
return SortOrder.forName(sortOrder);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Locale getLanguage() {
|
||||
return language == null || language.isEmpty() ? null : new Locale(language);
|
||||
}
|
||||
|
||||
public StandardRenameAction getRenameAction() {
|
||||
try {
|
||||
return StandardRenameAction.forName(action);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -62,6 +62,7 @@ import net.filebot.similarity.Match;
|
||||
import net.filebot.ui.rename.FormatDialog.Mode;
|
||||
import net.filebot.ui.rename.RenameModel.FormattedFuture;
|
||||
import net.filebot.ui.transfer.BackgroundFileTransferablePolicy;
|
||||
import net.filebot.util.FileUtilities;
|
||||
import net.filebot.util.PreferencesMap.PreferencesEntry;
|
||||
import net.filebot.util.ui.ActionPopup;
|
||||
import net.filebot.util.ui.LoadingOverlayPane;
|
||||
@ -240,6 +241,11 @@ public class RenamePanel extends JComponent {
|
||||
filesList.getButtonPanel().add(createImageButton(clearFilesAction), "gap 0");
|
||||
filesList.getButtonPanel().add(createImageButton(openHistoryAction), "gap indent");
|
||||
|
||||
// create macros popup
|
||||
final Action macrosAction = new ShowPresetsPopupAction("Presets", ResourceManager.getIcon("action.script"));
|
||||
JButton macrosButton = createImageButton(macrosAction);
|
||||
filesList.getButtonPanel().add(macrosButton, "gap 0");
|
||||
|
||||
matchButton.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
@ -370,6 +376,41 @@ public class RenamePanel extends JComponent {
|
||||
return MATCH_MODE_STRICT.equalsIgnoreCase(persistentPreferredMatchMode.getValue());
|
||||
}
|
||||
|
||||
protected ActionPopup createPresetsPopup() {
|
||||
List<Preset> presets = new ArrayList<Preset>();
|
||||
|
||||
// TODO load presets via prefs
|
||||
|
||||
final ActionPopup actionPopup = new ActionPopup("Presets", ResourceManager.getIcon("action.script"));
|
||||
|
||||
if (presets.size() > 0) {
|
||||
actionPopup.addDescription(new JLabel("Apply:"));
|
||||
for (Preset it : presets) {
|
||||
actionPopup.add(new ApplyPresetAction(it));
|
||||
}
|
||||
}
|
||||
|
||||
actionPopup.addDescription(new JLabel("Options:"));
|
||||
actionPopup.add(new AbstractAction("New Preset", ResourceManager.getIcon("script.add")) {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
});
|
||||
actionPopup.add(new AbstractAction("Delete Preset", ResourceManager.getIcon("script.remove")) {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return actionPopup;
|
||||
}
|
||||
|
||||
protected ActionPopup createFetchPopup() {
|
||||
final ActionPopup actionPopup = new ActionPopup("Fetch & Match Data", ResourceManager.getIcon("action.fetch"));
|
||||
|
||||
@ -596,6 +637,84 @@ public class RenamePanel extends JComponent {
|
||||
}
|
||||
};
|
||||
|
||||
protected class ShowPresetsPopupAction extends AbstractAction {
|
||||
|
||||
public ShowPresetsPopupAction(String name, Icon icon) {
|
||||
super(name, icon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// display popup below component
|
||||
JComponent source = (JComponent) e.getSource();
|
||||
createPresetsPopup().show(source, -3, source.getHeight() + 4);
|
||||
}
|
||||
};
|
||||
|
||||
protected class ApplyPresetAction extends AutoCompleteAction {
|
||||
|
||||
private Preset preset;
|
||||
|
||||
public ApplyPresetAction(Preset preset) {
|
||||
super(preset.getName(), ResourceManager.getIcon("script.go"), preset.getAutoCompleteMatcher());
|
||||
this.preset = preset;
|
||||
}
|
||||
|
||||
public List<File> getFiles(ActionEvent evt) {
|
||||
List<File> input = new ArrayList<File>();
|
||||
if (preset.getInputFolder() != null) {
|
||||
for (File f : FileUtilities.listFiles(preset.getInputFolder())) {
|
||||
if (preset.getIncludePattern() == null || preset.getIncludePattern().matcher(f.getPath()).find()) {
|
||||
input.add(f);
|
||||
}
|
||||
}
|
||||
renameModel.clear();
|
||||
renameModel.files().addAll(input);
|
||||
} else {
|
||||
input.addAll(super.getFiles(evt));
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
public boolean isStrict(ActionEvent evt) {
|
||||
return preset.getMatchMode() != null ? MATCH_MODE_STRICT.equals(preset.getMatchMode()) : super.isStrict(evt);
|
||||
}
|
||||
|
||||
public SortOrder getSortOrder(ActionEvent evt) {
|
||||
return preset.getSortOrder() != null ? preset.getSortOrder() : super.getSortOrder(evt);
|
||||
}
|
||||
|
||||
public Locale getLocale(ActionEvent evt) {
|
||||
return preset.getLanguage() != null ? preset.getLanguage() : super.getLocale(evt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
if (preset.getFormat() != null) {
|
||||
switch (preset.getMode()) {
|
||||
case Episode:
|
||||
renameModel.useFormatter(Episode.class, new ExpressionFormatter(preset.getFormat().getExpression(), EpisodeFormat.SeasonEpisode, Episode.class));
|
||||
break;
|
||||
case Movie:
|
||||
renameModel.useFormatter(Movie.class, new ExpressionFormatter(preset.getFormat().getExpression(), MovieFormat.NameYear, Movie.class));
|
||||
break;
|
||||
case Music:
|
||||
renameModel.useFormatter(AudioTrack.class, new ExpressionFormatter(preset.getFormat().getExpression(), new AudioTrackFormat(), AudioTrack.class));
|
||||
break;
|
||||
case File:
|
||||
renameModel.useFormatter(File.class, new ExpressionFormatter(preset.getFormat().getExpression(), new FileNameFormat(), File.class));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (preset.getRenameAction() != null) {
|
||||
new SetRenameAction(preset.getRenameAction(), preset.getRenameAction().getDisplayName(), ResourceManager.getIcon("rename.action." + preset.getRenameAction().toString().toLowerCase())).actionPerformed(evt);
|
||||
}
|
||||
|
||||
super.actionPerformed(evt);
|
||||
}
|
||||
}
|
||||
|
||||
protected class SetRenameMode extends AbstractAction {
|
||||
|
||||
private final boolean activate;
|
||||
@ -640,7 +759,7 @@ public class RenamePanel extends JComponent {
|
||||
|
||||
protected class AutoCompleteAction extends AbstractAction {
|
||||
|
||||
private final AutoCompleteMatcher matcher;
|
||||
protected final AutoCompleteMatcher matcher;
|
||||
|
||||
public AutoCompleteAction(String name, Icon icon, AutoCompleteMatcher matcher) {
|
||||
super(name, icon);
|
||||
@ -658,16 +777,36 @@ public class RenamePanel extends JComponent {
|
||||
});
|
||||
}
|
||||
|
||||
public List<File> getFiles(ActionEvent evt) {
|
||||
return renameModel.files();
|
||||
}
|
||||
|
||||
public boolean isStrict(ActionEvent evt) {
|
||||
return isMatchModeStrict();
|
||||
}
|
||||
|
||||
public SortOrder getSortOrder(ActionEvent evt) {
|
||||
return SortOrder.forName(persistentPreferredEpisodeOrder.getValue());
|
||||
}
|
||||
|
||||
private Locale getLocale(ActionEvent evt) {
|
||||
return new Locale(persistentPreferredLanguage.getValue());
|
||||
}
|
||||
|
||||
private boolean isAutoDetectionEnabled(ActionEvent evt) {
|
||||
return !isShiftOrAltDown(evt); // skip name auto-detection if SHIFT is pressed
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent evt) {
|
||||
// clear names list
|
||||
renameModel.values().clear();
|
||||
|
||||
final List<File> remainingFiles = new LinkedList<File>(renameModel.files());
|
||||
final boolean strict = isMatchModeStrict();
|
||||
final SortOrder order = SortOrder.forName(persistentPreferredEpisodeOrder.getValue());
|
||||
final Locale locale = new Locale(persistentPreferredLanguage.getValue());
|
||||
final boolean autodetection = !isShiftOrAltDown(evt); // skip name auto-detection if SHIFT is pressed
|
||||
final List<File> remainingFiles = new LinkedList<File>(getFiles(evt));
|
||||
final boolean strict = isStrict(evt);
|
||||
final SortOrder order = getSortOrder(evt);
|
||||
final Locale locale = getLocale(evt);
|
||||
final boolean autodetection = isAutoDetectionEnabled(evt);
|
||||
|
||||
if (isMacSandbox()) {
|
||||
if (!MacAppUtilities.askUnlockFolders(getWindow(RenamePanel.this), remainingFiles)) {
|
||||
@ -721,6 +860,7 @@ public class RenamePanel extends JComponent {
|
||||
|
||||
worker.execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user