Skip to content

Commit

Permalink
Mass update: Image processing pipeline rewritten, cli and gui partially
Browse files Browse the repository at this point in the history
implemented.
  • Loading branch information
apaz committed Aug 5, 2020
1 parent d80f1dc commit 9b54b56
Show file tree
Hide file tree
Showing 81 changed files with 3,790 additions and 2,440 deletions.
17 changes: 9 additions & 8 deletions Image-Hashing-Tools/.classpath
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="src" path="cli-src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
4 changes: 4 additions & 0 deletions Image-Hashing-Tools/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=1.8
109 changes: 109 additions & 0 deletions Image-Hashing-Tools/cli-src/app/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package app;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import app.commands.Command;
import app.commands.GuidedMerge;
import app.commands.ListDuplicates;
import app.commands.PartialMerge;
import app.commands.TrimExact;

public class Main {

// @nof
private static String HELP =
"Usage: ihtools [options]... command [arguments]...\n" +
"Options:\n" +
" -h, --help Display this message and exit.\n" +
" -c, --commands Display a help message detailing the usage of each command.\n" +
" -v, --verbose Print all the files that are created, move or are deleted as a result of this program.\n" +
" -t, --test Print all the files that would be created, moved, or be deleted as a result of this program, but don't.\n" +
" -r, --regex Use regex pattern matching for file and Sources instead of glob syntax.\n" +
" -p, --pHash Use the pHash algorithm for comparison.\n" +
" -d, --dHash Use the dHash algorithm for comparison.\n";


private static String COMMANDHELP =
"╔═══════════════╤══════════════════════╤═══════════════════════════════════════╗\n" +
"║Command │ Arguments │ Description ║\n" +
"╟───────────────┼──────────────────────┼───────────────────────────────────────╢\n" +
"║partialmerge │ fromSource toSource │ Delete images that are identical to ║\n" +
"║ │ │ one in toSource, leave images with ║\n" +
"║ │ │ partial matches, and move the rest, ║\n" +
"║ │ │ avoiding name collisions. ║\n" +
"╟───────────────┼──────────────────────┼───────────────────────────────────────╢\n" +
"║guidedmerge │ fromSource toSource │ Do a partialmerge, but a gui pops up ║\n" +
"║ │ │ for partial matches asking what to do.║\n" +
"╟───────────────┼──────────────────────┼───────────────────────────────────────╢\n" +
"║trimexact │ fromSource refSource │ Delete images in fromSource with an ║\n" +
"║ │ │ identical duplicate in refSource. Note║\n" +
"║ │ │ that fromSource and refSource can be ║\n" +
"║ │ │ the same Source. ║\n" +
"╟───────────────┼──────────────────────┼───────────────────────────────────────╢\n" +
"║listduplicates │ fromSource refSource │ Cross-compare and list the partial and║\n" +
"║ │ │ exact duplicates of images in from ║\n" +
"║ │ │ Source to the ones in refSource. Like ║\n" +
"║ │ │ with trimexact, these may be the same.║\n" +
"╚═══════════════╧══════════════════════╧═══════════════════════════════════════╝\n" +
" Note: \n" +
" Arguments for Sources can be either a folder containing images, or \n" +
" alternatively a text file containing links to images, one on each line. The \n" +
" images will be loaded or downloaded, hashed, and matches will be reloaded \n" +
" or redownloaded to check for exact duplicates. Sources will be edited at \n" +
" the end of the process to reflect changes. \n";
// @dof

private static HashMap<String, app.commands.Command> commands = new HashMap<>();
static {
commands.put("partialmerge", new PartialMerge());
commands.put("trimexact", new TrimExact());
commands.put("guidedmerge", new GuidedMerge());
commands.put("listduplicates", new ListDuplicates());
}

public static void main(String[] args) {
// Print usage if no args
if (args.length == 0) {
System.out.println(HELP);
System.exit(0);
}

// Exit if help
for (String arg : args) {
if (arg.equals("-h") || arg.equals("--help")) {
System.out.println(HELP);
System.exit(0);
} else if (arg.equals("-c") || arg.equals("--commands")) {
System.out.println(COMMANDHELP);
System.exit(0);
}
}

// The options constructor strips the flags from the arguments, as well as the
// command name. It contains all the configurations necessary for the command to
// run, as well as which command to run.
ArrayList<String> arguments = new ArrayList<>(Arrays.asList(args));
Options options = new Options(arguments);

Command command = parseCommand(arguments);
command.acceptOptions(options);
arguments.trimToSize();
command.acceptArgs(arguments);

command.run();
}

// The flags have been removed from the arg list.
private static app.commands.Command parseCommand(List<String> args) {
Command command = commands.get(args.remove(0).toLowerCase());
if (command == null) {
System.out.println("Please enter a valid command. Use -c or --commands to display a list.");
System.exit(0);
}
return command;
}

}
41 changes: 41 additions & 0 deletions Image-Hashing-Tools/cli-src/app/Options.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package app;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import hash.IHashAlgorithm;
import hash.implementations.DifferenceHash;
import hash.implementations.PerceptualHash;

public class Options {

public IHashAlgorithm algorithm = new DifferenceHash();
public boolean touchDisk = true;
public boolean verbose = false;
public boolean globMatch = true;

public Options(List<String> args) {
List<String> flags = Arrays.asList(
new String[] { "-v", "--verbose", "-t", "--test", "-r", "--regex", "-p", "--phash", "-d", "--dhash" });

boolean algSeen = false;

List<String> toRemove = new ArrayList<>();
for (String arg : args) {
if (flags.contains(arg.toLowerCase())) {
// @nof
if (!algSeen) {
if (arg.contains("-p")) algorithm = new PerceptualHash();
else if (arg.contains("-d")) algorithm = new DifferenceHash();
}
else if (arg.contains("-v")) verbose = true;
else if (arg.contains("-t")) touchDisk = false;
else if (arg.contains("-r")) globMatch = false;
// @dof
toRemove.add(arg);
}
}
args.removeAll(toRemove);
}
}
Loading

0 comments on commit 9b54b56

Please sign in to comment.