Support "Generic File" renaming via the command-line tools by using `--db xattr -non-strict` so that only xattr-tagged files are processed in strict mode, but any generic file can be processed in non-strict mode (File object is used in absence of Episode/Movie object)
This commit is contained in:
parent
bbc1bef181
commit
2d0a16688e
|
@ -115,8 +115,8 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
return renameMusic(files, action, conflictAction, outputDir, format, getMusicIdentificationService(db));
|
||||
}
|
||||
|
||||
if (XattrMetaData.getName().equalsIgnoreCase(db)) {
|
||||
return renameByMetaData(files, action, conflictAction, outputDir, format, filter, XattrMetaData);
|
||||
if (XattrMetaData.getIdentifier().equalsIgnoreCase(db)) {
|
||||
return renameFiles(files, action, conflictAction, outputDir, format, XattrMetaData, filter, strict);
|
||||
}
|
||||
|
||||
// auto-detect mode for each fileset
|
||||
|
@ -534,23 +534,23 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
return renameAll(renameMap, renameAction, conflictAction, null);
|
||||
}
|
||||
|
||||
public List<File> renameByMetaData(Collection<File> files, RenameAction renameAction, ConflictAction conflictAction, File outputDir, ExpressionFormat format, ExpressionFilter filter, XattrMetaInfoProvider service) throws Exception {
|
||||
public List<File> renameFiles(Collection<File> files, RenameAction renameAction, ConflictAction conflictAction, File outputDir, ExpressionFormat format, XattrMetaInfoProvider service, ExpressionFilter filter, boolean strict) throws Exception {
|
||||
log.config(format("Rename files using [%s]", service.getName()));
|
||||
|
||||
// force sort order
|
||||
List<File> selection = sortByUniquePath(files);
|
||||
// match to xattr metadata object or the file itself
|
||||
Map<File, Object> matches = service.match(files, strict);
|
||||
|
||||
Map<File, File> renameMap = new LinkedHashMap<File, File>();
|
||||
|
||||
for (Entry<File, Object> it : service.getMetaData(selection).entrySet()) {
|
||||
MediaBindingBean bindingBean = new MediaBindingBean(it.getValue(), it.getKey());
|
||||
for (Entry<File, Object> it : matches.entrySet()) {
|
||||
MediaBindingBean bindingBean = new MediaBindingBean(it.getValue(), it.getKey(), matches);
|
||||
|
||||
if (filter == null || filter.matches(bindingBean)) {
|
||||
String newName = (format != null) ? format.format(bindingBean) : validateFileName(it.getValue().toString());
|
||||
String newName = format != null ? format.format(bindingBean) : bindingBean.getInfoObject() instanceof File ? bindingBean.getInfoObject().toString() : validateFileName(bindingBean.getInfoObject().toString());
|
||||
renameMap.put(it.getKey(), getDestinationFile(it.getKey(), newName, outputDir));
|
||||
}
|
||||
}
|
||||
|
||||
// rename files according to xattr metadata objects
|
||||
return renameAll(renameMap, renameAction, conflictAction, null);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package net.filebot.media;
|
||||
|
||||
import static net.filebot.media.XattrMetaInfo.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -22,13 +21,19 @@ public class XattrMetaInfoProvider implements Datasource {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Map<File, Object> getMetaData(Iterable<File> files) {
|
||||
public Map<File, Object> match(Collection<File> files, boolean strict) {
|
||||
// enable xattr regardless of -DuseExtendedFileAttributes system properties
|
||||
XattrMetaInfo xattr = new XattrMetaInfo(true, false);
|
||||
|
||||
Map<File, Object> result = new LinkedHashMap<File, Object>();
|
||||
|
||||
for (File f : files) {
|
||||
Object metaObject = xattr.getMetaInfo(f);
|
||||
if (metaObject != null) {
|
||||
result.put(f, metaObject);
|
||||
Object object = xattr.getMetaInfo(f);
|
||||
|
||||
if (object != null) {
|
||||
result.put(f, object);
|
||||
} else if (!strict) {
|
||||
result.put(f, f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -314,21 +314,11 @@ public class RenamePanel extends JComponent {
|
|||
try {
|
||||
if (namesList.getModel().isEmpty()) {
|
||||
withWaitCursor(evt.getSource(), () -> {
|
||||
// try to read xattr from all files
|
||||
Map<File, Object> xattr = WebServices.XattrMetaData.getMetaData(renameModel.files());
|
||||
|
||||
// upper list is based on xattr metadata
|
||||
List<File> files = new ArrayList<File>(xattr.keySet());
|
||||
List<Object> objects = new ArrayList<Object>(xattr.values());
|
||||
|
||||
// lower list is just the fallback file object
|
||||
renameModel.files().stream().filter(f -> !xattr.containsKey(f)).forEach(f -> {
|
||||
files.add(f);
|
||||
objects.add(f);
|
||||
});
|
||||
// match to xattr metadata object or the file itself
|
||||
Map<File, Object> xattr = WebServices.XattrMetaData.match(renameModel.files(), false);
|
||||
|
||||
renameModel.clear();
|
||||
renameModel.addAll(objects, files);
|
||||
renameModel.addAll(xattr.values(), xattr.keySet());
|
||||
});
|
||||
} else {
|
||||
int index = namesList.getListComponent().getSelectedIndex();
|
||||
|
|
Loading…
Reference in New Issue