public
Last active

Downloads the latest MP3 from XLR8R

  • Download Gist
xlr8r.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#!/usr/bin/env ruby
 
# Dependencies: wget and the following gems:
require 'rubygems'
require 'feedzirra'
require 'httparty'
 
feed_url = 'http://feeds.xlr8r.com/xlr8rmp3s'
feed = Feedzirra::Feed.fetch_and_parse(feed_url)
 
mp3s = {}
 
print 'Parsing feed'
feed.entries.each do |entry|
response = HTTParty.get(entry.url)
if response.code == 200
response.body =~ /http:.*\.mp3/i
mp3s[$&] = entry.title
print '.'
end
end
 
print "\n"
 
mp3s.each do |url, title|
title = title.sub(/ "/, ' - ').sub(/"$/, '')
puts "Downloading [#{title}] from [#{url}]\n"
`wget -c "#{url}" -O "#{title}.mp3"`
end
 
=begin
 
BONUS: if you don't want/can't use wget, substitute the wget line with this block:
 
mp3 = HTTParty.get(url)
if mp3.code == 200
open("#{title}.mp3", 'wb') do |file|
file.write(mp3.body)
end
end
 
=end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.