Skip to content

Instantly share code, notes, and snippets.

@rabnawazPikesSoft
Forked from samqiu/railscasts.rb
Created November 23, 2015 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rabnawazPikesSoft/1b689758d9dd10019183 to your computer and use it in GitHub Desktop.
Save rabnawazPikesSoft/1b689758d9dd10019183 to your computer and use it in GitHub Desktop.
Download free Railscast video
#!/usr/bin/ruby
require 'rss'
# Usage
# $ ./railscasts.rb http://railscasts.com/subscriptions/YOURRAILSCASTRSS/\/
# episodes.rss
# OR
# $ ./railscasts.rb
p 'Downloading rss index'
rss_url = ARGV.first ? ARGV.first : 'http://feeds.feedburner.com/railscasts'
rss_string = open(rss_url).read
rss = RSS::Parser.parse(rss_string, false)
videos_urls = rss.items.map { |it| it.enclosure.url }.reverse
videos_filenames = videos_urls.map { |url| url.split('/').last }
existing_filenames = Dir.glob('*.mov')
missing_filenames = videos_filenames - existing_filenames
p "Downloading #{missing_filenames.size} missing videos"
missing_videos_urls = videos_urls.select { |video_url|
missing_filenames.any? { |filename| video_url.match filename }
}
missing_videos_urls.each do |video_url|
filename = video_url.split('/').last
next if File.exists? filename
p filename
p %x(wget #{video_url} -O #{filename}.tmp )
p %x(mv #{filename}.tmp #{filename} )
end
p 'Finished synchronization'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment