Skip to content

Instantly share code, notes, and snippets.

@yoonwaiyan
Forked from windix/gist:2970224
Created March 7, 2016 06:09
Show Gist options
  • Save yoonwaiyan/679b45b92085d23b8506 to your computer and use it in GitHub Desktop.
Save yoonwaiyan/679b45b92085d23b8506 to your computer and use it in GitHub Desktop.
Download codetv videos from codeschool.com (account required)
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.codetv h3 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