Added import archive #4
This commit is contained in:
@@ -18,6 +18,8 @@ import edu.cmu.sphinx.decoder.adaptation.*;
|
|||||||
import edu.cmu.sphinx.result.*;
|
import edu.cmu.sphinx.result.*;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.zip.*;
|
import java.util.zip.*;
|
||||||
|
import javax.swing.filechooser.*;
|
||||||
|
import javax.imageio.*;
|
||||||
|
|
||||||
public class AudiobookRecorder extends JFrame {
|
public class AudiobookRecorder extends JFrame {
|
||||||
|
|
||||||
@@ -35,6 +37,7 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
JMenuItem fileOpenBook;
|
JMenuItem fileOpenBook;
|
||||||
JMenuItem fileSave;
|
JMenuItem fileSave;
|
||||||
JMenuItem fileExit;
|
JMenuItem fileExit;
|
||||||
|
JMenuItem fileOpenArchive;
|
||||||
|
|
||||||
JMenuItem bookNewChapter;
|
JMenuItem bookNewChapter;
|
||||||
JMenuItem bookExportAudio;
|
JMenuItem bookExportAudio;
|
||||||
@@ -137,6 +140,13 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
fileOpenArchive = new JMenuItem("Open Archive...");
|
||||||
|
fileOpenArchive.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
openArchive();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
fileExit = new JMenuItem("Exit");
|
fileExit = new JMenuItem("Exit");
|
||||||
fileExit.addActionListener(new ActionListener() {
|
fileExit.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
@@ -149,6 +159,8 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
fileMenu.add(fileOpenBook);
|
fileMenu.add(fileOpenBook);
|
||||||
fileMenu.add(fileSave);
|
fileMenu.add(fileSave);
|
||||||
fileMenu.addSeparator();
|
fileMenu.addSeparator();
|
||||||
|
fileMenu.add(fileOpenArchive);
|
||||||
|
fileMenu.addSeparator();
|
||||||
fileMenu.add(fileExit);
|
fileMenu.add(fileExit);
|
||||||
|
|
||||||
menuBar.add(fileMenu);
|
menuBar.add(fileMenu);
|
||||||
@@ -2070,6 +2082,7 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
zos.closeEntry();
|
zos.closeEntry();
|
||||||
} else {
|
} else {
|
||||||
ZipEntry entry = new ZipEntry(path);
|
ZipEntry entry = new ZipEntry(path);
|
||||||
|
entry.setSize(f.length());
|
||||||
entry.setTime(f.lastModified());
|
entry.setTime(f.lastModified());
|
||||||
zos.putNextEntry(entry);
|
zos.putNextEntry(entry);
|
||||||
|
|
||||||
@@ -2114,4 +2127,79 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
mainScroll.setViewportView(null);
|
mainScroll.setViewportView(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void openArchive() {
|
||||||
|
JFileChooser jc = new JFileChooser(new File(Options.get("path.storage"), "archive"));
|
||||||
|
FileNameExtensionFilter filter = new FileNameExtensionFilter("Audiobook Archives", "abz");
|
||||||
|
jc.addChoosableFileFilter(filter);
|
||||||
|
jc.setFileFilter(filter);
|
||||||
|
jc.setDialogTitle("Select Audiobook Archive");
|
||||||
|
int r = jc.showOpenDialog(this);
|
||||||
|
|
||||||
|
if (r == JFileChooser.APPROVE_OPTION) {
|
||||||
|
File f = jc.getSelectedFile();
|
||||||
|
if (f.exists()) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
ZipInputStream zis = new ZipInputStream(new FileInputStream(f)) {
|
||||||
|
public void close() throws IOException {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ZipEntry entry = null;
|
||||||
|
ImageIcon cover = null;
|
||||||
|
Properties props = new Properties();
|
||||||
|
|
||||||
|
boolean gotMeta = false;
|
||||||
|
boolean gotCover = false;
|
||||||
|
|
||||||
|
while ((entry = zis.getNextEntry()) != null) {
|
||||||
|
if (gotMeta && gotCover) break;
|
||||||
|
|
||||||
|
if (entry.getName().endsWith("/audiobook.abk")) {
|
||||||
|
props.loadFromXML(zis);
|
||||||
|
gotMeta = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
entry.getName().endsWith("/coverart.png") ||
|
||||||
|
entry.getName().endsWith("/coverart.jpg") ||
|
||||||
|
entry.getName().endsWith("/coverart.gif")
|
||||||
|
) {
|
||||||
|
cover = new ImageIcon(ImageIO.read(zis));
|
||||||
|
gotCover = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zis.close();
|
||||||
|
|
||||||
|
BookPanel pan = new BookPanel(props, cover);
|
||||||
|
int okToImport = JOptionPane.showConfirmDialog(this, pan, "Import this book?", JOptionPane.OK_CANCEL_OPTION);
|
||||||
|
if (okToImport == JOptionPane.OK_OPTION) {
|
||||||
|
zis = new ZipInputStream(new FileInputStream(f));
|
||||||
|
while ((entry = zis.getNextEntry()) != null) {
|
||||||
|
File out = new File(Options.get("path.storage"), entry.getName());
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
out.mkdirs();
|
||||||
|
} else {
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int nr;
|
||||||
|
FileOutputStream fos = new FileOutputStream(out);
|
||||||
|
while ((nr = zis.read(buffer, 0, 1024)) > 0) {
|
||||||
|
fos.write(buffer, 0, nr);
|
||||||
|
}
|
||||||
|
fos.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zis.close();
|
||||||
|
|
||||||
|
File bookdir = new File(Options.get("path.storage"), props.getProperty("book.name"));
|
||||||
|
File conf = new File(bookdir, "audiobook.abk");
|
||||||
|
loadBookStructure(conf);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,15 +28,28 @@ public class BookPanel extends JPanel {
|
|||||||
|
|
||||||
boolean highlight = false;
|
boolean highlight = false;
|
||||||
|
|
||||||
|
public BookPanel(Properties p, ImageIcon i) {
|
||||||
|
loadBookData(p, i);
|
||||||
|
}
|
||||||
|
|
||||||
public BookPanel(File r) {
|
public BookPanel(File r) {
|
||||||
try {
|
try {
|
||||||
root = r;
|
root = r;
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.loadFromXML(new FileInputStream(new File(root, "audiobook.abk")));
|
props.loadFromXML(new FileInputStream(new File(root, "audiobook.abk")));
|
||||||
|
loadBookData(props, null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadBookData(Properties props, ImageIcon i) {
|
||||||
|
try {
|
||||||
name = props.getProperty("book.name");
|
name = props.getProperty("book.name");
|
||||||
author = props.getProperty("book.author");
|
author = props.getProperty("book.author");
|
||||||
genre = props.getProperty("book.genre");
|
genre = props.getProperty("book.genre");
|
||||||
comment = props.getProperty("book.comment");
|
comment = props.getProperty("book.comment");
|
||||||
|
if (i == null) {
|
||||||
File icon = new File(root, "coverart.png");
|
File icon = new File(root, "coverart.png");
|
||||||
if (!icon.exists()) {
|
if (!icon.exists()) {
|
||||||
icon = new File(root, "coverart.jpg");
|
icon = new File(root, "coverart.jpg");
|
||||||
@@ -53,6 +66,11 @@ public class BookPanel extends JPanel {
|
|||||||
resizedCover = null;
|
resizedCover = null;
|
||||||
iconLabel = new JLabel("");
|
iconLabel = new JLabel("");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
cover = i;
|
||||||
|
resizedCover = Utils.getScaledImage(cover.getImage(), 75, 75);
|
||||||
|
iconLabel = new JLabel(new ImageIcon(resizedCover));
|
||||||
|
}
|
||||||
|
|
||||||
iconLabel.setSize(new Dimension(75, 75));
|
iconLabel.setSize(new Dimension(75, 75));
|
||||||
iconLabel.setPreferredSize(new Dimension(75, 75));
|
iconLabel.setPreferredSize(new Dimension(75, 75));
|
||||||
|
|||||||
Reference in New Issue
Block a user