Last active
August 29, 2015 14:02
-
-
Save kristianfreeman/7839dcf519de94c90295 to your computer and use it in GitHub Desktop.
batch download for nsscreencasts
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' | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've commented out the
.env
loading because it's sloppy but it worked for me without having to importdotenv
or something similar. Just make sureNS_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!