Skip to content

Instantly share code, notes, and snippets.

@armatures
Forked from tippenein/gist:5328240
Last active December 15, 2015 21:49
Show Gist options
  • Select an option

  • Save armatures/5328352 to your computer and use it in GitHub Desktop.

Select an option

Save armatures/5328352 to your computer and use it in GitHub Desktop.
Ruby script to grab podcasts from KFAI's Jet Set Planet radio show. Updated to check if files are already in current directory before downloading.
require 'net/http'
require 'open-uri'
uri = URI('http://kfai.org/jet-set-planet')
body = Net::HTTP.get(uri)
body.scan(/https?:\/\/[\S]+.mp3/).each do |link|
filename = link.match(/([^\/]+$)/)
current_directory = Dir.getwd
unless(Dir.entries(current_directory).include? filename.to_s)
puts "new file is available: #{filename.to_s}"
puts "pulling from #{link}"
open(filename.to_s, 'wb') do |file|
puts "saving #{filename.to_s}"
file << open(link).read
end
else
puts "file #{filename.to_s} is already present in current directory. Skipping download.\ncurrent directory: #{current_directory}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment