Skip to content

Instantly share code, notes, and snippets.

@orlando
Created November 21, 2011 15:12
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 orlando/1382908 to your computer and use it in GitHub Desktop.
Save orlando/1382908 to your computer and use it in GitHub Desktop.
Railscasts downloader
#!/usr/bin/ruby
require 'rss'
p 'Downloading rss index'
rss_string = open('http://feeds.feedburner.com/railscasts').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 }
videos_filenames_fixed = videos_filenames.map {|video| video.split('-').first }
existing_filenames_mov = Dir.glob('*.mov')
existing_filenames_mp4 = Dir.glob('*.mp4')
existing_filenames_fixed = existing_filenames_mov.map {|video| video.split('_').first }
existing_filenames_fixed << existing_filenames_mp4.map {|video| video.split('-').first }
existing_filenames_fixed.flatten!.sort.uniq!
missing_filenames = videos_filenames_fixed - existing_filenames_fixed
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
p filename
p %x(wget -c #{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