import java.util.*; import java.io.*; import java.net.*; public class downloadPodcast { public static void getPodcast(String xmlFeed) throws Exception { try { String mp3URL=""; String proxy = "proxy.yourcompany.org"; String port = "8080"; Properties systemProperties = System.getProperties(); //systemProperties.setProperty("http.proxyHost",proxy); //systemProperties.setProperty("http.proxyPort",port); URL server = new URL(xmlFeed); HttpURLConnection connection = (HttpURLConnection)server.openConnection(); // You might need to spoof some settings: browser (user-agent), referer, and operating system connection.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows XP)"); connection.setRequestProperty("Referer","http://www.google.com"); connection.setRequestProperty("ua-os", "Windows XP"); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.connect(); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; while ((line = in.readLine()) != null) { if (line.indexOf(".mp3") > -1) { mp3URL= line.substring(line.indexOf("http://"), line.indexOf(".mp3")+4); System.out.println(mp3URL); downloadMP3(mp3URL); } // end of if } // end of while loop in.close(); } // end of try catch ( IOException e ) { e.printStackTrace(); } } // end of getPodcast public static void downloadMP3(String address) { String localFileName = address.substring(address.lastIndexOf("/")+1,address.length()); // Change the naming format to YYYYMMDD_the_dave_ramsey_show_podcast.mp3 if (localFileName.indexOf("ramsey")>-1) localFileName=localFileName.substring(4,8)+localFileName.substring(0,4)+localFileName.substring(8,localFileName.length()); OutputStream out = null; URLConnection conn = null; InputStream in = null; try { URL url = new URL(address); Properties systemProperties = System.getProperties(); //systemProperties.setProperty("http.proxyHost","proxy.yourcompany.org"); //systemProperties.setProperty("http.proxyPort","8080"); out = new BufferedOutputStream(new FileOutputStream(localFileName)); conn = url.openConnection(); in = conn.getInputStream(); byte[] buffer = new byte[1024]; int numRead; // 5% of the file size is about 1093565 long numWritten = 0, numTemp=546783; System.out.print("Downloading"); while ((numRead = in.read(buffer)) != -1) { out.write(buffer, 0, numRead); numWritten += numRead; if (numWritten > numTemp) { System.out.print("."); numTemp+=546783; } } // End of while loop System.out.println("\n"+localFileName + "\t" + numWritten); } catch (Exception e) { e.printStackTrace(); } finally { try { if (in != null) { in.close(); } if (out != null) { out.close(); } } catch (IOException ioe) {} } } // End of downloadMP3 public static void main(String[] args) { try{ // The Dave Ramsey podcast is the default String podcastFeed="http://www.daveramsey.com/media/audio/podcast/podcast.xml"; getPodcast(podcastFeed); } catch (Exception e) { System.out.println("An error has occurred!!!"); } } // End of main }