diff --git a/builds/classes/META-INF/MANIFEST.MF b/builds/classes/META-INF/MANIFEST.MF deleted file mode 100644 index b55046a..0000000 --- a/builds/classes/META-INF/MANIFEST.MF +++ /dev/null @@ -1,4 +0,0 @@ -Manifest-Version: 1.0 -Build-Jdk-Spec: 17 -Created-By: Maven Integration for Eclipse - diff --git a/builds/classes/META-INF/maven/ExtremeDemonList/ExtremeDemonList/pom.properties b/builds/classes/META-INF/maven/ExtremeDemonList/ExtremeDemonList/pom.properties deleted file mode 100644 index 5e042ce..0000000 --- a/builds/classes/META-INF/maven/ExtremeDemonList/ExtremeDemonList/pom.properties +++ /dev/null @@ -1,7 +0,0 @@ -#Generated by Maven Integration for Eclipse -#Sun Mar 03 02:06:38 CET 2024 -m2e.projectLocation=C\:\\Users\\jansc\\eclipse-workspace\\ExtremeDemonList -m2e.projectName=ExtremeDemonList -groupId=ExtremeDemonList -artifactId=ExtremeDemonList -version=0.0.1-SNAPSHOT diff --git a/builds/classes/META-INF/maven/ExtremeDemonList/ExtremeDemonList/pom.xml b/builds/classes/META-INF/maven/ExtremeDemonList/ExtremeDemonList/pom.xml deleted file mode 100644 index e75641c..0000000 --- a/builds/classes/META-INF/maven/ExtremeDemonList/ExtremeDemonList/pom.xml +++ /dev/null @@ -1,39 +0,0 @@ - - 4.0.0 - ExtremeDemonList - ExtremeDemonList - 0.0.1-SNAPSHOT - - - - org.json - json - 20140107 - - - com.google.code.gson - gson - 2.8.6 - - - - commons-io - commons-io - 2.6 - - - - ${project.basedir}/builds - src - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - 17 - - - - - diff --git a/pom.xml b/pom.xml index b165076..1d66620 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,16 @@ com.formdev flatlaf 3.4 + + + com.alex1304.jdash + jdash-client + 4.0.5 + + + javazoom + jlayer + 1.0.1 diff --git a/src/api/GetApiData.java b/src/api/GetApiData.java new file mode 100644 index 0000000..0711af6 --- /dev/null +++ b/src/api/GetApiData.java @@ -0,0 +1,29 @@ +package api; + +import jdash.client.GDClient; +import jdash.common.entity.GDLevel; + +public class GetApiData { + + public String getSongURL(int id) { + + GDClient client = GDClient.create(); + GDLevel level = client.findLevelById(id).block(); + + String url = level.song().get().downloadUrl() + ""; + url = url.substring(url.indexOf("[") + 1, url.length() - 1); + + return url; + } + + public String getSongID(int id) { + GDClient client = GDClient.create(); + GDLevel level = client.findLevelById(id).block(); + + String songID = level.songId().get() + ""; + songID = songID.substring(songID.indexOf("[") + 1, songID.length() - 1); + + return songID; + } + +} diff --git a/src/data/GuiData.java b/src/data/GuiData.java index e485b29..6d05b9a 100644 --- a/src/data/GuiData.java +++ b/src/data/GuiData.java @@ -25,10 +25,6 @@ public class GuiData { private FetchData data = new FetchData(); - public void setId(ArrayList id) { - this.id = id; - } - private int localLength; public int getLocalLength() { diff --git a/src/data/ManageFiles.java b/src/data/ManageFiles.java index 0199bdf..85dddcb 100644 --- a/src/data/ManageFiles.java +++ b/src/data/ManageFiles.java @@ -28,7 +28,6 @@ public class ManageFiles { fetch.getGithubString(); - for(int i = 0; i < fetch.allLevels().size(); i++) { File file = new File("C:\\ExtremeDemonList\\levels\\" + fetch.allLevels().get(i) + ".json"); diff --git a/src/filestructure/CreateFileStructure.java b/src/filestructure/CreateFileStructure.java index 9369459..8d57765 100644 --- a/src/filestructure/CreateFileStructure.java +++ b/src/filestructure/CreateFileStructure.java @@ -8,6 +8,8 @@ public class CreateFileStructure { File file = new File("C:\\ExtremeDemonList\\levels"); File file2 = new File("C:\\ExtremeDemonList\\completed"); + File file3 = new File("C:\\ExtremeDemonList\\index"); + File file4 = new File("C:\\ExtremeDemonList\\songs"); if(!file.isDirectory()) { file.mkdirs(); @@ -17,6 +19,14 @@ public class CreateFileStructure { file2.mkdirs(); } + if(!file3.exists()) { + file3.mkdirs(); + } + + if(!file4.exists()) { + file4.mkdirs(); + } + } } diff --git a/src/gui/MainGUI.java b/src/gui/MainGUI.java index de9b6f3..b5fa262 100644 --- a/src/gui/MainGUI.java +++ b/src/gui/MainGUI.java @@ -204,7 +204,7 @@ public class MainGUI { public void actionPerformed(ActionEvent e) { String url = data.getYoutubeLink().get(index); VerifyInfo ver = VerifyInfo.getInstance(); - ver.showInfo(url); + ver.showInfo(url, Integer.parseInt(data.getId().get(index))); } }); diff --git a/src/gui/VerifyInfo.java b/src/gui/VerifyInfo.java index 2d8a33c..1547af5 100644 --- a/src/gui/VerifyInfo.java +++ b/src/gui/VerifyInfo.java @@ -1,6 +1,9 @@ package gui; +import java.awt.Button; import java.awt.Image; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.IOException; import java.net.URL; @@ -10,21 +13,46 @@ import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; +import api.GetApiData; +import media.PlaySong; + public class VerifyInfo { private static VerifyInfo instance = null; private JFrame frame; private JLabel ytthumbnail; + private Button playsong; + private int currentSongId; // Instanzvariable für die ID + + private PlaySong player; + private GetApiData data; private VerifyInfo() { - frame = new JFrame("Verifikationsinfos"); + frame = new JFrame("Mehr Infos"); ytthumbnail = new JLabel(); + playsong = new Button("Songpreview abspielen"); + + playsong.setBounds(90, 200, 200 ,30); frame.setSize(400, 300); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setLayout(null); + + player = new PlaySong(); + data = new GetApiData(); + + playsong.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + playSongAction(); + } + }); + } + + private void playSongAction() { + player.play(data.getSongURL(currentSongId), data.getSongID(currentSongId)); // Verwende die Instanzvariable für die ID } public static VerifyInfo getInstance() { @@ -34,10 +62,11 @@ public class VerifyInfo { return instance; } - public void showInfo(String url) { + public void showInfo(String url, int id) { frame.getContentPane().removeAll(); // Clear previous content ytthumbnail.setBounds(90, 70, 200, 110); + currentSongId = id; // Setze die Instanzvariable auf die aktuelle ID if (url != null && url.contains("v=")) { int startIndex = url.indexOf("v=") + 2; @@ -69,6 +98,7 @@ public class VerifyInfo { } frame.add(ytthumbnail); + frame.add(playsong); frame.setVisible(true); } } diff --git a/src/main/Main.java b/src/main/Main.java index aa2f439..1e1116a 100644 --- a/src/main/Main.java +++ b/src/main/Main.java @@ -4,6 +4,7 @@ import java.io.IOException; import javax.swing.UnsupportedLookAndFeelException; +import api.GetApiData; import data.FetchData; import data.ManageFiles; import filestructure.CreateFileStructure; @@ -29,7 +30,7 @@ public class Main { load.updateBar("Liste wird auf Updates geprüft..."); ManageFiles manager = new ManageFiles(); - manager.compareArrays(); + manager.compareArrays(); load.updateBar("Ladevorgang abgeschlossen"); load.close(); diff --git a/src/media/PlaySong.java b/src/media/PlaySong.java new file mode 100644 index 0000000..55276a5 --- /dev/null +++ b/src/media/PlaySong.java @@ -0,0 +1,96 @@ +package media; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; + +import javazoom.jl.decoder.JavaLayerException; +import javazoom.jl.player.advanced.AdvancedPlayer; + +public class PlaySong { + + public void play(String link, String id) { + checkExisting(id, link); + } + + private synchronized void checkExisting(String songId, String link) { + String path = "C:/ExtremeDemonList/songs/" + songId + ".mp3"; + File file = new File(path); + + if(file.exists()) { + playSong(path); + } else { + downloadSong(link, songId); + playSong(path); + System.out.println("nein"); + } + } + + private void playSong(String path) { + String filePath = path; // Passe den Pfad zu deiner MP3-Datei an + + try { + FileInputStream fis = new FileInputStream(filePath); + AdvancedPlayer player = new AdvancedPlayer(fis); + + // Starte das Abspielen in einem neuen Thread, damit der Hauptthread nicht blockiert wird + Thread playerThread = new Thread(() -> { + try { + player.play(); + } catch (JavaLayerException e) { + e.printStackTrace(); + } + }); + + playerThread.start(); + + // Gib dem Player Zeit, die MP3-Datei abzuspielen + Thread.sleep(10000); // Zum Beispiel 10 Sekunden abwarten + + // Beende den Player und schließe die FileInputStream + player.close(); + fis.close(); + } catch (FileNotFoundException | JavaLayerException | InterruptedException e) { + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + private void downloadSong(String link, String id) { + try { + URL url = new URL(link); + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + int responseCode = httpConn.getResponseCode(); + + if (responseCode == HttpURLConnection.HTTP_OK) { + InputStream inputStream = httpConn.getInputStream(); + String saveFilePath = "C:/ExtremeDemonList/songs/" + id + ".mp3"; + + FileOutputStream outputStream = new FileOutputStream(saveFilePath); + + int bytesRead; + byte[] buffer = new byte[4096]; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + + outputStream.close(); + inputStream.close(); + + } else { + System.out.println("Der Server hat mit dem Statuscode " + responseCode + " geantwortet."); + } + httpConn.disconnect(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/module-info.java b/src/module-info.java index 137edb6..b577c5f 100644 --- a/src/module-info.java +++ b/src/module-info.java @@ -10,4 +10,7 @@ requires org.apache.commons.io; requires java.datatransfer; requires com.formdev.flatlaf; + requires jdash.client; + requires jdash.common; + requires jlayer; } \ No newline at end of file