aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDonald Shan <xxpinapelzxx@gmail.com>2022-08-19 16:38:32 -0700
committerGitHub <noreply@github.com>2022-08-19 16:38:32 -0700
commitb63b6e96c1706271e9dc02cf5e5865922aff9191 (patch)
tree8d3dd246b5d9b44e8bc2ac3b3df536eb541b197c /src
parentcf0a33531dec34969502ef1ffe87be49f70abccd (diff)
Update Main.java
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/example/Main.java117
1 files changed, 110 insertions, 7 deletions
diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java
index 6d87057..ba75319 100644
--- a/src/main/java/org/example/Main.java
+++ b/src/main/java/org/example/Main.java
@@ -1,4 +1,6 @@
-package org.example;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.io.*;
import java.net.URL;
import java.util.ArrayList;
@@ -9,12 +11,82 @@ import org.jaudiotagger.tag.FieldKey;
import org.jaudiotagger.tag.Tag;
import org.jaudiotagger.tag.datatype.Artwork;
+import javax.swing.*;
+import javax.swing.filechooser.FileNameExtensionFilter;
+import javax.swing.text.DefaultCaret;
import java.util.regex.Pattern;
-public class Main {
+public class Main extends JFrame {
+ String textPath = "";
+ JPanel panel = new JPanel();
+ Boolean readyState = false;
+ JScrollPane scrollPane;
+ int progress = 0;
+ JProgressBar progressBar = new JProgressBar();
+ JLabel title = new JLabel("SUPER JUICER DOWNLOAD MUSIC COVERS AND TAG NOW 100% SAFE");
+ 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");
+ public Main(){
+ 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(false);
+ 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);
+ 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(Box.createVerticalStrut(8));
+ panel.add(scrollPane);
+ startButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if(textPath.equals("")||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 = showFileChooser();
+ if(!textPath.equals("")){
+ showWarning("File has been set.\nMake sure you add a new line for each URL.\nOr else say bye bye to your system32");
+ 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");
+ }
+ }
+ else{
+ Runnable runnable = () -> {
+ outputArea.setText("");
+ startButton.setEnabled(false);
+ downloadLoop();
+ startButton.setEnabled(true);
+ };
+ Thread thread = new Thread(runnable);
+ thread.start();
+ }
+ }
+ });
+ this.setSize(550,300);
+
+ }
public static void main(String[] args) {
- ArrayList<String> songs = readFile("songs.txt");
+ new Main().setVisible(true);
+ }
+ private void downloadLoop(){
+ ArrayList<String> songs = readFile(textPath);
+ progress = 0;
for(int i = 0;i<songs.size();i++) {
try {
deleteFiles("downloaded");
@@ -30,13 +102,39 @@ public class Main {
Artwork cover = Artwork.createArtworkFromFile(new File("img.jpg"));
tag.addField(cover);
f.commit();
+ clearThumbnail("img.jpg");
moveFile(findMP3File("downloaded").getAbsolutePath(), "completed/" + removeNonAlphaNumeric(info[0]) + " ["+info[2]+ "].mp3");
+ 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){
+ double currentD = current;
+ double totalD = total;
+ return (int)((currentD/totalD)*100);
+ }
+ public static String showFileChooser() {
+ 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 void clearThumbnail(String fileName) {
+ File file = new File(fileName);
+ if (file.exists()) {
+ file.delete();
+ }
}
//download image using url
public static void downloadImage(String url, String fileName) throws IOException {
@@ -51,7 +149,11 @@ public class Main {
fos.close();
is.close();
}
-//remove all non alphanumeric characters from string
+
+ public static void showWarning(String message) {
+ JOptionPane.showMessageDialog(null, message, "JUST YOUR FRIENDLY NEIGHBORLY REMINDER", JOptionPane.WARNING_MESSAGE);
+ }
+
public static String removeNonAlphaNumeric(String str) {
return str.replaceAll("[^a-zA-Z0-9]", "");
}
@@ -59,6 +161,7 @@ public class Main {
File sourceFile = new File(source);
File destinationFile = new File(destination);
sourceFile.renameTo(destinationFile);
+ outputArea.setText(outputArea.getText()+"\n"+"Moved file to Completed Folder");
System.out.println("Moved file to Completed Folder");
}
@@ -144,6 +247,7 @@ public class Main {
if (line == null) {
break;
}
+ outputArea.setText(outputArea.getText()+"\n"+line);
System.out.println(line);
}
} catch (Exception e) {
@@ -175,5 +279,4 @@ public class Main {
return lines;
}
-
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage