Skip to content

Instantly share code, notes, and snippets.

@jhezjkp
Created March 15, 2013 07:22
Show Gist options
  • Save jhezjkp/5168074 to your computer and use it in GitHub Desktop.
Save jhezjkp/5168074 to your computer and use it in GitHub Desktop.
railscast video download script from ery/railscasts-downloader
require 'rss'
if File.exist?("rss.index")
p 'Read rss index'
rss_string = ''
File.open('rss.index', 'r') do |file|
while line = file.gets
rss_string += line
end
end
else
p 'Downloading rss index'
rss_string = open('http://feeds.feedburner.com/railscasts').read
File.open('rss.index', 'w') {|file| file.puts rss_string }
end
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('*.mp4')
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
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