-
-
Save yoonwaiyan/679b45b92085d23b8506 to your computer and use it in GitHub Desktop.
Download codetv videos from codeschool.com (account required)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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