Created
March 29, 2010 21:35
-
-
Save raymyers/348441 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.cadrlife; | |
import java.util.Arrays; | |
import java.util.LinkedHashMap; | |
import java.util.List; | |
public class SampleGet { | |
public static void main(String[] args) { | |
final JGet jGet = new JGet(); | |
final LinkedHashMap<String, List<String>> families = new LinkedHashMap<String, List<String>>(); | |
families.put("strings", Arrays.asList("violin", "viola", "cello", "double bass")); | |
families.put("woodwind", Arrays.asList("flute", "oboe", "english horn", "clarinet", "bass clarinet", "bassoon", "contrabassoon", "saxophone")); | |
families.put("brass", Arrays.asList("french horn", "trumpet", "trombone", "tuba")); | |
final List<String> notes = Arrays.asList("C", "Db", "D", "Eb", "F", "Gb", "G", "Ab", "A", "Bb", "B"); | |
final List<Integer> octaves = Arrays.asList( 1, 2, 3, | |
4, | |
5, 6, 7, 8); | |
final List<String> durations = Arrays.asList("short", "medium", "long"); | |
final List<String> dynamics = Arrays.asList("soft", "medium", "loud"); | |
for (String family : families.keySet()) { | |
for (String instrument : families.get(family)) { | |
for (Integer octave : octaves) { | |
for (String note : notes) { | |
for (String duration : durations) { | |
for (String dynamic : dynamics) { | |
String got = jGet.get(createUrl(family, instrument, note, octave, duration, dynamic)); | |
final String[] split = got.split("</object><p><a href=\""); | |
final String fileName = createFileName(family, instrument, octave, note, duration, dynamic); | |
if (split.length < 2) { | |
System.out.println("# " + fileName + " Not found"); | |
} else { | |
final String sampleUrl = split[1].substring(0, split[1].indexOf("\"")); | |
found(family, fileName, sampleUrl); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
private static void found(String family, String fileName, String sampleUrl) { | |
final String newWavFileName = fileName.replaceAll("\\.mp3$", ".wav"); | |
final String oldWavFileName = sampleUrl.replaceAll("%20", " ").replace("http://slib.soundex.co.uk/samples/", family + "/").replaceAll("\\.mp3$", ".wav"); | |
System.out.println("mv " + oldWavFileName + " " + newWavFileName); | |
} | |
private static String createFileName(String family, String instrument, Integer octave, String note, String duration, String dynamic) { | |
final String fileName = family + "/" + instrument + "/" + instrument + "-" + note + octave + "-" + duration + "_duration-" + dynamic + "_dynamic.mp3"; | |
return fileName; | |
} | |
private static String createUrl(String family, String instrument, String note, Integer octave, String duration, String dynamic) { | |
final String url = "http://slib.soundex.co.uk/slib.jsp?page=queryresultlite_nocookie.jsp&familyName=" | |
+ family + "&instrumentName=" + instrument + "¬e=" + note + "®=" + octave + "&durationName=" + duration + "&dynamicName=" + dynamic; | |
return url.replaceAll(" ", "%20"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment