Support for using 7z and unrar tools
This commit is contained in:
parent
e96251f956
commit
9dd32ecbfa
|
@ -11,4 +11,4 @@ fi
|
||||||
APP_DATA="$HOME/.config/filebot"
|
APP_DATA="$HOME/.config/filebot"
|
||||||
LIBRARY_PATH="$FILEBOT_HOME/lib/$(uname -m)"
|
LIBRARY_PATH="$FILEBOT_HOME/lib/$(uname -m)"
|
||||||
|
|
||||||
$JAVA_HOME/bin/java -Dapplication.deployment=aur -Dapplication.update=skip -Dnet.filebot.Archive.extractor=SevenZipExecutable @{java.application.options} @{linux.application.options} @{linux.desktop.application.options} $JAVA_OPTS $FILEBOT_OPTS -jar "$FILEBOT_HOME/jar/filebot.jar" "$@"
|
$JAVA_HOME/bin/java -Dapplication.deployment=aur -Dapplication.update=skip -Dnet.filebot.archive.extractor=ShellExecutables @{java.application.options} @{linux.application.options} @{linux.desktop.application.options} $JAVA_OPTS $FILEBOT_OPTS -jar "$FILEBOT_HOME/jar/filebot.jar" "$@"
|
||||||
|
|
|
@ -8,5 +8,5 @@ Homepage: @{package.homepage}
|
||||||
Section: utils
|
Section: utils
|
||||||
Priority: extra
|
Priority: extra
|
||||||
Depends: openjdk-@{jvm.version}-jre
|
Depends: openjdk-@{jvm.version}-jre
|
||||||
Recommends: openjfx, libjna-jni, libmediainfo0v5, libchromaprint-tools, p7zip-full, p7zip-rar
|
Recommends: openjfx, libjna-jni, libmediainfo0v5, libchromaprint-tools, p7zip-full, unrar
|
||||||
Enhances: nautilus-actions
|
Enhances: nautilus-actions
|
||||||
|
|
|
@ -11,4 +11,4 @@ APP_DATA="$HOME/.filebot"
|
||||||
LIBRARY_PATH="/usr/lib/$(uname -m)-linux-gnu/jni"
|
LIBRARY_PATH="/usr/lib/$(uname -m)-linux-gnu/jni"
|
||||||
MODULE_PATH="/usr/share/openjfx/lib"
|
MODULE_PATH="/usr/share/openjfx/lib"
|
||||||
|
|
||||||
java -Dapplication.deployment=deb --module-path "$MODULE_PATH" --add-modules ALL-MODULE-PATH -Djna.boot.library.name=jnidispatch.system -Dnet.filebot.Archive.extractor=SevenZipExecutable @{java.application.options} @{linux.application.options} @{linux.desktop.application.options} $JAVA_OPTS $FILEBOT_OPTS -jar "$FILEBOT_HOME/jar/filebot.jar" "$@"
|
java -Dapplication.deployment=deb --module-path "$MODULE_PATH" --add-modules ALL-MODULE-PATH -Djna.boot.library.name=jnidispatch.system -Dnet.filebot.archive.extractor=ShellExecutables @{java.application.options} @{linux.application.options} @{linux.desktop.application.options} $JAVA_OPTS $FILEBOT_OPTS -jar "$FILEBOT_HOME/jar/filebot.jar" "$@"
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
-DuseExtendedFileAttributes=false
|
-DuseExtendedFileAttributes=false
|
||||||
|
|
||||||
# Use Apache VFS to extract archives
|
# Use Apache VFS to extract archives
|
||||||
-Dnet.filebot.Archive.extractor=ApacheVFS
|
-Dnet.filebot.archive.extractor=ApacheVFS
|
||||||
|
|
||||||
# Use Darcula LaF
|
# Use Darcula LaF
|
||||||
-Dnet.filebot.theme=Darcula
|
-Dnet.filebot.theme=Darcula
|
||||||
|
|
|
@ -21,7 +21,7 @@ export LANG="en_US.UTF-8"
|
||||||
export LC_ALL="en_US.UTF-8"
|
export LC_ALL="en_US.UTF-8"
|
||||||
|
|
||||||
# choose archive extractor / media characteristics parser
|
# choose archive extractor / media characteristics parser
|
||||||
ARCHIVE_EXTRACTOR="ApacheVFS"
|
ARCHIVE_EXTRACTOR="ShellExecutables"
|
||||||
MEDIA_PARSER="ffprobe"
|
MEDIA_PARSER="ffprobe"
|
||||||
|
|
||||||
# choose ffprobe executable
|
# choose ffprobe executable
|
||||||
|
@ -32,4 +32,4 @@ APP_DATA="$QPKG_ROOT/data/$USER"
|
||||||
LIBRARY_PATH="$PACKAGE_LIBRARY_PATH:$LD_LIBRARY_PATH"
|
LIBRARY_PATH="$PACKAGE_LIBRARY_PATH:$LD_LIBRARY_PATH"
|
||||||
|
|
||||||
# start filebot
|
# start filebot
|
||||||
java -Dapplication.deployment=qpkg -Dnet.filebot.license="$QPKG_ROOT/data/.license" -Dnet.filebot.media.parser="$MEDIA_PARSER" -Dnet.filebot.media.ffprobe="$FFPROBE" -Dnet.filebot.Archive.extractor="$ARCHIVE_EXTRACTOR" -Djava.awt.headless=true @{java.application.options} @{linux.application.options} @{linux.portable.application.options} $JAVA_OPTS $FILEBOT_OPTS -jar "$QPKG_ROOT/jar/filebot.jar" "$@"
|
java -Dapplication.deployment=qpkg -Dnet.filebot.license="$QPKG_ROOT/data/.license" -Dnet.filebot.media.parser="$MEDIA_PARSER" -Dnet.filebot.media.ffprobe="$FFPROBE" -Dnet.filebot.archive.extractor="$ARCHIVE_EXTRACTOR" -Djava.awt.headless=true @{java.application.options} @{linux.application.options} @{linux.portable.application.options} $JAVA_OPTS $FILEBOT_OPTS -jar "$QPKG_ROOT/jar/filebot.jar" "$@"
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
export G_MESSAGES_DEBUG=all
|
|
||||||
|
|
||||||
export LANG="en_US.UTF-8"
|
export LANG="en_US.UTF-8"
|
||||||
export LC_ALL="en_US.UTF-8"
|
export LC_ALL="en_US.UTF-8"
|
||||||
|
|
||||||
APP_DATA="$SNAP_USER_DATA/data"
|
APP_DATA="$SNAP_USER_DATA/data"
|
||||||
LIBRARY_PATH="$SNAP/filebot/lib:$SNAP/usr/lib/x86_64-linux-gnu"
|
LIBRARY_PATH="$SNAP/filebot/lib:$SNAP/usr/lib/x86_64-linux-gnu"
|
||||||
|
|
||||||
"$SNAP/usr/lib/jvm/java-8-openjdk-amd64/bin/java" -Dapplication.deployment=snap -Dapplication.update=skip -Dnet.filebot.Archive.extractor=SevenZipExecutable -Dnet.filebot.Archive.7z="$SNAP/usr/lib/p7zip/7z" -Dnet.filebot.AcoustID.fpcalc="$SNAP/usr/bin/fpcalc" @{java.application.options} @{linux.application.options} @{linux.desktop.application.options} @{linux.portable.application.options} $JAVA_OPTS $FILEBOT_OPTS -jar "$SNAP/filebot/jar/filebot.jar" "$@"
|
"$SNAP/usr/lib/jvm/java-8-openjdk-amd64/bin/java" -Dapplication.deployment=snap -Dapplication.update=skip -Dnet.filebot.archive.extractor=ShellExecutables -Dnet.filebot.archive.7z="$SNAP/usr/bin/7z" -Dnet.filebot.archive.unrar="$SNAP/usr/bin/unrar-nonfree" -Dnet.filebot.AcoustID.fpcalc="$SNAP/usr/bin/fpcalc" @{java.application.options} @{linux.application.options} @{linux.desktop.application.options} @{linux.portable.application.options} $JAVA_OPTS $FILEBOT_OPTS -jar "$SNAP/filebot/jar/filebot.jar" "$@"
|
||||||
|
|
|
@ -56,7 +56,7 @@ parts:
|
||||||
- libmediainfo0v5
|
- libmediainfo0v5
|
||||||
- libchromaprint-tools
|
- libchromaprint-tools
|
||||||
- p7zip-full
|
- p7zip-full
|
||||||
- p7zip-rar
|
- unrar
|
||||||
- xdg-utils
|
- xdg-utils
|
||||||
after:
|
after:
|
||||||
- desktop-gtk2
|
- desktop-gtk2
|
||||||
|
|
|
@ -48,12 +48,12 @@ export LC_ALL="en_US.UTF-8"
|
||||||
# choose archive extractor / media characteristics parser
|
# choose archive extractor / media characteristics parser
|
||||||
if uname -m | egrep -q "i386|i686|amd64|x86_64"; then
|
if uname -m | egrep -q "i386|i686|amd64|x86_64"; then
|
||||||
# i686 or x86_64
|
# i686 or x86_64
|
||||||
ARCHIVE_EXTRACTOR="SevenZipNativeBindings" # use lib7-Zip-JBinding.so
|
ARCHIVE_EXTRACTOR="SevenZipNativeBindings"
|
||||||
MEDIA_PARSER="libmediainfo" # use libmediainfo
|
MEDIA_PARSER="libmediainfo"
|
||||||
else
|
else
|
||||||
# armv7l or aarch64
|
# armv7l or aarch64
|
||||||
ARCHIVE_EXTRACTOR="ApacheVFS" # use Apache Commons VFS2
|
ARCHIVE_EXTRACTOR="ShellExecutables"
|
||||||
MEDIA_PARSER="ffprobe" # use ffprobe
|
MEDIA_PARSER="ffprobe"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# choose ffprobe executable
|
# choose ffprobe executable
|
||||||
|
@ -64,4 +64,4 @@ APP_DATA="$FILEBOT_HOME/data/$USER"
|
||||||
LIBRARY_PATH="$SYNO_LIBRARY_PATH:$PACKAGE_LIBRARY_PATH"
|
LIBRARY_PATH="$SYNO_LIBRARY_PATH:$PACKAGE_LIBRARY_PATH"
|
||||||
|
|
||||||
# start filebot
|
# start filebot
|
||||||
java -Dapplication.deployment=spk -Dnet.filebot.license="$FILEBOT_HOME/data/.license" -Dnet.filebot.media.parser="$MEDIA_PARSER" -Dnet.filebot.media.ffprobe="$FFPROBE" -Dnet.filebot.Archive.extractor="$ARCHIVE_EXTRACTOR" -Djava.awt.headless=true @{java.application.options} @{linux.application.options} @{linux.portable.application.options} $JAVA_OPTS $FILEBOT_OPTS -jar "$FILEBOT_HOME/jar/filebot.jar" "$@"
|
java -Dapplication.deployment=spk -Dnet.filebot.license="$FILEBOT_HOME/data/.license" -Dnet.filebot.media.parser="$MEDIA_PARSER" -Dnet.filebot.media.ffprobe="$FFPROBE" -Dnet.filebot.archive.extractor="$ARCHIVE_EXTRACTOR" -Djava.awt.headless=true @{java.application.options} @{linux.application.options} @{linux.portable.application.options} $JAVA_OPTS $FILEBOT_OPTS -jar "$FILEBOT_HOME/jar/filebot.jar" "$@"
|
||||||
|
|
|
@ -44,7 +44,7 @@ case $PACKAGE_LIBRARY_ARCH in
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
# armv7l or aarch64
|
# armv7l or aarch64
|
||||||
ARCHIVE_EXTRACTOR="ApacheVFS"
|
ARCHIVE_EXTRACTOR="ShellExecutables"
|
||||||
MEDIA_PARSER="ffprobe"
|
MEDIA_PARSER="ffprobe"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -54,4 +54,4 @@ APP_DATA="$FILEBOT_HOME/data/$USER"
|
||||||
LIBRARY_PATH="$PACKAGE_LIBRARY_PATH:$LD_LIBRARY_PATH"
|
LIBRARY_PATH="$PACKAGE_LIBRARY_PATH:$LD_LIBRARY_PATH"
|
||||||
|
|
||||||
# start filebot
|
# start filebot
|
||||||
java -Dapplication.deployment=tar -Dnet.filebot.license="$FILEBOT_HOME/data/.license" -Dnet.filebot.media.parser="$MEDIA_PARSER" -Dnet.filebot.Archive.extractor="$ARCHIVE_EXTRACTOR" @{java.application.options} @{linux.application.options} @{linux.portable.application.options} $JAVA_OPTS $FILEBOT_OPTS -jar "$FILEBOT_HOME/jar/filebot.jar" "$@"
|
java -Dapplication.deployment=tar -Dnet.filebot.license="$FILEBOT_HOME/data/.license" -Dnet.filebot.media.parser="$MEDIA_PARSER" -Dnet.filebot.archive.extractor="$ARCHIVE_EXTRACTOR" @{java.application.options} @{linux.application.options} @{linux.portable.application.options} $JAVA_OPTS $FILEBOT_OPTS -jar "$FILEBOT_HOME/jar/filebot.jar" "$@"
|
||||||
|
|
|
@ -24,19 +24,19 @@ import net.sf.sevenzipjbinding.ArchiveFormat;
|
||||||
public class Archive implements Closeable {
|
public class Archive implements Closeable {
|
||||||
|
|
||||||
public static Extractor getExtractor() {
|
public static Extractor getExtractor() {
|
||||||
return SystemProperty.of("net.filebot.Archive.extractor", Extractor::valueOf, Extractor.SevenZipNativeBindings).get();
|
return SystemProperty.of("net.filebot.archive.extractor", Extractor::valueOf, Extractor.SevenZipNativeBindings).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum Extractor {
|
public static enum Extractor {
|
||||||
|
|
||||||
SevenZipNativeBindings, SevenZipExecutable, ApacheVFS;
|
SevenZipNativeBindings, ShellExecutables, ApacheVFS;
|
||||||
|
|
||||||
public ArchiveExtractor newInstance(File archive) throws Exception {
|
public ArchiveExtractor newInstance(File archive) throws Exception {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case SevenZipNativeBindings:
|
case SevenZipNativeBindings:
|
||||||
return new SevenZipNativeBindings(archive);
|
return new SevenZipNativeBindings(archive);
|
||||||
case SevenZipExecutable:
|
case ShellExecutables:
|
||||||
return new SevenZipExecutable(archive);
|
return new ShellExecutables(archive);
|
||||||
default:
|
default:
|
||||||
return new ApacheVFS(archive);
|
return new ApacheVFS(archive);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class Archive implements Closeable {
|
||||||
public String[] getSupportedTypes() {
|
public String[] getSupportedTypes() {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case SevenZipNativeBindings:
|
case SevenZipNativeBindings:
|
||||||
case SevenZipExecutable:
|
case ShellExecutables:
|
||||||
return stream(ArchiveFormat.values()).map(ArchiveFormat::getMethodName).toArray(String[]::new);
|
return stream(ArchiveFormat.values()).map(ArchiveFormat::getMethodName).toArray(String[]::new);
|
||||||
default:
|
default:
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,119 +0,0 @@
|
||||||
package net.filebot.archive;
|
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.*;
|
|
||||||
import static java.util.Arrays.*;
|
|
||||||
import static net.filebot.Logging.*;
|
|
||||||
import static net.filebot.util.RegularExpressions.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileFilter;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.ProcessBuilder.Redirect;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import net.filebot.util.ByteBufferOutputStream;
|
|
||||||
import net.filebot.vfs.FileInfo;
|
|
||||||
import net.filebot.vfs.SimpleFileInfo;
|
|
||||||
|
|
||||||
public class SevenZipExecutable implements ArchiveExtractor {
|
|
||||||
|
|
||||||
private File archive;
|
|
||||||
|
|
||||||
public SevenZipExecutable(File file) throws Exception {
|
|
||||||
if (!file.exists()) {
|
|
||||||
throw new FileNotFoundException(file.getAbsolutePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
this.archive = file.getCanonicalFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String get7zCommand() {
|
|
||||||
// use 7z executable path as specified by the cmdline or default to "7z" and let the shell figure it out
|
|
||||||
return System.getProperty("net.filebot.Archive.7z", "7z");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected CharSequence execute(String... command) throws IOException {
|
|
||||||
Process process = new ProcessBuilder(command).redirectError(Redirect.INHERIT).start();
|
|
||||||
|
|
||||||
try (ByteBufferOutputStream bb = new ByteBufferOutputStream(8 * 1024)) {
|
|
||||||
bb.transferFully(process.getInputStream());
|
|
||||||
|
|
||||||
int returnCode = process.waitFor();
|
|
||||||
String output = UTF_8.decode(bb.getByteBuffer()).toString();
|
|
||||||
|
|
||||||
// DEBUG
|
|
||||||
debug.fine(format("Execute: %s", asList(command)));
|
|
||||||
debug.finest(output);
|
|
||||||
|
|
||||||
if (returnCode == 0) {
|
|
||||||
return output;
|
|
||||||
} else {
|
|
||||||
throw new IOException(String.format("%s failed with exit code %d: %s", get7zCommand(), returnCode, SPACE.matcher(output).replaceAll(" ").trim()));
|
|
||||||
}
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
throw new IOException(String.format("%s timed out", get7zCommand()), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<FileInfo> listFiles() throws IOException {
|
|
||||||
// e.g. 7z l -y archive.7z
|
|
||||||
CharSequence output = execute(get7zCommand(), "l", "-slt", "-y", archive.getPath());
|
|
||||||
|
|
||||||
List<FileInfo> paths = new ArrayList<FileInfo>();
|
|
||||||
|
|
||||||
String path = null;
|
|
||||||
long size = -1;
|
|
||||||
|
|
||||||
for (String line : NEWLINE.split(output)) {
|
|
||||||
int split = line.indexOf(" = ");
|
|
||||||
|
|
||||||
// ignore empty lines
|
|
||||||
if (split < 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String key = line.substring(0, split);
|
|
||||||
String value = line.substring(split + 3, line.length());
|
|
||||||
|
|
||||||
// ignore empty lines
|
|
||||||
if (key.isEmpty() || value.isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("Path".equals(key)) {
|
|
||||||
path = value;
|
|
||||||
} else if ("Size".equals(key)) {
|
|
||||||
size = Long.parseLong(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path != null && size >= 0) {
|
|
||||||
paths.add(new SimpleFileInfo(path, size));
|
|
||||||
|
|
||||||
path = null;
|
|
||||||
size = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return paths;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void extract(File outputDir) throws IOException {
|
|
||||||
// e.g. 7z x -y -aos archive.7z
|
|
||||||
execute(get7zCommand(), "x", "-y", "-aos", archive.getPath(), "-o" + outputDir.getCanonicalPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void extract(File outputDir, FileFilter filter) throws IOException {
|
|
||||||
// e.g. 7z x -y -aos archive.7z file.txt image.png info.nfo
|
|
||||||
Stream<String> command = Stream.of(get7zCommand(), "x", "-y", "-aos", archive.getPath(), "-o" + outputDir.getCanonicalPath());
|
|
||||||
Stream<String> selection = listFiles().stream().filter(f -> filter.accept(f.toFile())).map(f -> f.getPath());
|
|
||||||
|
|
||||||
execute(Stream.concat(command, selection).toArray(String[]::new));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,206 @@
|
||||||
|
package net.filebot.archive;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
|
import static java.util.Arrays.*;
|
||||||
|
import static java.util.stream.Collectors.*;
|
||||||
|
import static net.filebot.Logging.*;
|
||||||
|
import static net.filebot.util.RegularExpressions.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileFilter;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.ProcessBuilder.Redirect;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import net.filebot.util.ByteBufferOutputStream;
|
||||||
|
import net.filebot.util.FileUtilities.ExtensionFileFilter;
|
||||||
|
import net.filebot.vfs.FileInfo;
|
||||||
|
import net.filebot.vfs.SimpleFileInfo;
|
||||||
|
|
||||||
|
public class ShellExecutables implements ArchiveExtractor {
|
||||||
|
|
||||||
|
private Command command;
|
||||||
|
private File archive;
|
||||||
|
|
||||||
|
public ShellExecutables(File archive) throws Exception {
|
||||||
|
if (!archive.exists()) {
|
||||||
|
throw new FileNotFoundException(archive.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.command = getCommand(archive);
|
||||||
|
this.archive = archive;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<FileInfo> listFiles() throws IOException {
|
||||||
|
return command.listFiles(archive);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void extract(File outputFolder) throws IOException {
|
||||||
|
command.extract(archive, outputFolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void extract(File outputFolder, FileFilter filter) throws IOException {
|
||||||
|
command.extract(archive, outputFolder, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static Command getCommand(File archive) {
|
||||||
|
return RAR_FILES.accept(archive) ? Command.unrar : Command.p7zip;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static CharSequence execute(String... command) throws IOException {
|
||||||
|
Process process = new ProcessBuilder(command).redirectError(Redirect.INHERIT).start();
|
||||||
|
|
||||||
|
try (ByteBufferOutputStream bb = new ByteBufferOutputStream(8 * 1024)) {
|
||||||
|
bb.transferFully(process.getInputStream());
|
||||||
|
|
||||||
|
int returnCode = process.waitFor();
|
||||||
|
String output = UTF_8.decode(bb.getByteBuffer()).toString();
|
||||||
|
|
||||||
|
// DEBUG
|
||||||
|
debug.fine(format("Execute: %s", asList(command)));
|
||||||
|
debug.finest(output);
|
||||||
|
|
||||||
|
if (returnCode == 0) {
|
||||||
|
return output;
|
||||||
|
} else {
|
||||||
|
throw new IOException(String.format("%s failed with exit code %d: %s", asList(command), returnCode, SPACE.matcher(output).replaceAll(" ").trim()));
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new IOException(String.format("%s timed out", asList(command)), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Command {
|
||||||
|
|
||||||
|
p7zip {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return System.getProperty("net.filebot.archive.7z", "7z");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<FileInfo> listFiles(File archive) throws IOException {
|
||||||
|
CharSequence output = execute(getCommand(), "l", "-slt", "-y", archive.getPath());
|
||||||
|
|
||||||
|
List<FileInfo> paths = new ArrayList<FileInfo>();
|
||||||
|
|
||||||
|
String path = null;
|
||||||
|
long size = -1;
|
||||||
|
|
||||||
|
for (String line : NEWLINE.split(output)) {
|
||||||
|
int split = line.indexOf(" = ");
|
||||||
|
|
||||||
|
// ignore empty lines
|
||||||
|
if (split < 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String key = line.substring(0, split);
|
||||||
|
String value = line.substring(split + 3, line.length());
|
||||||
|
|
||||||
|
// ignore empty lines
|
||||||
|
if (key.isEmpty() || value.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("Path".equals(key)) {
|
||||||
|
path = value;
|
||||||
|
} else if ("Size".equals(key)) {
|
||||||
|
size = Long.parseLong(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path != null && size >= 0) {
|
||||||
|
paths.add(new SimpleFileInfo(path, size));
|
||||||
|
|
||||||
|
path = null;
|
||||||
|
size = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void extract(File archive, File outputFolder) throws IOException {
|
||||||
|
execute(getCommand(), "x", "-y", "-aos", archive.getPath(), "-o" + outputFolder.getCanonicalPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void extract(File archive, File outputFolder, FileFilter filter) throws IOException {
|
||||||
|
Stream<String> command = Stream.of(getCommand(), "x", "-y", "-aos", archive.getPath(), "-o" + outputFolder.getCanonicalPath());
|
||||||
|
Stream<String> selection = listFiles(archive).stream().filter(f -> filter.accept(f.toFile())).map(FileInfo::getPath);
|
||||||
|
|
||||||
|
execute(Stream.concat(command, selection).toArray(String[]::new));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String version() throws IOException {
|
||||||
|
CharSequence output = execute(getCommand());
|
||||||
|
|
||||||
|
return NEWLINE.splitAsStream(output).map(String::trim).filter(s -> s.startsWith("p7zip")).findFirst().get();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
unrar {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return System.getProperty("net.filebot.archive.unrar", "unrar");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<FileInfo> listFiles(File archive) throws IOException {
|
||||||
|
CharSequence output = execute(getCommand(), "l", "-y", archive.getPath());
|
||||||
|
|
||||||
|
return NEWLINE.splitAsStream(output).map(String::trim).map(l -> SPACE.split(l, 5)).filter(r -> {
|
||||||
|
return r.length == 5 && r[4].length() > 0 && DIGIT.matcher(r[1]).matches();
|
||||||
|
}).map(r -> {
|
||||||
|
return new SimpleFileInfo(r[4], Long.parseLong(r[1]));
|
||||||
|
}).collect(toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void extract(File archive, File outputFolder) throws IOException {
|
||||||
|
execute(getCommand(), "x", "-y", archive.getPath(), outputFolder.getCanonicalPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void extract(File archive, File outputFolder, FileFilter filter) throws IOException {
|
||||||
|
Stream<String> command = Stream.of(getCommand(), "x", "-y", archive.getPath());
|
||||||
|
Stream<String> selection = listFiles(archive).stream().filter(f -> filter.accept(f.toFile())).map(FileInfo::getPath);
|
||||||
|
Stream<String> output = Stream.of(outputFolder.getCanonicalPath());
|
||||||
|
|
||||||
|
execute(Stream.concat(command, Stream.concat(selection, output)).toArray(String[]::new));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String version() throws IOException {
|
||||||
|
CharSequence output = execute(getCommand());
|
||||||
|
|
||||||
|
return Pattern.compile("\\n|\\s\\s+").splitAsStream(output).map(String::trim).filter(s -> s.length() > 0).findFirst().get();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public abstract String getCommand();
|
||||||
|
|
||||||
|
public abstract List<FileInfo> listFiles(File archive) throws IOException;
|
||||||
|
|
||||||
|
public abstract void extract(File archive, File outputFolder) throws IOException;
|
||||||
|
|
||||||
|
public abstract void extract(File archive, File outputFolder, FileFilter filter) throws IOException;
|
||||||
|
|
||||||
|
public abstract String version() throws IOException;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final FileFilter RAR_FILES = new ExtensionFileFilter("rar", "r00");
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue