Skip to content

Instantly share code, notes, and snippets.

@malavbhavsar
Forked from windix/gist:2970224
Last active December 23, 2015 01:09
Show Gist options
  • Save malavbhavsar/6558871 to your computer and use it in GitHub Desktop.
Save malavbhavsar/6558871 to your computer and use it in GitHub Desktop.
require 'bundler/setup'
require 'mechanize'
require 'open-uri'
agent = Mechanize.new
# agent.set_proxy 'localhost', 3128
# login
agent.get('https://www.codeschool.com/users/sign_in') do |page|
result = page.form_with(:action => '/users/sign_in') do |form|
form['user[login]'] = 'username'
form['user[password]'] = 'password'
end.submit
end
agent.get('http://www.codeschool.com/code_tv') do |page|
page.parser.css('article.screencast h4 a').each do |link|
video_name = link['href'].split('/').last
puts "Downloading #{video_name} ... "
next if File.exists?("#{video_name}.mp4")
agent.get("http://www.codeschool.com/code_tv/#{video_name}") do |page|
video = agent.get_file("http://www.codeschool.com/code_tv/#{video_name}/download?version=sd")
File.open("#{video_name}.mp4", 'w') do |f|
f.write(video)
end
#GC.start
video = nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment