Set automatically detected codec on new derivatives.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 30 Jul 2012 10:02:17 +0000 (12:02 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 30 Jul 2012 10:02:17 +0000 (12:02 +0200)
src/main/java/net/pterodactylus/demoscenemusic/page/admin/AddTrackDerivativePage.java

index e1a8d0a..620d302 100644 (file)
@@ -29,6 +29,8 @@ import net.pterodactylus.demoscenemusic.core.Core;
 import net.pterodactylus.demoscenemusic.data.Track;
 import net.pterodactylus.demoscenemusic.data.TrackDerivative;
 import net.pterodactylus.demoscenemusic.page.ServletRequest;
+import net.pterodactylus.demoscenemusic.utils.AudioCodecs;
+import net.pterodactylus.demoscenemusic.utils.AudioCodecs.AudioCodecDescription;
 import net.pterodactylus.util.database.DatabaseException;
 import net.pterodactylus.util.io.Closer;
 import net.pterodactylus.util.io.StreamCopier;
@@ -122,6 +124,10 @@ public class AddTrackDerivativePage extends AdminBasePage {
                                        if (filename.indexOf('.') > filename.lastIndexOf('/')) {
                                                derivative.getProperties().set("file/extension", filename.substring(filename.lastIndexOf('.') + 1));
                                        }
+                                       AudioCodecDescription audioCodecDescription = AudioCodecs.detect(filename);
+                                       if (audioCodecDescription != null) {
+                                               derivative.getProperties().set("audio/codec", audioCodecDescription.code);
+                                       }
                                        /* TODO - identify file type and media information */
                                        getCore().getDataManager().saveTrackDerivate(derivative);