Skip to content

@fzero /xlr8r.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.