Skip to content

Instantly share code, notes, and snippets.

@kristianfreeman
Last active August 29, 2015 14:02
Show Gist options
  • Save kristianfreeman/7839dcf519de94c90295 to your computer and use it in GitHub Desktop.
Save kristianfreeman/7839dcf519de94c90295 to your computer and use it in GitHub Desktop.
batch download for nsscreencasts
require 'nokogiri'
require 'open-uri'
# if File.exist?(".env")
# `source .env`
# else
# puts "Couldn't find '.env'. Make sure NS_FEED env. variable is set."
# end
FEED = ENV["NS_FEED"]
doc = Nokogiri::XML(open(FEED))
urls = doc.
search("link[@rel='enclosure']").
map { |i|
i.attr('href')
}
urls.each do |url|
puts "Downloading #{ url }."
`wget #{ url } -nv`
end
@kristianfreeman
Copy link
Author

I've commented out the .env loading because it's sloppy but it worked for me without having to import dotenv or something similar. Just make sure NS_FEED is set, and you'll be good.

Note that this doesn't cover file renaming - the files will have key params attached to them. Renaming is a pretty simple task that I didn't feel necessary to include here. Know your regex!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment