diff options
| -rw-r--r-- | src/main/java/DownloadConfigPane.form | 115 | ||||
| -rw-r--r-- | src/main/java/DownloadConfigPane.java | 183 | ||||
| -rw-r--r-- | src/main/java/Main.java | 39 |
3 files changed, 331 insertions, 6 deletions
diff --git a/src/main/java/DownloadConfigPane.form b/src/main/java/DownloadConfigPane.form new file mode 100644 index 0000000..324f738 --- /dev/null +++ b/src/main/java/DownloadConfigPane.form @@ -0,0 +1,115 @@ +<?xml version="1.0" encoding="UTF-8"?> +<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="DownloadConfigPane"> + <grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="6" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <margin top="5" left="10" bottom="5" right="10"/> + <constraints> + <xy x="20" y="20" width="500" height="400"/> + </constraints> + <properties/> + <border type="none"/> + <children> + <vspacer id="ebbca"> + <constraints> + <grid row="0" column="4" row-span="2" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/> + </constraints> + </vspacer> + <component id="b2b01" class="javax.swing.JTextField" binding="urlField"> + <constraints> + <grid row="0" column="1" 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> + </constraints> + <properties/> + </component> + <component id="680dd" class="javax.swing.JTextField" binding="fromField"> + <constraints> + <grid row="1" column="1" 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> + </constraints> + <properties> + <text value="HH:MM:SS"/> + </properties> + </component> + <component id="397fe" class="javax.swing.JTextField" binding="toField"> + <constraints> + <grid row="1" column="3" 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> + </constraints> + <properties> + <text value="HH:MM:SS"/> + </properties> + </component> + <component id="ec6a1" class="javax.swing.JLabel" binding="urlLabel"> + <constraints> + <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text value="URL"/> + </properties> + </component> + <component id="6cdf5" class="javax.swing.JLabel" binding="fromLabel"> + <constraints> + <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text value="From:"/> + </properties> + </component> + <component id="8697b" class="javax.swing.JLabel" binding="toLabel"> + <constraints> + <grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text value="To:"/> + </properties> + </component> + <component id="ceeb1" class="javax.swing.JButton" binding="loadFromFileButton"> + <constraints> + <grid row="5" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text value="Load From File"/> + </properties> + </component> + <component id="be7e5" class="javax.swing.JButton" binding="addButton" default-binding="true"> + <constraints> + <grid row="2" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text value="Add"/> + </properties> + </component> + <component id="9d097" class="javax.swing.JButton" binding="saveButton" default-binding="true"> + <constraints> + <grid row="5" column="2" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text value="Save"/> + </properties> + </component> + <component id="c475a" class="javax.swing.JButton" binding="removeButton" default-binding="true"> + <constraints> + <grid row="3" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text value="Remove"/> + </properties> + </component> + <scrollpane id="2fcad" binding="tableScrollPane"> + <constraints> + <grid row="4" column="0" row-span="1" col-span="4" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + </constraints> + <properties/> + <border type="none"/> + <children> + <component id="3f523" class="javax.swing.JTable" binding="outputTable"> + <constraints/> + <properties/> + </component> + </children> + </scrollpane> + </children> + </grid> +</form> diff --git a/src/main/java/DownloadConfigPane.java b/src/main/java/DownloadConfigPane.java new file mode 100644 index 0000000..9d6a3b9 --- /dev/null +++ b/src/main/java/DownloadConfigPane.java @@ -0,0 +1,183 @@ +import javax.swing.*; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.DefaultTableModel; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.nio.file.Files; + +public class DownloadConfigPane extends JFrame{ + private JPanel mainPanel; + private JTable outputTable; + private JTextField urlField; + private JTextField fromField; + private JTextField toField; + private JButton loadFromFileButton; + private JLabel fromLabel; + private JLabel toLabel; + private JLabel urlLabel; + private JButton addButton; + private JButton saveButton; + private JButton removeButton; + private JScrollPane tableScrollPane; + + private String loadedPath; + + public DownloadConfigPane() { + // initialize intellijlaf + this.add(mainPanel); + this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.setLocationRelativeTo(null); + this.setSize(900, 500); + initializeTable(); + this.setVisible(true); + loadFromFileButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + loadConfigFromFile(); + } + }); + saveButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + } + }); + addButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String url = urlField.getText(); + String from = fromField.getText(); + String to = toField.getText(); + if (url.length() == 0){ + return; + } + if (from.length() != 8){ + from = "00:00:00"; + } + if (to.length() != 8){ + to = "00:00:00"; + } + Object[] song = new Object[]{url, from, to}; + DefaultTableModel model = (DefaultTableModel) outputTable.getModel(); + model.addRow(song); + } + }); + removeButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + int row = outputTable.getSelectedRow(); + if (row == -1){ + return; + } + DefaultTableModel model = (DefaultTableModel) outputTable.getModel(); + model.removeRow(row); + } + }); + saveButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + saveConfigToFile(); + } + }); + } + + private void initializeTable() { + DefaultTableModel model = new DefaultTableModel(); + // center align the text in the table + + DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(); + centerRenderer.setHorizontalAlignment( JLabel.CENTER ); + outputTable.setDefaultRenderer(String.class, centerRenderer); + model.addColumn("URL"); + model.addColumn("From"); + model.addColumn("To"); + outputTable.setModel(model); + outputTable.getTableHeader().setReorderingAllowed(false); + } + + private void clearTable(){ + DefaultTableModel model = (DefaultTableModel) outputTable.getModel(); + model.setRowCount(0); + } + + private File selectTextFileChooser(){ + JFileChooser chooser = new JFileChooser(); + chooser.setCurrentDirectory(new File(System.getProperty("user.home"))); + int result = chooser.showOpenDialog(this); + if (result == JFileChooser.APPROVE_OPTION) { + File selectedFile = chooser.getSelectedFile(); + System.out.println("Selected file: " + selectedFile.getAbsolutePath()); + return selectedFile; + } + return null; + } + + private void loadConfigFromFile(){ + File file = selectTextFileChooser(); + if (file == null){ + return; + } + clearTable(); + initializeTable(); + try{ + for (String line : Files.readAllLines(file.toPath())) { + String[] split = line.split(","); + String url = split[0]; + String[] timeRange = new String[2]; + if (split.length == 2){ + timeRange = split[1].split("-"); + } + else{ + timeRange[0] = "00:00:00"; + timeRange[1] = "00:00:00"; + } + String from = timeRange[0]; + String to = timeRange[1]; + if (from.length() != 8){ + from = "00:00:00"; + } + if (to.length() != 8){ + to = "00:00:00"; + } + Object[] song = new Object[]{url, from, to}; + DefaultTableModel model = (DefaultTableModel) outputTable.getModel(); + model.addRow(song); + // add headers to the table + + + + } + loadedPath = file.getAbsolutePath(); + } + catch (Exception e){ + e.printStackTrace(); + JOptionPane.showMessageDialog(null, "Please choose a file with the download config format"); + System.out.println("Invalid file selected"); + loadedPath = null; + } + + } + + private void saveConfigToFile(){ + if(loadedPath == null){ + System.out.println("No file loaded"); + return; + } + File saveFile = new File(loadedPath); + if(!saveFile.exists()){ + System.out.println("File does not exist"); + return; + } + for (int i = 0; i < outputTable.getRowCount(); i++) { + String url = (String) outputTable.getValueAt(i, 0); + String from = (String) outputTable.getValueAt(i, 1); + String to = (String) outputTable.getValueAt(i, 2); + String line = url + "," + from + "-" + to; + System.out.println(line); + } + JOptionPane.showConfirmDialog(null, "Saved to " + loadedPath, "Saved", JOptionPane.DEFAULT_OPTION); + } + + +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 0281001..ed04835 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -6,12 +6,9 @@ import java.text.SimpleDateFormat; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
+import java.util.Scanner;
-import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.FlatIntelliJLaf;
-import com.formdev.flatlaf.FlatLightLaf;
-import com.formdev.flatlaf.themes.FlatMacDarkLaf;
-import com.formdev.flatlaf.themes.FlatMacLightLaf;
import org.jaudiotagger.audio.AudioFile;
import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.tag.FieldKey;
@@ -37,6 +34,7 @@ public class Main extends JFrame { JButton songsGen = new JButton("Generate text file");
JButton editButton = new JButton("Edit Tags");
JButton startButton = new JButton("Set .txt File");
+ JButton configureDownloadButton = new JButton("Configure Download File Interactively");
JCheckBox defaultFileBox = new JCheckBox("Use Default songs.txt file");
JCheckBox useBlacklistBox = new JCheckBox("Use Blacklist.txt");
JProgressBar progressBar = new JProgressBar();
@@ -86,7 +84,6 @@ public class Main extends JFrame { return;
}
-
String info[] = fileUtil.parseInfoJSON(fileUtil.jsonToString(fileUtil.findJsonFile(DOWNLOADED_DIR))); //title,uploader
String uploader = info[1];
String title = info[0];
@@ -255,8 +252,14 @@ public class Main extends JFrame { panel.add(scrollPane);
panel.add(Box.createVerticalStrut(5));
panel.add(editButton);
+ panel.add(Box.createVerticalStrut(5));
panel.add(useBlacklistBox);
panel.add(Box.createVerticalStrut(8));
+ outputArea.setEditable(false);
+ // make configureDownloadButton centered
+ configureDownloadButton.setAlignmentX(Component.CENTER_ALIGNMENT);
+ panel.add(configureDownloadButton);
+
this.setSize(550, 450);
this.setTitle("YTMP3Tagger");
@@ -276,13 +279,17 @@ public class Main extends JFrame { showWarning("Default File has been set.\nMake sure you add a new line for each URL");
readyState = true;
startButton.setText("Start Download");
- outputArea.setText(outputArea.getText() + "\n" + "Ready to begin downloading. Press the button");
+ outputArea.setText("Configuration Loaded:\n");
+ writeFileContentsToOutputArea(textPath);
+ outputArea.setText(outputArea.getText() + "\n\n\n" + "Ready to begin downloading. Press the button");
System.out.println("Ready to begin downloading. Press the button");
useDefault = true;
} else {
useDefault = false;
readyState = false;
+ outputArea.setText(outputArea.getText() + "\n" + "Cancelled. Please set a .txt file");
+ System.out.println("Cancelled. Please set a .txt file");
startButton.setText("Set .txt file");
}
}
@@ -311,6 +318,7 @@ public class Main extends JFrame { if (!textPath.equals("")) {
showWarning("File has been set.\nMake sure you add a new line for each URL");
readyState = true;
+ writeFileContentsToOutputArea(textPath);
startButton.setText("Start Download");
outputArea.setText(outputArea.getText() + "\n" + "Ready to begin downloading. Press the button");
System.out.println("Ready to begin downloading. Press the button");
@@ -337,8 +345,27 @@ public class Main extends JFrame { new TagEditorScreen().setVisible(true);
}
});
+ configureDownloadButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ new DownloadConfigPane();
+ }
+ });
}
+ private void writeFileContentsToOutputArea(String path){
+ File file = new File(path);
+ try {
+ Scanner scanner = new Scanner(file);
+ while (scanner.hasNextLine()){
+ String line = scanner.nextLine();
+ outputArea.setText(outputArea.getText() + "\n" + line);
+ }
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+
+ }
/**
* Convert mp4 to mp3 using ffmpeg
* @param mp4File The mp4 file to convert
|
