Identify MP3 files.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 15 Mar 2013 05:37:00 +0000 (06:37 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 15 Mar 2013 05:37:00 +0000 (06:37 +0100)
src/main/java/net/pterodactylus/sonitus/io/IdentifyingInputStream.java

index 7cc69b0..c63e565 100644 (file)
@@ -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();
        }