-
-
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.
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 '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