From 5428f6df5412d99a0e631d3f0f798dd04f3dc5a5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 15 Mar 2013 06:37:00 +0100 Subject: [PATCH] Identify MP3 files. --- .../net/pterodactylus/sonitus/io/IdentifyingInputStream.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/net/pterodactylus/sonitus/io/IdentifyingInputStream.java b/src/main/java/net/pterodactylus/sonitus/io/IdentifyingInputStream.java index 7cc69b0..c63e565 100644 --- a/src/main/java/net/pterodactylus/sonitus/io/IdentifyingInputStream.java +++ b/src/main/java/net/pterodactylus/sonitus/io/IdentifyingInputStream.java @@ -24,6 +24,7 @@ import java.io.InputStream; import net.pterodactylus.sonitus.data.Format; import com.google.common.base.Optional; +import com.google.common.io.ByteStreams; /** * Wrapper around an {@link InputStream} that identifies the {@link Format} of @@ -88,6 +89,14 @@ public class IdentifyingInputStream extends FilterInputStream { return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), format.get())); } + /* try MP3 now. */ + rememberingInputStream = new RememberingInputStream(rememberingInputStream.remembered()); + InputStream limitedInputStream = ByteStreams.limit(rememberingInputStream, 1048576); + format = Mp3Identifier.identify(limitedInputStream); + if (format.isPresent()) { + return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), format.get())); + } + return Optional.absent(); } -- 2.7.4