Created
December 10, 2014 05:19
-
-
Save cholick/d07a43f52913b00aea6a 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
import java.util.concurrent.ConcurrentLinkedQueue | |
def results = new XmlSlurper().parse( | |
'http://www.howstuffworks.com/podcasts/stuff-you-should-know.rss'.toURL().openStream() | |
) | |
ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<String>() | |
public void download(String address) { | |
new File("downloads/${address.tokenize('/')[-1]}.mp3").withOutputStream { out -> | |
out << new URL(address).openStream() | |
} | |
} | |
results.channel.item.link.each { | |
queue.add(it as String) | |
} | |
(1..5).each { | |
Thread.start { | |
String file = queue.poll() | |
while (file) { | |
println "Downloading ${file}" | |
download(file) | |
file = queue.poll() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment