From 7431550d61a4b46f58b155c44a591c468626f532 Mon Sep 17 00:00:00 2001 From: Matt Jenkins Date: Sat, 6 Oct 2018 20:47:22 +0100 Subject: [PATCH] Added ACX website connections --- .../audiobookrecorder/AudiobookRecorder.java | 36 ++++++++++- src/uk/co/majenko/audiobookrecorder/Book.java | 31 +++------- .../audiobookrecorder/BookInfoPanel.java | 59 ++++++++++--------- .../audiobookrecorder/DonationPanel.java | 7 +-- .../co/majenko/audiobookrecorder/Utils.java | 9 +++ 5 files changed, 84 insertions(+), 58 deletions(-) diff --git a/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java b/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java index 5c12d22..c5fde4f 100644 --- a/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java +++ b/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java @@ -41,6 +41,10 @@ public class AudiobookRecorder extends JFrame { JMenuItem bookNewChapter; JMenuItem bookExportAudio; + JMenu bookVisitACX; + JMenuItem bookVisitTitle; + JMenuItem bookVisitAudition; + JMenuItem bookVisitProduce; JMenuItem toolsMerge; JMenuItem toolsArchive; @@ -184,6 +188,33 @@ public class AudiobookRecorder extends JFrame { bookMenu.add(bookNewChapter); bookMenu.add(bookExportAudio); + bookVisitACX = new JMenu("Visit ACX"); + bookMenu.add(bookVisitACX); + + bookVisitTitle = new JMenuItem("Title"); + bookVisitTitle.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Utils.browse("https://www.acx.com/titleview/" + book.getACX()); + } + }); + bookVisitACX.add(bookVisitTitle); + + bookVisitAudition = new JMenuItem("Audition"); + bookVisitAudition.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Utils.browse("https://www.acx.com/titleview/" + book.getACX() + "?bucket=AUDITION_READY"); + } + }); + bookVisitACX.add(bookVisitAudition); + + bookVisitProduce = new JMenuItem("Produce"); + bookVisitProduce.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Utils.browse("https://www.acx.com/titleview/" + book.getACX() + "?bucket=PRODUCE"); + } + }); + bookVisitACX.add(bookVisitProduce); + menuBar.add(bookMenu); toolsMenu = new JMenu("Tools"); @@ -589,7 +620,7 @@ public class AudiobookRecorder extends JFrame { } public void createNewBook() { - BookInfoPanel info = new BookInfoPanel("", "", "", ""); + BookInfoPanel info = new BookInfoPanel("", "", "", "", ""); int r = JOptionPane.showConfirmDialog(this, info, "New Book", JOptionPane.OK_CANCEL_OPTION); if (r != JOptionPane.OK_OPTION) return; @@ -608,6 +639,7 @@ public class AudiobookRecorder extends JFrame { prefs.setProperty("book.author", info.getAuthor()); prefs.setProperty("book.genre", info.getGenre()); prefs.setProperty("book.comment", info.getComment()); + prefs.setProperty("book.acx", info.getACX()); prefs.setProperty("chapter.audition.name", "Audition"); prefs.setProperty("chapter.audition.pre-gap", Options.get("catenation.pre-chapter")); prefs.setProperty("chapter.audition.post-gap", Options.get("catenation.post-chapter")); @@ -1282,6 +1314,7 @@ public class AudiobookRecorder extends JFrame { prefs.setProperty("book.author", book.getAuthor()); prefs.setProperty("book.genre", book.getGenre()); prefs.setProperty("book.comment", book.getComment()); + prefs.setProperty("book.acx", book.getACX()); prefs.setProperty("audio.recording.samplerate", "" + book.getSampleRate()); prefs.setProperty("audio.recording.resolution", "" + book.getResolution()); @@ -1363,6 +1396,7 @@ public class AudiobookRecorder extends JFrame { book.setAuthor(prefs.getProperty("book.author")); book.setGenre(prefs.getProperty("book.genre")); book.setComment(prefs.getProperty("book.comment")); + book.setACX(prefs.getProperty("book.acx")); int sr = Utils.s2i(prefs.getProperty("audio.recording.samplerate")); if (sr == 0) { diff --git a/src/uk/co/majenko/audiobookrecorder/Book.java b/src/uk/co/majenko/audiobookrecorder/Book.java index e97d0fb..280743d 100644 --- a/src/uk/co/majenko/audiobookrecorder/Book.java +++ b/src/uk/co/majenko/audiobookrecorder/Book.java @@ -17,6 +17,7 @@ public class Book extends DefaultMutableTreeNode { String author; String genre; String comment; + String ACX; int sampleRate; int channels; @@ -35,29 +36,15 @@ public class Book extends DefaultMutableTreeNode { AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name); } - public void setAuthor(String a) { - author = a; - } + public void setAuthor(String a) { author = a; } + public void setGenre(String g) { genre = g; } + public void setComment(String c) { comment = c; } + public void setACX(String c) { ACX = c; } - public void setGenre(String g) { - genre = g; - } - - public void setComment(String c) { - comment = c; - } - - public String getAuthor() { - return author; - } - - public String getGenre() { - return genre; - } - - public String getComment() { - return comment; - } + public String getAuthor() { return author; } + public String getGenre() { return genre; } + public String getComment() { return comment; } + public String getACX() { return ACX; } public Chapter getClosingCredits() { return getChapterById("close"); diff --git a/src/uk/co/majenko/audiobookrecorder/BookInfoPanel.java b/src/uk/co/majenko/audiobookrecorder/BookInfoPanel.java index 6030595..753ef07 100644 --- a/src/uk/co/majenko/audiobookrecorder/BookInfoPanel.java +++ b/src/uk/co/majenko/audiobookrecorder/BookInfoPanel.java @@ -4,6 +4,7 @@ import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; +import java.util.regex.*; public class BookInfoPanel extends JPanel { @@ -11,8 +12,9 @@ public class BookInfoPanel extends JPanel { JTextField author; JTextField genre; JTextField comment; + JTextField acx; - public BookInfoPanel(String t, String a, String g, String c) { + public BookInfoPanel(String t, String a, String g, String c, String x) { super(); setLayout(new GridBagLayout()); GridBagConstraints con = new GridBagConstraints(); @@ -56,37 +58,36 @@ public class BookInfoPanel extends JPanel { con.gridx = 0; con.gridy++; + add(new JLabel("AXC Code:"), con); + con.gridx = 1; + acx = new JTextField(x); + acx.setPreferredSize(new Dimension(200, 20)); + add(acx, con); + + con.gridx = 0; + con.gridy++; + } - public String getTitle() { - return title.getText(); + public String getTitle() { return title.getText(); } + public String getAuthor() { return author.getText(); } + public String getGenre() { return genre.getText(); } + public String getComment() { return comment.getText(); } + + public String getACX() { + Pattern p = Pattern.compile("\\/titleview\\/([A-Z0-9]{14})"); + Matcher m = p.matcher(acx.getText()); + if (m.find()) { + System.err.println(m); + return m.group(1); + } + return acx.getText(); } - public String getAuthor() { - return author.getText(); - } + public void setTitle(String t) { title.setText(t); } + public void setAuthor(String a) { author.setText(a); } + public void setGenre(String g) { genre.setText(g); } + public void setComment(String c) { comment.setText(c); } + public void setACX(String a) { acx.setText(a); } - public String getGenre() { - return genre.getText(); - } - - public String getComment() { - return comment.getText(); - } - - public void setTitle(String t) { - title.setText(t); - } - - public void setAuthor(String a) { - author.setText(a); - } - - public void setGenre(String g) { - genre.setText(g); - } - - public void setComment(String c) { - comment.setText(c); - } } diff --git a/src/uk/co/majenko/audiobookrecorder/DonationPanel.java b/src/uk/co/majenko/audiobookrecorder/DonationPanel.java index 6a47dee..d120dc1 100644 --- a/src/uk/co/majenko/audiobookrecorder/DonationPanel.java +++ b/src/uk/co/majenko/audiobookrecorder/DonationPanel.java @@ -40,12 +40,7 @@ public class DonationPanel extends JPanel { JButton donate = new JButton("Donate!"); donate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - if (Desktop.isDesktopSupported()) { - try { - Desktop.getDesktop().browse(new URI("https://paypal.me/majenko")); - } catch (Exception ex) { - } - } + Utils.browse("https://paypal.me/majenko"); } }); diff --git a/src/uk/co/majenko/audiobookrecorder/Utils.java b/src/uk/co/majenko/audiobookrecorder/Utils.java index c38b3ef..758f9d6 100644 --- a/src/uk/co/majenko/audiobookrecorder/Utils.java +++ b/src/uk/co/majenko/audiobookrecorder/Utils.java @@ -8,6 +8,7 @@ import java.awt.image.*; import javax.swing.border.*; import java.util.*; import java.io.*; +import java.net.*; public class Utils { public static Image getScaledImage(Image srcImg, int w, int h){ @@ -46,4 +47,12 @@ public class Utils { return 0.0f; } + public static void browse(String url) { + if (Desktop.isDesktopSupported()) { + try { + Desktop.getDesktop().browse(new URI(url)); + } catch (Exception ex) { + } + } + } }