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