Skip to content

Instantly share code, notes, and snippets.

@cholick
Created December 10, 2014 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cholick/d07a43f52913b00aea6a to your computer and use it in GitHub Desktop.
Save cholick/d07a43f52913b00aea6a to your computer and use it in GitHub Desktop.
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