From c0ff5b7c82fad02d7bbb229fd185c81a36108b13 Mon Sep 17 00:00:00 2001 From: potzplitz <127513690+potzplitz@users.noreply.github.com> Date: Fri, 22 Mar 2024 19:32:52 +0100 Subject: [PATCH 1/3] working on song media player added gd server api request working on player --- builds/classes/META-INF/MANIFEST.MF | 4 -- .../ExtremeDemonList/pom.properties | 7 ---- .../ExtremeDemonList/ExtremeDemonList/pom.xml | 39 ------------------- pom.xml | 5 +++ src/api/GetApiData.java | 20 ++++++++++ src/data/GuiData.java | 4 -- src/data/ManageFiles.java | 1 - src/filestructure/CreateFileStructure.java | 5 +++ src/gui/MainGUI.java | 2 +- src/gui/VerifyInfo.java | 11 +++++- src/main/Main.java | 3 +- src/media/PlaySong.java | 5 +++ src/module-info.java | 2 + 13 files changed, 50 insertions(+), 58 deletions(-) delete mode 100644 builds/classes/META-INF/MANIFEST.MF delete mode 100644 builds/classes/META-INF/maven/ExtremeDemonList/ExtremeDemonList/pom.properties delete mode 100644 builds/classes/META-INF/maven/ExtremeDemonList/ExtremeDemonList/pom.xml create mode 100644 src/api/GetApiData.java create mode 100644 src/media/PlaySong.java 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 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>ExtremeDemonList</groupId> - <artifactId>ExtremeDemonList</artifactId> - <version>0.0.1-SNAPSHOT</version> - <!-- https://mvnrepository.com/artifact/org.json/json --> - <dependencies> - <dependency> - <groupId>org.json</groupId> - <artifactId>json</artifactId> - <version>20140107</version> - </dependency> - <dependency> - <groupId>com.google.code.gson</groupId> - <artifactId>gson</artifactId> - <version>2.8.6</version> - </dependency> - <!-- https://mvnrepository.com/artifact/commons-io/commons-io --> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>2.6</version> - </dependency> - </dependencies> - <build> - <directory>${project.basedir}/builds</directory> - <sourceDirectory>src</sourceDirectory> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.10.1</version> <!-- Stelle sicher, dass diese Version Java 17 unterstützt --> - <configuration> - <release>17</release> <!-- Setze dies auf die gewünschte Java-Version --> - </configuration> - </plugin> - </plugins> - </build> -</project> diff --git a/pom.xml b/pom.xml index b165076..a477d63 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,11 @@ <groupId>com.formdev</groupId> <artifactId>flatlaf</artifactId> <version>3.4</version> +</dependency> +<dependency> + <groupId>com.alex1304.jdash</groupId> + <artifactId>jdash-client</artifactId> + <version>4.0.5</version> <!-- replace with latest version --> </dependency> </dependencies> <build> diff --git a/src/api/GetApiData.java b/src/api/GetApiData.java new file mode 100644 index 0000000..82efd9d --- /dev/null +++ b/src/api/GetApiData.java @@ -0,0 +1,20 @@ +package api; + +import jdash.client.GDClient; +import jdash.common.entity.GDLevel; + +public class GetApiData { + + public String getGDSongID(int id) { + + GDClient client = GDClient.create(); + + GDLevel level = client.findLevelById(id).block(); + + String songID = level.song().get().downloadUrl() + ""; + 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<String> 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..b2ba0b4 100644 --- a/src/filestructure/CreateFileStructure.java +++ b/src/filestructure/CreateFileStructure.java @@ -8,6 +8,7 @@ public class CreateFileStructure { File file = new File("C:\\ExtremeDemonList\\levels"); File file2 = new File("C:\\ExtremeDemonList\\completed"); + File file3 = new File("C:\\ExtremeDemonList\\index"); if(!file.isDirectory()) { file.mkdirs(); @@ -17,6 +18,10 @@ public class CreateFileStructure { file2.mkdirs(); } + if(!file3.exists()) { + file3.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..9bae0b6 100644 --- a/src/gui/VerifyInfo.java +++ b/src/gui/VerifyInfo.java @@ -1,5 +1,6 @@ package gui; +import java.awt.Button; import java.awt.Image; import java.awt.image.BufferedImage; import java.io.IOException; @@ -10,12 +11,15 @@ import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; +import api.GetApiData; + public class VerifyInfo { private static VerifyInfo instance = null; private JFrame frame; private JLabel ytthumbnail; + private Button playsong; private VerifyInfo() { frame = new JFrame("Verifikationsinfos"); @@ -34,7 +38,7 @@ 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); @@ -70,5 +74,10 @@ public class VerifyInfo { frame.add(ytthumbnail); frame.setVisible(true); + + GetApiData data = new GetApiData(); + + System.out.println(data.getGDSongID(id)); + } } 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..0f88215 --- /dev/null +++ b/src/media/PlaySong.java @@ -0,0 +1,5 @@ +package media; + +public class PlaySong { + +} diff --git a/src/module-info.java b/src/module-info.java index 137edb6..32ba37f 100644 --- a/src/module-info.java +++ b/src/module-info.java @@ -10,4 +10,6 @@ requires org.apache.commons.io; requires java.datatransfer; requires com.formdev.flatlaf; + requires jdash.client; + requires jdash.common; } \ No newline at end of file From f210f17fb1acaed4cdca98462cbffd467945e16b Mon Sep 17 00:00:00 2001 From: potzplitz <127513690+potzplitz@users.noreply.github.com> Date: Fri, 22 Mar 2024 20:27:45 +0100 Subject: [PATCH 2/3] raw media player done --- pom.xml | 7 +- src/api/GetApiData.java | 15 +++- src/filestructure/CreateFileStructure.java | 5 ++ src/gui/VerifyInfo.java | 33 ++++++-- src/media/PlaySong.java | 93 +++++++++++++++++++++- src/module-info.java | 1 + 6 files changed, 143 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index a477d63..1d66620 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,12 @@ <dependency> <groupId>com.alex1304.jdash</groupId> <artifactId>jdash-client</artifactId> - <version>4.0.5</version> <!-- replace with latest version --> + <version>4.0.5</version> +</dependency> +<dependency> + <groupId>javazoom</groupId> + <artifactId>jlayer</artifactId> + <version>1.0.1</version> </dependency> </dependencies> <build> diff --git a/src/api/GetApiData.java b/src/api/GetApiData.java index 82efd9d..0711af6 100644 --- a/src/api/GetApiData.java +++ b/src/api/GetApiData.java @@ -5,13 +5,22 @@ import jdash.common.entity.GDLevel; public class GetApiData { - public String getGDSongID(int id) { + public String getSongURL(int id) { GDClient client = GDClient.create(); - GDLevel level = client.findLevelById(id).block(); - String songID = level.song().get().downloadUrl() + ""; + 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/filestructure/CreateFileStructure.java b/src/filestructure/CreateFileStructure.java index b2ba0b4..8d57765 100644 --- a/src/filestructure/CreateFileStructure.java +++ b/src/filestructure/CreateFileStructure.java @@ -9,6 +9,7 @@ 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(); @@ -22,6 +23,10 @@ public class CreateFileStructure { file3.mkdirs(); } + if(!file4.exists()) { + file4.mkdirs(); + } + } } diff --git a/src/gui/VerifyInfo.java b/src/gui/VerifyInfo.java index 9bae0b6..0dbd2a6 100644 --- a/src/gui/VerifyInfo.java +++ b/src/gui/VerifyInfo.java @@ -2,6 +2,8 @@ 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; @@ -12,6 +14,7 @@ import javax.swing.JFrame; import javax.swing.JLabel; import api.GetApiData; +import media.PlaySong; public class VerifyInfo { @@ -20,15 +23,36 @@ public class VerifyInfo { 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("Song 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() { @@ -42,6 +66,7 @@ public class VerifyInfo { 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; @@ -73,11 +98,7 @@ public class VerifyInfo { } frame.add(ytthumbnail); + frame.add(playsong); frame.setVisible(true); - - GetApiData data = new GetApiData(); - - System.out.println(data.getGDSongID(id)); - } } diff --git a/src/media/PlaySong.java b/src/media/PlaySong.java index 0f88215..55276a5 100644 --- a/src/media/PlaySong.java +++ b/src/media/PlaySong.java @@ -1,5 +1,96 @@ package media; -public class PlaySong { +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 32ba37f..b577c5f 100644 --- a/src/module-info.java +++ b/src/module-info.java @@ -12,4 +12,5 @@ requires com.formdev.flatlaf; requires jdash.client; requires jdash.common; + requires jlayer; } \ No newline at end of file From bcf0e75db1323c7695dd9ddd7f50aee09999a146 Mon Sep 17 00:00:00 2001 From: potzplitz <127513690+potzplitz@users.noreply.github.com> Date: Fri, 22 Mar 2024 20:34:01 +0100 Subject: [PATCH 3/3] small update --- src/gui/VerifyInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/VerifyInfo.java b/src/gui/VerifyInfo.java index 0dbd2a6..1547af5 100644 --- a/src/gui/VerifyInfo.java +++ b/src/gui/VerifyInfo.java @@ -31,7 +31,7 @@ public class VerifyInfo { private VerifyInfo() { frame = new JFrame("Mehr Infos"); ytthumbnail = new JLabel(); - playsong = new Button("Song abspielen"); + playsong = new Button("Songpreview abspielen"); playsong.setBounds(90, 200, 200 ,30);