Created
April 7, 2013 13:42
-
-
Save modsaid/5330545 to your computer and use it in GitHub Desktop.
Ruby script for downloading rails casts
http://blog.modsaid.com/2010/02/ruby-script-for-downloading-rails-casts.html this has been posted 3 years ago actually
This file contains 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
#!/usr/local/bin/ruby | |
# A script to download the latest episodes from railscasts.com | |
# | |
# requires simple-rss (1.2.2) gem | |
# and base on linux wget | |
# | |
# author: modsaid < [email protected] > | |
# | |
require 'rubygems' | |
require 'simple-rss' | |
require 'open-uri' | |
RAILS_CASTS_FEED='http://feeds.feedburner.com/railscasts' | |
DOWNLOAD_DIRECTORY='.' | |
# parse the current directory and get the downloaded eposodes ids | |
downloaded_episodes_ids=[] | |
begin | |
downloaded_episodes_ids = Dir.new(DOWNLOAD_DIRECTORY).entries.select{|f| f =~ /^(\d){3}.*.mov/ }.collect{|f| f.split('_').first.to_i} | |
rescue | |
end | |
def get_id(rss_item) | |
rss_item.link.split('/').last.split('-').first.to_i | |
end | |
puts "Checking railscasts feeds for new episodes..." | |
rss = SimpleRSS.parse open(RAILS_CASTS_FEED) | |
count=0 | |
rss.items.each do |rss_item| | |
id = get_id(rss_item) | |
unless downloaded_episodes_ids.include?(id) | |
puts "Downloading #{rss_item.title}.." | |
link = `wget http://railscasts.com/episodes/#{id} -O- | grep -oi 'http://media.railscasts.com/videos/[a-z_0-9]*.mov'` | |
`wget -c #{link.strip}` | |
count +=1 | |
end | |
end | |
puts "Done. #{count} new episodes were downloaded" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment