aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDonald Shan <xxpinapelzxx@gmail.com>2022-11-01 11:04:05 -0700
committerGitHub <noreply@github.com>2022-11-01 11:04:05 -0700
commit8173386f6bad0cdb6ea7b9dee463fd8db31c5f15 (patch)
tree457dd875c0b9614ef5d6c3751053b0fc2b3068fd /src
parentb109ae605064bb61fcb6f706923cfb269097149d (diff)
Delete src/main/java directory
Diffstat (limited to 'src')
-rw-r--r--src/main/java/FileUtility.java247
-rw-r--r--src/main/java/Main.java318
-rw-r--r--src/main/java/TagEditorScreen.form157
-rw-r--r--src/main/java/TagEditorScreen.java186
4 files changed, 0 insertions, 908 deletions
diff --git a/src/main/java/FileUtility.java b/src/main/java/FileUtility.java
deleted file mode 100644
index c85ea36..0000000
--- a/src/main/java/FileUtility.java
+++ /dev/null
@@ -1,247 +0,0 @@
-import javax.swing.*;
-import javax.swing.filechooser.FileNameExtensionFilter;
-import java.io.*;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class FileUtility {
- public void deleteFile(String fileName) {
- File file = new File(fileName);
- if (file.exists()) {
- file.delete();
- }
- }
-
- public void downloadImage(String url, String fileName,String[] formats) {
- boolean successfulDownload = false;
- int formatIndex = 0;
- while(!successfulDownload) {
- try {
- FileOutputStream fos = new FileOutputStream(fileName);
- URL urlObj = new URL(url+formats[formatIndex]);
- InputStream is = urlObj.openStream();
- byte[] b = new byte[2048];
- int length;
- while ((length = is.read(b)) != -1) {
- fos.write(b, 0, length);
- }
- fos.close();
- is.close();
- successfulDownload = true;
- } catch (Exception e) {
- formatIndex++;
- }
- }
-
- }
- public String removeBlacklist(String s, String filename){
- HashMap<String, String> blacklist = arrayListToHashMap(readTextFile(filename),":");
- for(String key : blacklist.keySet()){
- if(s.contains(key)){
- s = s.replace(key,blacklist.get(key));
- }
- }
- return s;
-
-
- }
- //read a text file and return the contents as a hashmap with key value pairs
- public ArrayList<String> readTextFile(String fileName) {
- ArrayList<String> lines = new ArrayList<String>();
- try {
- BufferedReader br = new BufferedReader(new FileReader(fileName));
- String line;
- while ((line = br.readLine()) != null) {
- lines.add(line);
- }
- br.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return lines;
- }
- public HashMap<String, String> arrayListToHashMap(ArrayList<String> list, String delimiter) {
-
- HashMap<String, String> map = new HashMap<String, String>();
- for (String line : list) {
- String[] parts = line.split(delimiter);
- if (parts.length >= 2) {
- String key = parts[0];
- String value = parts[1];
- map.put(key, value);
- }
- else if(parts.length==1){
- String key = parts[0];
- String value = "";
- map.put(key, value);
- }
- else {
- System.out.println("ignoring line: " + line);
- }
- }
- return map;
- }
-
-
-
-
-
-
-
-
-
-
-
- public void moveFile(String source, String destination) {
- File sourceFile = new File(source);
- File destinationFile = new File(destination);
- sourceFile.renameTo(destinationFile);
- System.out.println("Moved file to Completed Folder");
- }
- public String removeNonAlphaNumeric(String str) {
- return str.replaceAll("[^a-zA-Z0-9]", "");
- }
- public static String showTextFileChooser() {
- javax.swing.JFileChooser chooser = new javax.swing.JFileChooser();
- FileNameExtensionFilter filter = new FileNameExtensionFilter("Text File", "txt", "text");
- chooser.setFileFilter(filter);
- chooser.setDialogTitle("Select a text file");
- chooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_ONLY);
- chooser.setAcceptAllFileFilterUsed(false);
- if (chooser.showOpenDialog(null) == javax.swing.JFileChooser.APPROVE_OPTION) {
- return chooser.getSelectedFile().getAbsolutePath();
- } else {
- return null;
- }
- }
- public static File findMP3File(String directory){
- File dir = new File(directory);
- File[] files = dir.listFiles();
- for(File file : files){
- if(file.getName().endsWith(".mp3")){
- return file;
- }
- }
- return null;
- }
-
- public static String findJsonFile(String folderName) {
- File folder = new File(folderName);
- File[] listOfFiles = folder.listFiles();
- for (int i = 0; i < listOfFiles.length; i++) {
- if (listOfFiles[i].isFile()) {
- if (listOfFiles[i].getName().endsWith(".json")) {
- return listOfFiles[i].getAbsolutePath();
- }
- }
- }
- return null;
- }
- public static String[] parseJson(String json) {
- String title = "";
- String uploader = "";
- String id = "";
- Pattern titlePattern = Pattern.compile("\"fulltitle\": \"(.*?)\",");
- Matcher titleMatcher = titlePattern.matcher(json);
- Pattern uploaderPattern = Pattern.compile("\"uploader\": \"(.*?)\",");
- Matcher uploaderMatcher = uploaderPattern.matcher(json);
- Pattern idPattern = Pattern.compile("\"id\": \"(.*?)\",");
- Matcher idMatcher = idPattern.matcher(json);
- titleMatcher.find();
- idMatcher.find();
- uploaderMatcher.find();
- title = titleMatcher.group(1);
- uploader = uploaderMatcher.group(1);
- id = idMatcher.group(1);
- String[] info = {title,uploader,id};
- return info;
-
- }
- public static String jsonToString(String fileName) {
- String json = "";
- try {
- BufferedReader br = new BufferedReader(new FileReader(fileName));
- StringBuilder sb = new StringBuilder();
- String line = br.readLine();
- while (line != null) {
- sb.append(line);
- line = br.readLine();
- }
- json = sb.toString();
- br.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return json;
- }
- public static void deleteAllFilesDir(String path) {
- File folder = new File(path);
- File[] files = folder.listFiles();
- if (files != null) {
- for (File f : files) {
- f.delete();
- }
- }
- }
-
- public static String showImageFileChooser() {
- javax.swing.JFileChooser chooser = new javax.swing.JFileChooser();
- FileNameExtensionFilter filter = new FileNameExtensionFilter("JPEG Image File", "jpg", "jpeg");
- chooser.setFileFilter(filter);
- chooser.setDialogTitle("Select a image file");
- chooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_ONLY);
- chooser.setAcceptAllFileFilterUsed(false);
- if (chooser.showOpenDialog(null) == javax.swing.JFileChooser.APPROVE_OPTION) {
- return chooser.getSelectedFile().getAbsolutePath();
- } else {
- return null;
- }
- }
- public static ArrayList<String> txtToArrayList(String fileName) {
- ArrayList<String> lines = new ArrayList<String>();
- try {
- FileReader fr = new FileReader(fileName);
- BufferedReader br = new BufferedReader(fr);
- String line;
- while ((line = br.readLine()) != null) {
- lines.add(line);
- }
- br.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return lines;
- }
- public String showDirectoryChooser(){
- try {
- JFileChooser fileChooser = new JFileChooser();
- fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
- int result = fileChooser.showOpenDialog(null);
- if (result == JFileChooser.APPROVE_OPTION) {
- return fileChooser.getSelectedFile().getAbsolutePath();
- }
- }
- catch(Exception e){
- JOptionPane.showMessageDialog(null,"An unexpected error has occured");
- }
- 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
deleted file mode 100644
index 4f7019c..0000000
--- a/src/main/java/Main.java
+++ /dev/null
@@ -1,318 +0,0 @@
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.io.*;
-import java.util.ArrayList;
-import java.util.Arrays;
-import org.jaudiotagger.audio.AudioFile;
-import org.jaudiotagger.audio.AudioFileIO;
-import org.jaudiotagger.tag.FieldKey;
-import org.jaudiotagger.tag.Tag;
-import org.jaudiotagger.tag.datatype.Artwork;
-import javax.swing.*;
-import javax.swing.text.DefaultCaret;
-
-
-public class Main extends JFrame {
- String textPath = "";
- JPanel panel = new JPanel();
- Boolean readyState = false;
- JScrollPane scrollPane;
- JButton songsGen = new JButton("Generate text file");
- JButton editButton = new JButton("Edit Tags");
- JCheckBox defaultFileBox = new JCheckBox("Use Default songs.txt file");
- JCheckBox useBlacklistBox = new JCheckBox("Use Blacklist.txt");
- int progress = 0;
- Boolean useBlacklist = false;
- String formats[] = {"maxresdefault.jpg","mqdefault.jpg","hqdefault.jpg"};
- FileUtility fileUtil = new FileUtility();
- JProgressBar progressBar = new JProgressBar();
- JLabel title = new JLabel("YouTube to MP3 Auto Tagging [1]");
- JButton startButton = new JButton("Set .txt File");
- static JTextArea outputArea = new JTextArea("");
- Boolean useDefault = false;
-
- public Main(){
- initializeComponents();
- initializeActionsListeners();
- }
-
- public static void main(String[] args) {
- new Main().setVisible(true);
- }
-
- 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;
- String timeAppend = "";
- boolean partFlag = false;
- for(int i = 0;i<songs.size();i++) {
- try {
- fileUtil.deleteAllFilesDir("downloaded");
- ArrayList<String> splitStamp = null;
- try{
- splitStamp = new ArrayList<>(Arrays.asList(songs.get(i).split(",")));
- }
- catch(Exception e) {
-
- }
- if(splitStamp.size()>=2){
- timeAppend = youtubeToMP3Part(splitStamp.get(0),splitStamp.get(1));
- partFlag = true;
- }
- else{
- youtubeToMP3Full(songs.get(i));
- }
-
- String info[] = fileUtil.parseJson(fileUtil.jsonToString(fileUtil.findJsonFile("downloaded"))); //title,uploader
- String uploader = info[1];
- String title = info[0];
- if(useBlacklist){
- System.out.println("Using blacklist");
- uploader = fileUtil.removeBlacklist(uploader,"blacklist.txt");
- title = fileUtil.removeBlacklist(title,"blacklist.txt");
- }
- AudioFile f = AudioFileIO.read(fileUtil.findMP3File("downloaded"));
- Tag tag = f.getTag();
- System.out.println("Uploader: "+uploader);
- System.out.println("Title: "+title);
- tag.setField(FieldKey.ARTIST, uploader);
- tag.setField(FieldKey.TITLE, title);
- fileUtil.downloadImage("https://img.youtube.com/vi/"+info[2]+"/","img.jpg",formats);
- Artwork cover = Artwork.createArtworkFromFile(new File("img.jpg"));
- tag.addField(cover);
- f.commit();
- fileUtil.deleteFile("img.jpg");
- if(partFlag){
- fileUtil.moveFile(fileUtil.findMP3File("downloaded").getAbsolutePath(), "completed/"
- + fileUtil.removeNonAlphaNumeric(info[0]) +
- " ["+info[2]+ "]"+timeAppend+".mp3");
- }
- else{
- fileUtil.moveFile(fileUtil.findMP3File("downloaded").getAbsolutePath(), "completed/" +
- fileUtil.removeNonAlphaNumeric(info[0]) + " ["+info[2]+ "].mp3");
- }
- outputArea.setText(outputArea.getText()+"\n"+"Moved file to Completed Folder");
- progress = i;
- System.out.println("Current Progress " + calculatePercentage(i+1,songs.size()));
- progressBar.setValue(calculatePercentage(i+1,songs.size()));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- 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 youtubeToMP3Full(String url) {//Download mp3 of youtube video using yt-dlp.exe. Ran from cmd
- try {
- ProcessBuilder builder = new ProcessBuilder(
- "yt-dlp.exe",
- "--extract-audio",
- "--audio-format", "mp3",
- "--audio-quality", "0",
- "--output", "downloaded/%(title)s_%(id)s.mp3",
- "--ffmpeg-location","ffmpeg.exe",
- "--write-info-json",
- url
- );
- builder.redirectErrorStream(true);
- Process p = builder.start();
- BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
- String line;
- while (true) {
- line = r.readLine();
- if (line == null) {
- break;
- }
- outputArea.setText(outputArea.getText()+"\n"+line);
- System.out.println(line);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
- public static String youtubeToMP3Part(String url,String stamp) {//Download mp3 of youtube video using yt-dlp.exe. Ran from cmd
- System.out.println(url + " " + stamp);
- ArrayList<String> times = new ArrayList<>(Arrays.asList(stamp.split("-")));
- ArrayList<String> startTimeComponents = new ArrayList<>(Arrays.asList(times.get(0).split(":")));
- ArrayList<String> endTimeComponents = new ArrayList<>(Arrays.asList(times.get(1).split(":")));
- int startSec = 0;
- int endSec = 0;
- if(startTimeComponents.size()==3){
- startSec = Integer.parseInt(startTimeComponents.get(0))*60*60+Integer.parseInt(startTimeComponents.get(1))*60+Integer.parseInt(startTimeComponents.get(2));
- }
- else if(startTimeComponents.size()==2){
- startSec = Integer.parseInt(startTimeComponents.get(0))*60+Integer.parseInt(startTimeComponents.get(1));
- }
- if(endTimeComponents.size()==3){
- endSec = Integer.parseInt(endTimeComponents.get(0))*60*60+Integer.parseInt(endTimeComponents.get(1))*60+Integer.parseInt(endTimeComponents.get(2));
- }
- else if(endTimeComponents.size()==2){
- endSec = Integer.parseInt(endTimeComponents.get(0))*60+Integer.parseInt(endTimeComponents.get(1));
- }
- try {
- ProcessBuilder builder = new ProcessBuilder(
- "yt-dlp.exe",
- "--extract-audio",
- "--audio-format", "mp3",
- "--audio-quality", "0",
- "--output", "downloaded/%(title)s_%(id)s.mp3",
- "--ffmpeg-location","ffmpeg.exe",
- "--write-info-json","--download-sections","\"*"+startSec+"-"+endSec+"\"",
- "--force-keyframes-at-cuts",
- url
- );
- builder.redirectErrorStream(true);
- Process p = builder.start();
- BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
- String line;
- while (true) {
- line = r.readLine();
- if (line == null) {
- break;
- }
- outputArea.setText(outputArea.getText()+"\n"+line);
- System.out.println(line);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return startSec+"to"+endSec;
- }
-
-
- private void initializeComponents(){//Initiate GUI components
- this.setDefaultCloseOperation(EXIT_ON_CLOSE);
- this.setLocationRelativeTo(null);
- this.add(panel);
- panel.setLayout(new BoxLayout(panel,BoxLayout.PAGE_AXIS));
- scrollPane = new JScrollPane(outputArea);
- scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
- outputArea.setEditable(true);
- outputArea.setLineWrap(true);
- DefaultCaret caret = (DefaultCaret)outputArea.getCaret();
- caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
- panel.add(Box.createRigidArea(new Dimension(0,5)));
- panel.setBorder(BorderFactory.createEmptyBorder(25,10,20,10));
- startButton.setAlignmentX(CENTER_ALIGNMENT);
- title.setAlignmentX(Component.CENTER_ALIGNMENT);
- defaultFileBox.setAlignmentX(Component.CENTER_ALIGNMENT);
- useBlacklistBox.setAlignmentX(Component.CENTER_ALIGNMENT);
- editButton.setAlignmentX(Component.CENTER_ALIGNMENT);
- songsGen.setAlignmentX(Component.CENTER_ALIGNMENT);
- progressBar.setStringPainted(true);
- title.setFont(new Font("Verdana", Font.PLAIN, 14));
- panel.add(title);
- panel.add(Box.createVerticalStrut(10));
- panel.add(progressBar);
- panel.add(Box.createVerticalStrut(10));
- panel.add(startButton);
- panel.add(defaultFileBox);
- panel.add(Box.createVerticalStrut(8));
- panel.add(scrollPane);
- panel.add(Box.createVerticalStrut(5));
- panel.add(editButton);
- panel.add(useBlacklistBox);
- // panel.add(Box.createVerticalStrut(5));
- // panel.add(songsGen);
-
- this.setSize(550,450);
- this.setTitle("YTMP3Tagger");
- }
-
- private void initializeActionsListeners(){//Add all actionlisteners for buttons
- defaultFileBox.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- File f = new File("songs.txt");
- if(f.exists()&!f.isDirectory()&&!useDefault) {
- System.out.println("songs found");
- textPath = "songs.txt";
- 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");
- System.out.println("Ready to begin downloading. Press the button");
- useDefault = true;
-
- }
- else{
- useDefault = false;
- readyState = false;
- startButton.setText("Set .txt file");
- }
- }
- });
- useBlacklistBox.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- if(useBlacklistBox.isSelected()){
- useBlacklist = true;
- }
- else{
- useBlacklist = false;
- }
-
- }
- });
-
- startButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- if (readyState==false){
- outputArea.setText(outputArea.getText()+"\n"+"txt path has not been set. Launching chooserPane");
- System.out.println(".txt path has not been set. Launching chooserPane");
- textPath = fileUtil.showTextFileChooser();
- try {
- if (!textPath.equals("")) {
- showWarning("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");
- System.out.println("Ready to begin downloading. Press the button");
- }
- }
- catch(Exception ex){
-
- }
- }
- else{
- Runnable runnable = () -> {
- outputArea.setText("");
- startButton.setEnabled(false);
- downloadAndTag();
- startButton.setEnabled(true);
-
- };
- Thread thread = new Thread(runnable);
- thread.start();
- }
- }
- });
- editButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e){
- new TagEditorScreen().setVisible(true);
- }
- });
- songsGen.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e){
- new SongGenScreen().setVisible(true);
- }
- });
- }
-
-
-}
diff --git a/src/main/java/TagEditorScreen.form b/src/main/java/TagEditorScreen.form
deleted file mode 100644
index 828484c..0000000
--- a/src/main/java/TagEditorScreen.form
+++ /dev/null
@@ -1,157 +0,0 @@
-<?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="imagePathField">
- <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
deleted file mode 100644
index 764404c..0000000
--- a/src/main/java/TagEditorScreen.java
+++ /dev/null
@@ -1,186 +0,0 @@
-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.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 imagePathField;
- 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 String selectedAlbumArt = "";
- private ArrayList<File> songList = new ArrayList<File>();
- private String currPath = "";
- private Boolean imageSelected = false;
-
- 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()));
- currPath = songTable.getModel().getValueAt(songTable.getSelectedRow() , 2).toString();
- imageSelected = false;
- }
- });
- 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()));
- currPath = songTable.getModel().getValueAt(songTable.getSelectedRow() + 1, 2).toString();
- imageSelected = false;
- }
- catch(Exception ex){
-
- }
- }
- else if(e.getKeyCode()==KeyEvent.VK_UP){
- try {
- populateFields(new File(songTable.getModel().getValueAt(songTable.getSelectedRow() - 1, 2).toString()));
- currPath = songTable.getModel().getValueAt(songTable.getSelectedRow() - 1, 2).toString();
- imageSelected = false;
- }
- catch(Exception ex){
-
- }
- }
- }
- });
- applyChangesButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- System.out.println("CURRENT PATH " + currPath);
- AudioFile f = AudioFileIO.read(new File(currPath));
- Tag tag = f.getTag();
- tag.setField(FieldKey.TITLE, titleField.getText());
- tag.setField(FieldKey.ARTIST, uploaderField.getText());
- if(imageSelected){
- tag.deleteArtworkField();
- Artwork cover = Artwork.createArtworkFromFile(new File(selectedAlbumArt));
- tag.addField(cover);
- System.out.println("Changed the Artwork");
- }
- f.commit();
- clearSongTable();
- songList = fileUtil.getMp3Files(setDirPath); //get arraylist of all files in the directory
- for(int i=0;i<songList.size();i++){
- addSongTable(songList.get(i));
- }
- }
- catch(Exception ex){
- ex.printStackTrace();
- }
-
- }
- });
- imageChooseButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- selectedAlbumArt = fileUtil.showImageFileChooser();
- File selectedFile = new File(selectedAlbumArt);
- BufferedImage selectedImage = null;
- selectedImage = ImageIO.read(selectedFile);
- ImageIcon albumArtIcon = new ImageIcon(resizeImage(selectedImage, 260, 180));
- artIconLabel.setText(selectedFile.getName());
- artIconLabel.setIcon(albumArtIcon);
- imageSelected = true;
-
- }
- catch(Exception ex){
-
- }
-
- }
- });
- }
- 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){
-
- }
- }
-
- 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);
- artIconLabel.setText("");
-
-
- }
- 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;
- }
-
-
-}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage