Created
September 26, 2014 03:42
-
-
Save kristianfreeman/02114da4ac2da2b33a9d to your computer and use it in GitHub Desktop.
Downloading NPR "First Listen" albums
This file contains hidden or 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
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