diff options
| author | Donald Shan <xxpinapelzxx@gmail.com> | 2022-08-21 23:27:41 -0700 |
|---|---|---|
| committer | Donald Shan <xxpinapelzxx@gmail.com> | 2022-08-21 23:27:41 -0700 |
| commit | 8047076887b10a8aff91d3c85ba1bf31c200e679 (patch) | |
| tree | 89211ba331804aefd7e99cec4ddc499e45bcc68f /src | |
| parent | de338a05e5fbbb3c707a69335677ca805f1a042f (diff) | |
Added second preliminary screen for editing tags manually
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/FileUtility.java | 25 | ||||
| -rw-r--r-- | src/main/java/Main.java | 19 | ||||
| -rw-r--r-- | src/main/java/TagEditor.java | 11 | ||||
| -rw-r--r-- | src/main/java/TagEditorScreen.form | 157 | ||||
| -rw-r--r-- | src/main/java/TagEditorScreen.java | 149 |
5 files changed, 342 insertions, 19 deletions
diff --git a/src/main/java/FileUtility.java b/src/main/java/FileUtility.java index 7f35c30..cc0dffb 100644 --- a/src/main/java/FileUtility.java +++ b/src/main/java/FileUtility.java @@ -1,3 +1,4 @@ +import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.io.*; import java.net.URL; @@ -25,6 +26,7 @@ public class FileUtility { fos.close(); is.close(); } + public void moveFile(String source, String destination) { File sourceFile = new File(source); File destinationFile = new File(destination); @@ -131,4 +133,27 @@ public class FileUtility { } return lines; } + public String showDirectoryChooser(){ + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + int result = fileChooser.showOpenDialog(null); + if(result == JFileChooser.APPROVE_OPTION){ + return fileChooser.getSelectedFile().getAbsolutePath(); + } + return ""; + } + //get the path of all mp3 files in a directory and return them as a file arraylist + public ArrayList<File> getMp3Files(String path){ + ArrayList<File> mp3Files = new ArrayList<File>(); + File folder = new File(path); + File[] listOfFiles = folder.listFiles(); + for(int i=0;i<listOfFiles.length;i++){ + if(listOfFiles[i].isFile()){ + if(listOfFiles[i].getName().endsWith(".mp3")){ + mp3Files.add(listOfFiles[i]); + } + } + } + return mp3Files; + } } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index ec95ad9..46723d3 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -20,7 +20,7 @@ public class Main extends JFrame { int progress = 0; FileUtility fileUtil = new FileUtility(); JProgressBar progressBar = new JProgressBar(); - JLabel title = new JLabel("SUPER JUICER DOWNLOAD MUSIC COVERS AND TAG NOW 100% SAFE"); + JLabel title = new JLabel("YouTube to MP3 Auto Tagging"); JButton startButton = new JButton("Set .txt File"); static JTextArea outputArea = new JTextArea("this is bery bery bery safe no worries no virus malwar ur monies back granteed"); @@ -33,7 +33,7 @@ public class Main extends JFrame { new Main().setVisible(true); } - private void initializeComponents(){ + private void initializeComponents(){//Initiate GUI components this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setLocationRelativeTo(null); this.add(panel); @@ -60,10 +60,11 @@ public class Main extends JFrame { panel.add(scrollPane); panel.add(Box.createVerticalStrut(5)); panel.add(editButton); - this.setSize(550,300); + this.setSize(550,450); + this.setTitle("amazing program to download and tag all mp3 files"); } - private void initializeActionsListeners(){ + private void initializeActionsListeners(){//Add all actionlisteners for buttons startButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -95,12 +96,12 @@ public class Main extends JFrame { editButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e){ - + new TagEditorScreen().setVisible(true); } }); } - private void downloadAndTag(){ + private void downloadAndTag(){ //Main loop ran for checking list of songs, downloading mp3 files, and applying tags ArrayList<String> songs = fileUtil.txtToArrayList(textPath); progress = 0; for(int i = 0;i<songs.size();i++) { @@ -130,15 +131,17 @@ public class Main extends JFrame { } } - private int calculatePercentage(int current, int total){ + private int calculatePercentage(int current, int total){//Calculate the percentage when give numerator and denominator double currentD = current; double totalD = total; return (int)((currentD/totalD)*100); } + public static void showWarning(String message) { JOptionPane.showMessageDialog(null, message, "JUST YOUR FRIENDLY NEIGHBORLY REMINDER", JOptionPane.WARNING_MESSAGE); } - public static void youtubeToMP3(String url) { + + public static void youtubeToMP3(String url) {//Download mp3 of youtube video using yt-dlp.exe. Ran from cmd try { ProcessBuilder builder = new ProcessBuilder( "yt-dlp.exe", diff --git a/src/main/java/TagEditor.java b/src/main/java/TagEditor.java deleted file mode 100644 index b2095e5..0000000 --- a/src/main/java/TagEditor.java +++ /dev/null @@ -1,11 +0,0 @@ -import javax.swing.*; -import java.awt.*; - -public class TagEditor extends JFrame { - JPanel mainPanel = new JPanel(); - GridBagConstraints constraints = new GridBagConstraints(); - public TagEditor(){ - mainPanel.setLayout(new GridBagLayout()); - this.setDefaultCloseOperation(EXIT_ON_CLOSE); - } -} diff --git a/src/main/java/TagEditorScreen.form b/src/main/java/TagEditorScreen.form new file mode 100644 index 0000000..c82ca8e --- /dev/null +++ b/src/main/java/TagEditorScreen.form @@ -0,0 +1,157 @@ +<?xml version="1.0" encoding="UTF-8"?> +<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="TagEditorScreen"> + <grid id="27dc6" binding="mainPanel" layout-manager="FormLayout"> + <rowspec value="center:d:grow"/> + <rowspec value="top:4dlu:noGrow"/> + <rowspec value="center:max(d;4px):noGrow"/> + <rowspec value="top:4dlu:noGrow"/> + <rowspec value="center:max(d;4px):noGrow"/> + <rowspec value="top:4dlu:noGrow"/> + <rowspec value="center:max(d;4px):noGrow"/> + <rowspec value="top:4dlu:noGrow"/> + <rowspec value="center:max(d;4px):noGrow"/> + <rowspec value="top:4dlu:noGrow"/> + <rowspec value="center:max(d;4px):noGrow"/> + <rowspec value="top:4dlu:noGrow"/> + <rowspec value="center:max(d;4px):noGrow"/> + <colspec value="fill:d:noGrow"/> + <colspec value="left:4dlu:noGrow"/> + <colspec value="fill:d:grow"/> + <colspec value="left:4dlu:noGrow"/> + <colspec value="fill:d:grow"/> + <constraints> + <xy x="20" y="20" width="405" height="548"/> + </constraints> + <properties/> + <border type="none"/> + <children> + <component id="fd64c" class="javax.swing.JTextField" binding="titleField"> + <constraints> + <grid row="4" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> + <preferred-size width="150" height="-1"/> + </grid> + <forms defaultalign-horz="false"/> + </constraints> + <properties/> + </component> + <component id="b5045" class="javax.swing.JLabel" binding="titleLabel"> + <constraints> + <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + <forms/> + </constraints> + <properties> + <font size="16"/> + <text value="Title"/> + </properties> + </component> + <component id="6c543" class="javax.swing.JTextField" binding="uploaderField"> + <constraints> + <grid row="6" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> + <preferred-size width="150" height="-1"/> + </grid> + <forms defaultalign-horz="false"/> + </constraints> + <properties/> + </component> + <component id="e1d1b" class="javax.swing.JLabel" binding="uploaderLabel"> + <constraints> + <grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + <forms/> + </constraints> + <properties> + <font size="16"/> + <text value="Artist"/> + </properties> + </component> + <component id="b30b1" class="javax.swing.JLabel"> + <constraints> + <grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + <forms/> + </constraints> + <properties> + <font size="16"/> + <text value="Image"/> + </properties> + </component> + <component id="a2643" class="javax.swing.JTextField" binding="textField1" default-binding="true"> + <constraints> + <grid row="8" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> + <preferred-size width="150" height="-1"/> + </grid> + <forms defaultalign-horz="false"/> + </constraints> + <properties/> + </component> + <component id="68cf1" class="javax.swing.JButton" binding="imageChooseButton"> + <constraints> + <grid row="10" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> + <forms/> + </constraints> + <properties> + <text value="Choose Image File"/> + </properties> + </component> + <component id="c4b6c" class="javax.swing.JButton" binding="applyChangesButton" default-binding="true"> + <constraints> + <grid row="12" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> + <forms/> + </constraints> + <properties> + <text value="Apply Changes"/> + </properties> + </component> + <component id="c22a3" class="javax.swing.JButton" binding="chooseAudioDirectoryButton" default-binding="true"> + <constraints> + <grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> + <forms/> + </constraints> + <properties> + <text value="Choose Audio Directory"/> + </properties> + </component> + <component id="5326a" class="javax.swing.JLabel" binding="artIconLabel"> + <constraints> + <grid row="10" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + <forms/> + </constraints> + <properties> + <text value=""/> + </properties> + </component> + <scrollpane id="a5b4e"> + <constraints> + <grid row="0" column="0" row-span="1" col-span="5" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + <forms defaultalign-horz="false" defaultalign-vert="false"/> + </constraints> + <properties> + <font size="14"/> + </properties> + <border type="none"/> + <children> + <component id="7b1a7" class="javax.swing.JTable" binding="songTable"> + <constraints/> + <properties/> + </component> + </children> + </scrollpane> + <component id="b9881" class="javax.swing.JTextField" binding="textField2" default-binding="true"> + <constraints> + <grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> + <preferred-size width="150" height="-1"/> + </grid> + <forms defaultalign-horz="false"/> + </constraints> + <properties/> + </component> + <component id="d9cc0" class="javax.swing.JLabel"> + <constraints> + <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + <forms/> + </constraints> + <properties> + <text value="Search"/> + </properties> + </component> + </children> + </grid> +</form> diff --git a/src/main/java/TagEditorScreen.java b/src/main/java/TagEditorScreen.java new file mode 100644 index 0000000..19ea8fd --- /dev/null +++ b/src/main/java/TagEditorScreen.java @@ -0,0 +1,149 @@ +import org.jaudiotagger.audio.*; +import org.jaudiotagger.tag.FieldKey; +import org.jaudiotagger.tag.Tag; +import org.jaudiotagger.tag.datatype.Artwork; + +import javax.imageio.ImageIO; +import javax.swing.*; +import javax.swing.table.DefaultTableModel; +import java.awt.*; +import java.awt.event.*; +import java.awt.image.BufferedImage; +import java.awt.image.CropImageFilter; +import java.awt.image.FilteredImageSource; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +public class TagEditorScreen extends JFrame{ + private JPanel mainPanel; + private JTextField titleField; + private JLabel titleLabel; + private JTextField uploaderField; + private JLabel uploaderLabel; + private JTextField textField1; + private JButton imageChooseButton; + private JTable songTable; + private JButton chooseAudioDirectoryButton; + private JButton applyChangesButton; + private JLabel artIconLabel; + private JTextField textField2; + private FileUtility fileUtil = new FileUtility(); + private String setDirPath = ""; + private ArrayList<File> songList = new ArrayList<File>(); + private long timeOfLastClick = 9999999; + + public TagEditorScreen(){ + this.setContentPane(mainPanel); + this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.setLocationRelativeTo(null); + this.setSize(600, 450); + initializeTable(); + this.setVisible(true); + chooseAudioDirectoryButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + clearSongTable(); + setDirPath = fileUtil.showDirectoryChooser(); + songList = fileUtil.getMp3Files(setDirPath); //get arraylist of all files in the directory + for(int i=0;i<songList.size();i++){ + addSongTable(songList.get(i)); + + } + } + }); + songTable.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + super.mouseClicked(e); + populateFields(new File(songTable.getModel().getValueAt(songTable.getSelectedRow(),2 ).toString())); + + + } + }); + songTable.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + super.keyPressed(e); + if(e.getKeyCode()==KeyEvent.VK_DOWN){ + try { + populateFields(new File(songTable.getModel().getValueAt(songTable.getSelectedRow() + 1, 2).toString())); + } + catch(Exception ex){ + + } + } + else if(e.getKeyCode()==KeyEvent.VK_UP){ + try { + populateFields(new File(songTable.getModel().getValueAt(songTable.getSelectedRow() - 1, 2).toString())); + } + catch(Exception ex){ + + } + } + } + }); + applyChangesButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + } + }); + } + public void initializeTable(){ + songTable.setDefaultEditor(Object.class, null); + songTable.setModel(new DefaultTableModel(null, new String[]{"Title", "Artist","Filepath"})); + songTable.getTableHeader().setReorderingAllowed(false); + } + public void clearSongTable(){ + DefaultTableModel dtm = (DefaultTableModel) songTable.getModel(); + dtm.setRowCount(0); + } + public void addSongTable(File audioFile){ + try { + AudioFile f = AudioFileIO.read(audioFile); + Tag tag = f.getTag(); + DefaultTableModel model = (DefaultTableModel) songTable.getModel(); + model.addRow(new Object[]{tag.getFirst(FieldKey.TITLE), tag.getFirst(FieldKey.ARTIST),audioFile.getAbsolutePath()}); + } + catch(Exception e){ + + } + } +//search for a file in a directory and return the file as a file + public File searchForFile(String fileName, String directory){ + File[] files = new File(directory).listFiles(); + for(File file:files){ + if(file.getName().equals(fileName)){ + return file; + } + } + return null; + } + + public void populateFields(File audioFile){ + try { + AudioFile f = AudioFileIO.read(audioFile); + Tag tag = f.getTag(); + titleField.setText(tag.getFirst(FieldKey.TITLE)); + uploaderField.setText(tag.getFirst(FieldKey.ARTIST)); + Artwork albumArt = tag.getFirstArtwork(); + ImageIcon albumArtIcon = new ImageIcon(resizeImage(albumArt.getImage(),320,180)); + artIconLabel.setIcon(albumArtIcon); + + + } + catch (Exception e){ + e.printStackTrace(); + } + + } + BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws IOException { + Image resultingImage = originalImage.getScaledInstance(targetWidth, targetHeight, Image.SCALE_DEFAULT); + BufferedImage outputImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB); + outputImage.getGraphics().drawImage(resultingImage, 0, 0, null); + return outputImage; + } + + +} |
