* Extract API changes to include FileSize
This commit is contained in:
parent
dea0a1fb83
commit
66a6278611
|
@ -1,7 +1,5 @@
|
||||||
|
|
||||||
package net.sourceforge.filebot.archive;
|
package net.sourceforge.filebot.archive;
|
||||||
|
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
|
@ -23,15 +21,15 @@ import net.sf.sevenzipjbinding.ISevenZipInArchive;
|
||||||
import net.sf.sevenzipjbinding.PropID;
|
import net.sf.sevenzipjbinding.PropID;
|
||||||
import net.sf.sevenzipjbinding.SevenZipException;
|
import net.sf.sevenzipjbinding.SevenZipException;
|
||||||
import net.sourceforge.filebot.MediaTypes;
|
import net.sourceforge.filebot.MediaTypes;
|
||||||
|
import net.sourceforge.filebot.vfs.FileInfo;
|
||||||
|
import net.sourceforge.filebot.vfs.SimpleFileInfo;
|
||||||
import net.sourceforge.tuned.FileUtilities.ExtensionFileFilter;
|
import net.sourceforge.tuned.FileUtilities.ExtensionFileFilter;
|
||||||
|
|
||||||
|
|
||||||
public class Archive implements Closeable {
|
public class Archive implements Closeable {
|
||||||
|
|
||||||
private ISevenZipInArchive inArchive;
|
private ISevenZipInArchive inArchive;
|
||||||
private ArchiveOpenVolumeCallback openVolume;
|
private ArchiveOpenVolumeCallback openVolume;
|
||||||
|
|
||||||
|
|
||||||
public Archive(File file) throws Exception {
|
public Archive(File file) throws Exception {
|
||||||
// initialize 7-Zip-JBinding
|
// initialize 7-Zip-JBinding
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
|
@ -52,12 +50,10 @@ public class Archive implements Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int itemCount() throws SevenZipException {
|
public int itemCount() throws SevenZipException {
|
||||||
return inArchive.getNumberOfItems();
|
return inArchive.getNumberOfItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<PropID, Object> getItem(int index) throws SevenZipException {
|
public Map<PropID, Object> getItem(int index) throws SevenZipException {
|
||||||
Map<PropID, Object> item = new EnumMap<PropID, Object>(PropID.class);
|
Map<PropID, Object> item = new EnumMap<PropID, Object>(PropID.class);
|
||||||
|
|
||||||
|
@ -71,16 +67,16 @@ public class Archive implements Closeable {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<FileInfo> listFiles() throws SevenZipException {
|
||||||
public List<File> listFiles() throws SevenZipException {
|
List<FileInfo> paths = new ArrayList<FileInfo>();
|
||||||
List<File> paths = new ArrayList<File>();
|
|
||||||
|
|
||||||
for (int i = 0; i < inArchive.getNumberOfItems(); i++) {
|
for (int i = 0; i < inArchive.getNumberOfItems(); i++) {
|
||||||
boolean isFolder = (Boolean) inArchive.getProperty(i, PropID.IS_FOLDER);
|
boolean isFolder = (Boolean) inArchive.getProperty(i, PropID.IS_FOLDER);
|
||||||
if (!isFolder) {
|
if (!isFolder) {
|
||||||
String path = (String) inArchive.getProperty(i, PropID.PATH);
|
String path = (String) inArchive.getProperty(i, PropID.PATH);
|
||||||
|
Long length = (Long) inArchive.getProperty(i, PropID.SIZE);
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
paths.add(new File(path));
|
paths.add(new SimpleFileInfo(path, length != null ? length : -1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,12 +84,10 @@ public class Archive implements Closeable {
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void extract(ExtractOutProvider outputMapper) throws SevenZipException {
|
public void extract(ExtractOutProvider outputMapper) throws SevenZipException {
|
||||||
inArchive.extract(null, false, new ExtractCallback(inArchive, outputMapper));
|
inArchive.extract(null, false, new ExtractCallback(inArchive, outputMapper));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void extract(ExtractOutProvider outputMapper, FileFilter filter) throws SevenZipException {
|
public void extract(ExtractOutProvider outputMapper, FileFilter filter) throws SevenZipException {
|
||||||
List<Integer> selection = new ArrayList<Integer>();
|
List<Integer> selection = new ArrayList<Integer>();
|
||||||
|
|
||||||
|
@ -114,7 +108,6 @@ public class Archive implements Closeable {
|
||||||
inArchive.extract(indices, false, new ExtractCallback(inArchive, outputMapper));
|
inArchive.extract(indices, false, new ExtractCallback(inArchive, outputMapper));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
try {
|
try {
|
||||||
|
@ -126,7 +119,6 @@ public class Archive implements Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Set<String> getArchiveTypes() {
|
public static Set<String> getArchiveTypes() {
|
||||||
Set<String> extensions = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
Set<String> extensions = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||||
|
|
||||||
|
@ -143,7 +135,6 @@ public class Archive implements Closeable {
|
||||||
|
|
||||||
private static final Pattern multiPartIndex = Pattern.compile("[.][0-9]{3}+$");
|
private static final Pattern multiPartIndex = Pattern.compile("[.][0-9]{3}+$");
|
||||||
|
|
||||||
|
|
||||||
public static boolean hasMultiPartIndex(File file) {
|
public static boolean hasMultiPartIndex(File file) {
|
||||||
return multiPartIndex.matcher(file.getName()).find();
|
return multiPartIndex.matcher(file.getName()).find();
|
||||||
}
|
}
|
||||||
|
@ -153,7 +144,6 @@ public class Archive implements Closeable {
|
||||||
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);
|
||||||
private FileFilter archives = new ExtensionFileFilter(getArchiveTypes());
|
private FileFilter archives = new ExtensionFileFilter(getArchiveTypes());
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File path) {
|
public boolean accept(File path) {
|
||||||
if (!archives.accept(path) && !hasMultiPartIndex(path)) {
|
if (!archives.accept(path) && !hasMultiPartIndex(path)) {
|
||||||
|
|
|
@ -58,6 +58,7 @@ import net.sourceforge.filebot.similarity.SimilarityComparator;
|
||||||
import net.sourceforge.filebot.similarity.SimilarityMetric;
|
import net.sourceforge.filebot.similarity.SimilarityMetric;
|
||||||
import net.sourceforge.filebot.subtitle.SubtitleFormat;
|
import net.sourceforge.filebot.subtitle.SubtitleFormat;
|
||||||
import net.sourceforge.filebot.subtitle.SubtitleNaming;
|
import net.sourceforge.filebot.subtitle.SubtitleNaming;
|
||||||
|
import net.sourceforge.filebot.vfs.FileInfo;
|
||||||
import net.sourceforge.filebot.vfs.MemoryFile;
|
import net.sourceforge.filebot.vfs.MemoryFile;
|
||||||
import net.sourceforge.filebot.web.AudioTrack;
|
import net.sourceforge.filebot.web.AudioTrack;
|
||||||
import net.sourceforge.filebot.web.Episode;
|
import net.sourceforge.filebot.web.Episode;
|
||||||
|
@ -1085,8 +1086,8 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
final FileMapper outputMapper = new FileMapper(outputFolder, false);
|
final FileMapper outputMapper = new FileMapper(outputFolder, false);
|
||||||
|
|
||||||
final List<File> outputMapping = new ArrayList<File>();
|
final List<File> outputMapping = new ArrayList<File>();
|
||||||
for (File entry : archive.listFiles()) {
|
for (FileInfo entry : archive.listFiles()) {
|
||||||
outputMapping.add(outputMapper.getOutputFile(entry));
|
outputMapping.add(outputMapper.getOutputFile(new File(entry.getPath())));
|
||||||
}
|
}
|
||||||
|
|
||||||
final Set<File> selection = new TreeSet<File>();
|
final Set<File> selection = new TreeSet<File>();
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
|
|
||||||
package net.sourceforge.filebot.cli;
|
package net.sourceforge.filebot.cli;
|
||||||
|
|
||||||
|
|
||||||
public enum ConflictAction {
|
public enum ConflictAction {
|
||||||
|
|
||||||
OVERRIDE,
|
SKIP, OVERRIDE, FAIL, AUTO;
|
||||||
SKIP,
|
|
||||||
FAIL;
|
|
||||||
|
|
||||||
public static ConflictAction forName(String action) {
|
public static ConflictAction forName(String action) {
|
||||||
for (ConflictAction it : values()) {
|
for (ConflictAction it : values()) {
|
||||||
|
|
|
@ -53,6 +53,7 @@ import net.sourceforge.filebot.similarity.SequenceMatchSimilarity;
|
||||||
import net.sourceforge.filebot.similarity.SeriesNameMatcher;
|
import net.sourceforge.filebot.similarity.SeriesNameMatcher;
|
||||||
import net.sourceforge.filebot.similarity.SimilarityComparator;
|
import net.sourceforge.filebot.similarity.SimilarityComparator;
|
||||||
import net.sourceforge.filebot.similarity.SimilarityMetric;
|
import net.sourceforge.filebot.similarity.SimilarityMetric;
|
||||||
|
import net.sourceforge.filebot.vfs.FileInfo;
|
||||||
import net.sourceforge.filebot.web.Date;
|
import net.sourceforge.filebot.web.Date;
|
||||||
import net.sourceforge.filebot.web.Episode;
|
import net.sourceforge.filebot.web.Episode;
|
||||||
import net.sourceforge.filebot.web.Movie;
|
import net.sourceforge.filebot.web.Movie;
|
||||||
|
@ -95,8 +96,8 @@ public class MediaDetection {
|
||||||
FileFilter diskFolderEntryFilter = releaseInfo.getDiskFolderEntryFilter();
|
FileFilter diskFolderEntryFilter = releaseInfo.getDiskFolderEntryFilter();
|
||||||
Archive iso = new Archive(file);
|
Archive iso = new Archive(file);
|
||||||
try {
|
try {
|
||||||
for (File path : iso.listFiles()) {
|
for (FileInfo it : iso.listFiles()) {
|
||||||
for (File entry : listPath(path)) {
|
for (File entry : listPath(new File(it.getPath()))) {
|
||||||
if (diskFolderEntryFilter.accept(entry)) {
|
if (diskFolderEntryFilter.accept(entry)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
|
|
||||||
package net.sourceforge.filebot.ui.analyze;
|
package net.sourceforge.filebot.ui.analyze;
|
||||||
|
|
||||||
|
|
||||||
import static net.sourceforge.filebot.ui.NotificationLogging.*;
|
import static net.sourceforge.filebot.ui.NotificationLogging.*;
|
||||||
import static net.sourceforge.tuned.ExceptionUtilities.*;
|
import static net.sourceforge.tuned.ExceptionUtilities.*;
|
||||||
import static net.sourceforge.tuned.FileUtilities.*;
|
import static net.sourceforge.tuned.FileUtilities.*;
|
||||||
|
@ -38,6 +36,8 @@ import net.sourceforge.filebot.ResourceManager;
|
||||||
import net.sourceforge.filebot.archive.Archive;
|
import net.sourceforge.filebot.archive.Archive;
|
||||||
import net.sourceforge.filebot.archive.FileMapper;
|
import net.sourceforge.filebot.archive.FileMapper;
|
||||||
import net.sourceforge.filebot.ui.analyze.FileTree.FolderNode;
|
import net.sourceforge.filebot.ui.analyze.FileTree.FolderNode;
|
||||||
|
import net.sourceforge.filebot.vfs.FileInfo;
|
||||||
|
import net.sourceforge.tuned.FileUtilities;
|
||||||
import net.sourceforge.tuned.ui.GradientStyle;
|
import net.sourceforge.tuned.ui.GradientStyle;
|
||||||
import net.sourceforge.tuned.ui.LoadingOverlayPane;
|
import net.sourceforge.tuned.ui.LoadingOverlayPane;
|
||||||
import net.sourceforge.tuned.ui.ProgressDialog;
|
import net.sourceforge.tuned.ui.ProgressDialog;
|
||||||
|
@ -45,12 +45,10 @@ import net.sourceforge.tuned.ui.ProgressDialog.Cancellable;
|
||||||
import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter;
|
import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter;
|
||||||
import net.sourceforge.tuned.ui.notification.SeparatorBorder;
|
import net.sourceforge.tuned.ui.notification.SeparatorBorder;
|
||||||
|
|
||||||
|
|
||||||
class ExtractTool extends Tool<TableModel> {
|
class ExtractTool extends Tool<TableModel> {
|
||||||
|
|
||||||
private JTable table = new JTable(new ArchiveEntryModel());
|
private JTable table = new JTable(new ArchiveEntryModel());
|
||||||
|
|
||||||
|
|
||||||
public ExtractTool() {
|
public ExtractTool() {
|
||||||
super("Archives");
|
super("Archives");
|
||||||
|
|
||||||
|
@ -69,13 +67,11 @@ class ExtractTool extends Tool<TableModel> {
|
||||||
add(new JButton(extractAction), "gap top rel, gap bottom unrel");
|
add(new JButton(extractAction), "gap top rel, gap bottom unrel");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setModel(TableModel model) {
|
protected void setModel(TableModel model) {
|
||||||
table.setModel(model);
|
table.setModel(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TableModel createModelInBackground(FolderNode sourceModel) throws InterruptedException {
|
protected TableModel createModelInBackground(FolderNode sourceModel) throws InterruptedException {
|
||||||
List<ArchiveEntry> entries = new ArrayList<ArchiveEntry>();
|
List<ArchiveEntry> entries = new ArrayList<ArchiveEntry>();
|
||||||
|
@ -88,7 +84,7 @@ class ExtractTool extends Tool<TableModel> {
|
||||||
if (Archive.VOLUME_ONE_FILTER.accept(file)) {
|
if (Archive.VOLUME_ONE_FILTER.accept(file)) {
|
||||||
Archive archive = new Archive(file);
|
Archive archive = new Archive(file);
|
||||||
try {
|
try {
|
||||||
for (File it : archive.listFiles()) {
|
for (FileInfo it : archive.listFiles()) {
|
||||||
entries.add(new ArchiveEntry(file, it));
|
entries.add(new ArchiveEntry(file, it));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -112,7 +108,6 @@ class ExtractTool extends Tool<TableModel> {
|
||||||
return new ArchiveEntryModel(entries);
|
return new ArchiveEntryModel(entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Action extractAction = new AbstractAction("Extract All", ResourceManager.getIcon("package.extract")) {
|
private Action extractAction = new AbstractAction("Extract All", ResourceManager.getIcon("package.extract")) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -150,7 +145,6 @@ class ExtractTool extends Tool<TableModel> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void done(PropertyChangeEvent evt) {
|
protected void done(PropertyChangeEvent evt) {
|
||||||
dialog.close();
|
dialog.close();
|
||||||
|
@ -162,35 +156,29 @@ class ExtractTool extends Tool<TableModel> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
private static class ArchiveEntry {
|
private static class ArchiveEntry {
|
||||||
|
|
||||||
public final File archive;
|
public final File archive;
|
||||||
public final File entry;
|
public final FileInfo entry;
|
||||||
|
|
||||||
|
public ArchiveEntry(File archive, FileInfo entry) {
|
||||||
public ArchiveEntry(File archive, File entry) {
|
|
||||||
this.archive = archive;
|
this.archive = archive;
|
||||||
this.entry = entry;
|
this.entry = entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class ArchiveEntryModel extends AbstractTableModel {
|
private static class ArchiveEntryModel extends AbstractTableModel {
|
||||||
|
|
||||||
private final ArchiveEntry[] data;
|
private final ArchiveEntry[] data;
|
||||||
|
|
||||||
|
|
||||||
public ArchiveEntryModel() {
|
public ArchiveEntryModel() {
|
||||||
this.data = new ArchiveEntry[0];
|
this.data = new ArchiveEntry[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ArchiveEntryModel(Collection<ArchiveEntry> data) {
|
public ArchiveEntryModel(Collection<ArchiveEntry> data) {
|
||||||
this.data = data.toArray(new ArchiveEntry[data.size()]);
|
this.data = data.toArray(new ArchiveEntry[data.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<File> getArchiveList() {
|
public List<File> getArchiveList() {
|
||||||
Set<File> archives = new LinkedHashSet<File>();
|
Set<File> archives = new LinkedHashSet<File>();
|
||||||
for (ArchiveEntry it : data) {
|
for (ArchiveEntry it : data) {
|
||||||
|
@ -199,19 +187,16 @@ class ExtractTool extends Tool<TableModel> {
|
||||||
return new ArrayList<File>(archives);
|
return new ArrayList<File>(archives);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRowCount() {
|
public int getRowCount() {
|
||||||
return data.length;
|
return data.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getColumnCount() {
|
public int getColumnCount() {
|
||||||
return 2;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getColumnName(int column) {
|
public String getColumnName(int column) {
|
||||||
switch (column) {
|
switch (column) {
|
||||||
|
@ -219,11 +204,12 @@ class ExtractTool extends Tool<TableModel> {
|
||||||
return "File";
|
return "File";
|
||||||
case 1:
|
case 1:
|
||||||
return "Path";
|
return "Path";
|
||||||
|
case 2:
|
||||||
|
return "Size";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getValueAt(int row, int column) {
|
public Object getValueAt(int row, int column) {
|
||||||
switch (column) {
|
switch (column) {
|
||||||
|
@ -231,28 +217,28 @@ class ExtractTool extends Tool<TableModel> {
|
||||||
return data[row].entry.getName();
|
return data[row].entry.getName();
|
||||||
case 1:
|
case 1:
|
||||||
File root = new File(data[row].archive.getName());
|
File root = new File(data[row].archive.getName());
|
||||||
File prefix = data[row].entry.getParentFile();
|
File prefix = new File(data[row].entry.getPath()).getParentFile();
|
||||||
File path = (prefix == null) ? root : new File(root, prefix.getPath());
|
File path = (prefix == null) ? root : new File(root, prefix.getPath());
|
||||||
return normalizePathSeparators(path.getPath());
|
return normalizePathSeparators(path.getPath());
|
||||||
|
case 2:
|
||||||
|
return FileUtilities.formatSize(data[row].entry.getLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static class ExtractJob extends SwingWorker<Void, Void> implements Cancellable {
|
protected static class ExtractJob extends SwingWorker<Void, Void> implements Cancellable {
|
||||||
|
|
||||||
private final File[] archives;
|
private final File[] archives;
|
||||||
private final File outputRoot;
|
private final File outputRoot;
|
||||||
|
|
||||||
|
|
||||||
public ExtractJob(Collection<File> archives, File outputRoot) {
|
public ExtractJob(Collection<File> archives, File outputRoot) {
|
||||||
this.archives = archives.toArray(new File[archives.size()]);
|
this.archives = archives.toArray(new File[archives.size()]);
|
||||||
this.outputRoot = outputRoot;
|
this.outputRoot = outputRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground() throws Exception {
|
protected Void doInBackground() throws Exception {
|
||||||
for (File it : archives) {
|
for (File it : archives) {
|
||||||
|
@ -279,7 +265,6 @@ class ExtractTool extends Tool<TableModel> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean cancel() {
|
public boolean cancel() {
|
||||||
return cancel(true);
|
return cancel(true);
|
||||||
|
|
Loading…
Reference in New Issue