Changed music file metadata reader library
All checks were successful
Locusworks Team/eight-track/pipeline/head This commit looks good
All checks were successful
Locusworks Team/eight-track/pipeline/head This commit looks good
This commit is contained in:
9
pom.xml
9
pom.xml
@ -196,7 +196,7 @@
|
||||
<artifactId>hibernate-entitymanager</artifactId>
|
||||
<version>${hibernate.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0 -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
@ -317,11 +317,10 @@
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.mpatric/mp3agic -->
|
||||
<dependency>
|
||||
<groupId>com.mpatric</groupId>
|
||||
<artifactId>mp3agic</artifactId>
|
||||
<version>0.9.1</version>
|
||||
<groupId>net.jthink</groupId>
|
||||
<artifactId>jaudiotagger</artifactId>
|
||||
<version>2.2.3</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
@ -34,21 +34,22 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.UUID;
|
||||
import org.jaudiotagger.audio.AudioFile;
|
||||
import org.jaudiotagger.audio.AudioFileIO;
|
||||
import org.jaudiotagger.tag.Tag;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.mpatric.mp3agic.ID3v2;
|
||||
import com.mpatric.mp3agic.Mp3File;
|
||||
|
||||
@Component
|
||||
public class Mp3UploadHandler {
|
||||
|
||||
public Mp3UploadResults parse(Path file) throws IOException {
|
||||
InputStream is = Files.newInputStream(file);
|
||||
return parse(is);
|
||||
return parse(is, file.getFileName().toString());
|
||||
}
|
||||
|
||||
public Mp3UploadResults parse(InputStream is) throws IOException {
|
||||
public Mp3UploadResults parse(InputStream is, String fileName) throws IOException {
|
||||
byte[] data;
|
||||
String id = null;
|
||||
Path tmp = null;
|
||||
try(InputStream in = is; ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||
int read = 0;
|
||||
byte[] buffer = new byte[1024 * 1024];
|
||||
@ -57,17 +58,21 @@ public class Mp3UploadHandler {
|
||||
}
|
||||
data = baos.toByteArray();
|
||||
|
||||
id = UUID.nameUUIDFromBytes(data).toString();
|
||||
Files.write(Paths.get(id), data);
|
||||
Mp3File mp3 = new Mp3File(Paths.get(id));
|
||||
ID3v2 tag = mp3.getId3v2Tag();
|
||||
String id = UUID.nameUUIDFromBytes(data).toString();
|
||||
|
||||
tmp = Paths.get(String.format("%s_%s", id, fileName));
|
||||
|
||||
Files.write(tmp, data);
|
||||
|
||||
AudioFile f = AudioFileIO.read(tmp.toFile());
|
||||
Tag tag = f.getTag();
|
||||
|
||||
return new Mp3UploadResults(tag, data);
|
||||
} catch (Exception ex) {
|
||||
return new Mp3UploadResults(ex);
|
||||
} finally {
|
||||
if (id != null) {
|
||||
Files.deleteIfExists(Paths.get(id));
|
||||
if (tmp != null) {
|
||||
Files.deleteIfExists(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,8 @@
|
||||
*/
|
||||
package net.locusworks.discord.eighttrack.audio;
|
||||
|
||||
import com.mpatric.mp3agic.ID3v2;
|
||||
import org.jaudiotagger.tag.FieldKey;
|
||||
import org.jaudiotagger.tag.Tag;
|
||||
|
||||
public class Mp3UploadResults {
|
||||
|
||||
@ -43,7 +44,7 @@ public class Mp3UploadResults {
|
||||
private byte[] rawData;
|
||||
private Throwable err;
|
||||
|
||||
public Mp3UploadResults(ID3v2 tag, byte[] data) {
|
||||
public Mp3UploadResults(Tag tag, byte[] data) {
|
||||
parseResults(tag);
|
||||
this.rawData = data;
|
||||
}
|
||||
@ -52,15 +53,15 @@ public class Mp3UploadResults {
|
||||
this.err = err;
|
||||
}
|
||||
|
||||
private void parseResults(ID3v2 metadata) {
|
||||
genre = metadata.getGenreDescription();
|
||||
composure = metadata.getComposer();
|
||||
album = metadata.getAlbum();
|
||||
trackNumber = metadata.getTrack();
|
||||
discNumber = metadata.getPartOfSet();
|
||||
artist = metadata.getArtist();
|
||||
title = metadata.getTitle();
|
||||
releaseDate = metadata.getDate();
|
||||
private void parseResults(Tag tag) {
|
||||
genre = tag.getFirst(FieldKey.GENRE);
|
||||
composure = tag.getFirst(FieldKey.COMPOSER);
|
||||
album = tag.getFirst(FieldKey.ALBUM);
|
||||
trackNumber = tag.getFirst(FieldKey.TRACK);
|
||||
discNumber = tag.getFirst(FieldKey.DISC_NO);
|
||||
artist = tag.getFirst(FieldKey.ARTIST);
|
||||
title = tag.getFirst(FieldKey.TITLE);
|
||||
releaseDate = tag.getFirst(FieldKey.ORIGINAL_YEAR);
|
||||
}
|
||||
|
||||
public final byte[] getData() {
|
||||
|
@ -83,7 +83,7 @@ public class UploadHandler extends AbstractMainEventHandler {
|
||||
MessageEmbed embed = null;
|
||||
try {
|
||||
|
||||
res = uploadHandler.parse(in);
|
||||
res = uploadHandler.parse(in, attachment.getFileName());
|
||||
if (res.validFile()) {
|
||||
embed = persistSong(res, event, attachment.getFileName());
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user