* improved --compute hash CLI function
This commit is contained in:
parent
c981cba2e2
commit
9574172b35
|
@ -50,6 +50,7 @@ import net.sourceforge.filebot.hash.HashType;
|
||||||
import net.sourceforge.filebot.hash.VerificationFileReader;
|
import net.sourceforge.filebot.hash.VerificationFileReader;
|
||||||
import net.sourceforge.filebot.hash.VerificationFileWriter;
|
import net.sourceforge.filebot.hash.VerificationFileWriter;
|
||||||
import net.sourceforge.filebot.media.MediaDetection;
|
import net.sourceforge.filebot.media.MediaDetection;
|
||||||
|
import net.sourceforge.filebot.similarity.CommonSequenceMatcher;
|
||||||
import net.sourceforge.filebot.similarity.EpisodeMatcher;
|
import net.sourceforge.filebot.similarity.EpisodeMatcher;
|
||||||
import net.sourceforge.filebot.similarity.Match;
|
import net.sourceforge.filebot.similarity.Match;
|
||||||
import net.sourceforge.filebot.similarity.NameSimilarityMetric;
|
import net.sourceforge.filebot.similarity.NameSimilarityMetric;
|
||||||
|
@ -909,16 +910,26 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File compute(Collection<File> files, String output, String csn) throws Exception {
|
public File compute(Collection<File> files, String output, String csn) throws Exception {
|
||||||
// check common parent for all given files
|
// ignore folders and any sort of special files
|
||||||
File root = null;
|
files = filter(files, FILES);
|
||||||
for (File it : files) {
|
|
||||||
if (root == null || root.getPath().startsWith(it.getParent()))
|
|
||||||
root = it.getParentFile();
|
|
||||||
|
|
||||||
if (!it.getParent().startsWith(root.getPath()))
|
// find common parent folder of all files
|
||||||
throw new Exception("Paths don't share a common root: " + files);
|
File[] fileList = files.toArray(new File[0]);
|
||||||
|
File[][] pathArray = new File[fileList.length][];
|
||||||
|
for (int i = 0; i < fileList.length; i++) {
|
||||||
|
pathArray[i] = listPath(fileList[i].getParentFile()).toArray(new File[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommonSequenceMatcher csm = new CommonSequenceMatcher(null, 0, true);
|
||||||
|
File[] common = csm.matchFirstCommonSequence(pathArray);
|
||||||
|
|
||||||
|
if (common == null) {
|
||||||
|
throw new Exception("Paths must be on the same filesystem: " + files);
|
||||||
|
}
|
||||||
|
|
||||||
|
// last element in the common sequence must be the root folder
|
||||||
|
File root = common[common.length - 1];
|
||||||
|
|
||||||
// create verification file
|
// create verification file
|
||||||
File outputFile;
|
File outputFile;
|
||||||
HashType hashType;
|
HashType hashType;
|
||||||
|
@ -937,7 +948,11 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
throw new Exception("Illegal output type: " + output);
|
throw new Exception("Illegal output type: " + output);
|
||||||
}
|
}
|
||||||
|
|
||||||
CLILogger.config("Using output file: " + outputFile);
|
if (files.isEmpty()) {
|
||||||
|
throw new Exception("No files: " + files);
|
||||||
|
}
|
||||||
|
|
||||||
|
CLILogger.info(format("Compute %s hash for %s files [%s]", hashType, files.size(), outputFile));
|
||||||
compute(root.getPath(), files, outputFile, hashType, csn);
|
compute(root.getPath(), files, outputFile, hashType, csn);
|
||||||
|
|
||||||
return outputFile;
|
return outputFile;
|
||||||
|
@ -985,7 +1000,6 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
VerificationFileWriter out = new VerificationFileWriter(outputFile, hashType.getFormat(), csn != null ? csn : "UTF-8");
|
VerificationFileWriter out = new VerificationFileWriter(outputFile, hashType.getFormat(), csn != null ? csn : "UTF-8");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CLILogger.fine("Computing hashes");
|
|
||||||
for (File it : files) {
|
for (File it : files) {
|
||||||
if (it.isHidden() || MediaTypes.getDefaultFilter("verification").accept(it))
|
if (it.isHidden() || MediaTypes.getDefaultFilter("verification").accept(it))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -89,6 +89,7 @@
|
||||||
^queue$
|
^queue$
|
||||||
^raid$
|
^raid$
|
||||||
^rename$
|
^rename$
|
||||||
|
^rip$
|
||||||
^Romance$
|
^Romance$
|
||||||
^rtorrent$
|
^rtorrent$
|
||||||
^Science.Fiction$
|
^Science.Fiction$
|
||||||
|
@ -97,6 +98,7 @@
|
||||||
^Season$
|
^Season$
|
||||||
^Seeding$
|
^Seeding$
|
||||||
^Seeds$
|
^Seeds$
|
||||||
|
^Serier$
|
||||||
^Series$
|
^Series$
|
||||||
^share$
|
^share$
|
||||||
^sort$
|
^sort$
|
||||||
|
|
Loading…
Reference in New Issue