* extract only archives that contain at least one video file
This commit is contained in:
parent
87cfae4c76
commit
42ecf32100
|
@ -95,6 +95,27 @@ public class Archive implements Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void extract(ExtractOutProvider outputMapper, FileFilter filter) throws SevenZipException {
|
||||||
|
List<Integer> selection = new ArrayList<Integer>();
|
||||||
|
|
||||||
|
for (int i = 0; i < inArchive.getNumberOfItems(); i++) {
|
||||||
|
boolean isFolder = (Boolean) inArchive.getProperty(i, PropID.IS_FOLDER);
|
||||||
|
if (!isFolder) {
|
||||||
|
String path = (String) inArchive.getProperty(i, PropID.PATH);
|
||||||
|
if (path != null && filter.accept(new File(path))) {
|
||||||
|
selection.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int[] indices = new int[selection.size()];
|
||||||
|
for (int i = 0; i < indices.length; i++) {
|
||||||
|
indices[i] = selection.get(i);
|
||||||
|
}
|
||||||
|
inArchive.extract(indices, false, new ExtractCallback(inArchive, outputMapper));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
try {
|
try {
|
||||||
|
@ -121,7 +142,6 @@ public class Archive implements Closeable {
|
||||||
return extensions;
|
return extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final FileFilter VOLUME_ONE_FILTER = new FileFilter() {
|
public static final FileFilter VOLUME_ONE_FILTER = new FileFilter() {
|
||||||
|
|
||||||
private Pattern volume = Pattern.compile("[.]r[0-9]+$|[.]part[0-9]+|[.][0-9]+$", Pattern.CASE_INSENSITIVE);
|
private Pattern volume = Pattern.compile("[.]r[0-9]+$|[.]part[0-9]+|[.][0-9]+$", Pattern.CASE_INSENSITIVE);
|
||||||
|
|
|
@ -79,7 +79,7 @@ public class ArgumentProcessor {
|
||||||
Collection<File> files = new LinkedHashSet<File>(args.getFiles(true));
|
Collection<File> files = new LinkedHashSet<File>(args.getFiles(true));
|
||||||
|
|
||||||
if (args.extract) {
|
if (args.extract) {
|
||||||
files.addAll(cli.extract(files, args.output, args.conflict));
|
files.addAll(cli.extract(files, args.output, args.conflict, null, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.getSubtitles) {
|
if (args.getSubtitles) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package net.sourceforge.filebot.cli;
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileFilter;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -32,6 +33,6 @@ public interface CmdlineInterface {
|
||||||
String getMediaInfo(File file, String format) throws Exception;
|
String getMediaInfo(File file, String format) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
List<File> extract(Collection<File> files, String output, String conflict) throws Exception;
|
List<File> extract(Collection<File> files, String output, String conflict, FileFilter filter, boolean forceExtractAll) throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -980,7 +980,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<File> extract(Collection<File> files, String output, String conflict) throws Exception {
|
public List<File> extract(Collection<File> files, String output, String conflict, FileFilter filter, boolean forceExtractAll) throws Exception {
|
||||||
ConflictAction conflictAction = ConflictAction.forName(conflict);
|
ConflictAction conflictAction = ConflictAction.forName(conflict);
|
||||||
|
|
||||||
// only keep single-volume archives or first part of multi-volume archives
|
// only keep single-volume archives or first part of multi-volume archives
|
||||||
|
@ -995,22 +995,51 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
outputFolder = new File(file.getParentFile(), outputFolder.getPath());
|
outputFolder = new File(file.getParentFile(), outputFolder.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
CLILogger.info(String.format("Extract archive [%s] to [%s]", file.getName(), outputFolder));
|
CLILogger.info(String.format("Read archive [%s] to [%s]", file.getName(), outputFolder));
|
||||||
FileMapper outputMapper = new FileMapper(outputFolder, false);
|
FileMapper outputMapper = new FileMapper(outputFolder, false);
|
||||||
|
|
||||||
List<File> entries = archive.listFiles();
|
final List<File> outputMapping = new ArrayList<File>();
|
||||||
|
for (File entry : archive.listFiles()) {
|
||||||
|
outputMapping.add(outputMapper.getOutputFile(entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
final Set<File> selection = new TreeSet<File>();
|
||||||
|
for (File future : outputMapping) {
|
||||||
|
if (filter == null || filter.accept(future)) {
|
||||||
|
selection.add(future);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if there is anything to extract at all
|
||||||
|
if (selection.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
boolean skip = true;
|
boolean skip = true;
|
||||||
for (File entry : entries) {
|
for (File future : filter == null || forceExtractAll ? outputMapping : selection) {
|
||||||
File outputFile = outputMapper.getOutputFile(entry);
|
skip &= future.exists();
|
||||||
skip &= outputFile.exists();
|
|
||||||
extractedFiles.add(outputFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skip || conflictAction == ConflictAction.OVERRIDE) {
|
if (!skip || conflictAction == ConflictAction.OVERRIDE) {
|
||||||
CLILogger.finest("Extracting files " + entries);
|
if (filter == null || forceExtractAll) {
|
||||||
|
CLILogger.finest("Extracting files " + outputMapping);
|
||||||
|
// extract all files
|
||||||
archive.extract(outputMapper);
|
archive.extract(outputMapper);
|
||||||
|
extractedFiles.addAll(outputMapping);
|
||||||
} else {
|
} else {
|
||||||
CLILogger.finest("Skipped extracting files " + entries);
|
CLILogger.finest("Extracting files " + selection);
|
||||||
|
// extract files selected by the given filter
|
||||||
|
archive.extract(outputMapper, new FileFilter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accept(File entry) {
|
||||||
|
return selection.contains(entry);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
extractedFiles.addAll(selection);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
CLILogger.finest("Skipped extracting files " + selection);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
archive.close();
|
archive.close();
|
||||||
|
@ -1019,5 +1048,4 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
|
|
||||||
return extractedFiles;
|
return extractedFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,7 +264,7 @@ def compute(args) { args = _defaults(args)
|
||||||
|
|
||||||
def extract(args) { args = _defaults(args)
|
def extract(args) { args = _defaults(args)
|
||||||
synchronized (_cli) {
|
synchronized (_cli) {
|
||||||
_guarded { _cli.extract(_files(args), args.output as String, args.conflict as String) }
|
_guarded { _cli.extract(_files(args), args.output as String, args.conflict as String, args.filter instanceof Closure ? args.filter as FileFilter : null, args.forceExtractAll != null ? args.forceExtractAll : false) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,17 +319,10 @@ def _renameFunction(fn) {
|
||||||
* Fill in default values from cmdline arguments
|
* Fill in default values from cmdline arguments
|
||||||
*/
|
*/
|
||||||
def _defaults(args) {
|
def _defaults(args) {
|
||||||
args.action = args.action ?: _args.action
|
['action', 'conflict', 'query', 'filter', 'format', 'db', 'order', 'lang', 'output', 'encoding'].each{ k ->
|
||||||
args.conflict = args.conflict ?: _args.conflict
|
args[k] = args.containsKey(k) ? args[k] : _args[k]
|
||||||
args.query = args.query ?: _args.query
|
}
|
||||||
args.filter = args.filter ?: _args.filter
|
args.strict = args.strict != null ? args.strict : !_args.nonStrict // invert strict/non-strict
|
||||||
args.format = args.format ?: _args.format
|
|
||||||
args.db = args.db ?: _args.db
|
|
||||||
args.order = args.order ?: _args.order
|
|
||||||
args.lang = args.lang ?: _args.lang
|
|
||||||
args.output = args.output ?: _args.output
|
|
||||||
args.encoding = args.encoding ?: _args.encoding
|
|
||||||
args.strict = args.strict != null ? args.strict : !_args.nonStrict
|
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,11 +47,12 @@ if (args.empty) {
|
||||||
input += args.getFiles()
|
input += args.getFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract archives if necessary
|
|
||||||
input += extract(file:input, output:".", conflict:"override")
|
// extract archives (zip, rar, etc) that contain at least one video file
|
||||||
|
input += extract(file: input.findAll{ it.isArchive() }, output: null, conflict: 'override', filter: { it.isVideo() }, forceExtractAll: true)
|
||||||
|
|
||||||
// process only media files
|
// process only media files
|
||||||
input = input.findAll{ it.isVideo() || it.isSubtitle() }
|
input = input.unique().findAll{ it.isVideo() || it.isSubtitle() }
|
||||||
|
|
||||||
// ignore clutter files
|
// ignore clutter files
|
||||||
input = input.findAll{ !(it.path =~ /\b(?i:sample|trailer|extras|deleted.scenes|music.video|scrapbook)\b/) }
|
input = input.findAll{ !(it.path =~ /\b(?i:sample|trailer|extras|deleted.scenes|music.video|scrapbook)\b/) }
|
||||||
|
|
Loading…
Reference in New Issue