Skip to content

Instantly share code, notes, and snippets.

@fzero
Created October 31, 2012 17:09
Show Gist options
  • Save fzero/3988374 to your computer and use it in GitHub Desktop.
Save fzero/3988374 to your computer and use it in GitHub Desktop.
Downloads the latest MP3 from XLR8R
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment