X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fdemoscenemusic%2Futils%2FAudioCodecs.java;h=a543e30b1d893cd5d05fe9bfc8d121b0a439de7e;hb=c01208917a2c53a0703f2ab5ca3dbc16d51f5bb7;hp=f09e79fb36a541aa45e768974519818f010915d8;hpb=61c649c53893188489d713374eccc240e3b2ea15;p=demoscenemusic.git diff --git a/src/main/java/net/pterodactylus/demoscenemusic/utils/AudioCodecs.java b/src/main/java/net/pterodactylus/demoscenemusic/utils/AudioCodecs.java index f09e79f..a543e30 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/utils/AudioCodecs.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/utils/AudioCodecs.java @@ -36,8 +36,39 @@ public class AudioCodecs { codecDescriptions.put("aac", new AudioCodecDescription("aac", "Advanced Audio Coding", "AAC", "audio/x-aac", true, false)); codecDescriptions.put("flac", new AudioCodecDescription("flac", "Free Lossless Audio Codec", "FLAC", "audio/ogg", true, true)); codecDescriptions.put("wav", new AudioCodecDescription("wav", "Waveform Audio", "WAV", "audio/vnc.wave", true, true)); - codecDescriptions.put("mod", new AudioCodecDescription("mod", "Module", "MOD", "audio/mod", false, true)); + codecDescriptions.put("mod", new AudioCodecDescription("mod", "ProTracker Module", "MOD", "audio/mod", false, true)); codecDescriptions.put("ft2", new AudioCodecDescription("ft2", "FastTracker II Module", "XM", "audio/xm", false, true)); + codecDescriptions.put("it", new AudioCodecDescription("it", "Impulse Tracker Module", "IT", "audio/it", false, true)); + codecDescriptions.put("s3m", new AudioCodecDescription("s3m", "Scream Tracker 3 Module", "S3M", "audio/s3m", false, true)); + } + + /** + * Tries to automatically detect the audio codec from the filename. In most + * cases this will match the {@link AudioCodecDescription#code} of the codec + * but in some cases other extensions are possible, too. Also, on Amiga + * filenames usually start with the extension (mod files are often named + * “mod.somethingsomethingsomethingdarkside”). + * + * @param filename + * The name of the file + * @return The audio codec of the file, or {@code null} if no codec could be + * detected + */ + public static AudioCodecDescription detect(String filename) { + String extension = filename.substring(filename.lastIndexOf('.') + 1).toLowerCase(); + if (codecDescriptions.containsKey(extension)) { + return codecDescriptions.get(extension); + } + if (extension.equals("ogg")) { + return codecDescriptions.get("vorbis"); + } + if (extension.equals("mp4")) { + return codecDescriptions.get("aac"); + } + if (extension.equals("xm")) { + return codecDescriptions.get("ft2"); + } + return null; } /** @@ -94,6 +125,18 @@ public class AudioCodecs { this.lossless = lossless; } + // + // OBJECT METHODS + // + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return String.format("AudioCodec[%s,%s,%s,%s,%s,%s]", code, name, shortName, mimeType, streaming, lossless); + } + } }