Skip to content

Instantly share code, notes, and snippets.

@dpetersen
Created September 28, 2008 23:33
Show Gist options
  • Save dpetersen/13518 to your computer and use it in GitHub Desktop.
Save dpetersen/13518 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
RSS_URL = "http://www.971freefm.com/pages/podcast/43.rss"
require 'rss'
require 'open-uri'
require 'rubygems'
require 'activesupport'
require 'chronic'
require 'tempfile'
day = ARGV.empty? ? Time.now : Chronic.parse(ARGV.join(" "))
class Time
def on_day?(day)
(day.beginning_of_day..day.end_of_day).include?(self)
end
end
print "Downloading File... "
rss_text = ""
open(RSS_URL) { |f| rss_text = f.read }
puts "done!"
print "Parsing File... "
rss = RSS::Parser.parse(rss_text, false)
puts "done!"
print "Processing RSS entries... "
the_days_items = rss.items.inject([]) do |items, item|
items << item if item.pubDate.on_day?(day)
items
end.reverse
puts "found #{the_days_items.length} items for #{day.to_date.to_formatted_s(:short)}.\n"
dir = Dir.tmpdir
the_days_items.each_with_index do |item, index|
puts "#{index + 1}) '#{item.description}', #{item.enclosure.length / 60} minutes"
filename = item.enclosure.url.scan(/\/(\d+)\.mp3/).flatten.first
temp_file_path = "#{dir}/#{filename}.mp3"
puts "Downloading to #{temp_file_path}..."
system("wget #{item.enclosure.url} --output-document=#{temp_file_path}")
end
print "Concatenating the MP3's from each of the items... "
system("cat #{dir}/*.mp3 > ./\"Adam Carolla Show - #{day.to_date.to_formatted_s(:short)}.mp3\"")
print "done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment