change to land.chipmunk.chayapak because yes

This commit is contained in:
ChomeNS
2023-03-27 12:53:05 +07:00
parent cb34dfff90
commit fbf9f3e2f1
70 changed files with 221 additions and 220 deletions

View File

@@ -1,73 +0,0 @@
package me.chayapak1.chomens_bot.song;
import me.chayapak1.chomens_bot.Bot;
import me.chayapak1.chomens_bot.plugins.MusicPlayerPlugin;
import me.chayapak1.chomens_bot.util.DownloadUtilities;
import net.kyori.adventure.text.Component;
import java.io.File;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Files;
import java.nio.file.Paths;
public class SongLoaderThread extends Thread {
private String location;
private File songPath;
private URL songUrl;
public SongLoaderException exception;
public Song song;
private Bot bot;
private boolean isUrl = false;
public SongLoaderThread (URL location, Bot bot) throws SongLoaderException {
this.bot = bot;
isUrl = true;
songUrl = location;
}
public SongLoaderThread (Path location, Bot bot) throws SongLoaderException {
this.bot = bot;
isUrl = false;
songPath = location.toFile();
}
public void run () {
byte[] bytes;
String name;
try {
if (isUrl) {
bytes = DownloadUtilities.DownloadToByteArray(songUrl, 10*1024*1024);
name = Paths.get(songUrl.toURI().getPath()).getFileName().toString();
} else {
bytes = Files.readAllBytes(songPath.toPath());
name = songPath.getName();
}
} catch (Exception e) {
e.printStackTrace();
exception = new SongLoaderException(Component.text(e.getMessage()), e);
return;
}
try {
song = MidiConverter.getSongFromBytes(bytes, name, bot);
} catch (Exception e) {
}
if (song == null) {
try {
song = NBSConverter.getSongFromBytes(bytes, name, bot);
} catch (Exception e) {
}
}
if (song == null) {
exception = new SongLoaderException(Component.translatable("Invalid format"));
}
}
private File getSongFile (String name) {
return new File(MusicPlayerPlugin.SONG_DIR, name);
}
}