Skip to content

Instantly share code, notes, and snippets.

@kristianfreeman
Created September 26, 2014 03:42
Show Gist options
  • Save kristianfreeman/02114da4ac2da2b33a9d to your computer and use it in GitHub Desktop.
Save kristianfreeman/02114da4ac2da2b33a9d to your computer and use it in GitHub Desktop.
Downloading NPR "First Listen" albums
require 'nokogiri'
require 'open-uri'
# for url - http://ask.metafilter.com/187877/How-to-download-audio-from-NPR-stream
url = 'http://api.npr.org/query?id=1039&fields=titles,audio,show&sort=assigned&apiKey=MDAzMzQ2MjAyMDEyMzk4MTU1MDg3ZmM3MQ010'
doc = Nokogiri::XML(open(url))
doc.xpath('//mp3').each do |file|
url = file.text.strip
if url.include?("/fl/") && url.include?('.mp3') # Is it a "first listen" mp3?
filename = URI(url).path.split('/').last
`curl -o #{filename} #{url}`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment