Created
          October 23, 2011 14:20 
        
      - 
      
- 
        Save callumj/1307409 to your computer and use it in GitHub Desktop. 
    Download the Web Applications videos from Stanford's OpenClassroom. http://openclassroom.stanford.edu
  
        
  
    
      This file contains hidden or 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 'uri' | |
| require 'net/http' | |
| require 'fileutils' | |
| BASE = "http://openclassroom.stanford.edu/MainFolder/courses/HCI/videos/" | |
| for l in 1..42 do | |
| for p in 1..20 do | |
| uri = "CS147L" + l.to_s + "P" + p.to_s + ".flv" | |
| uri_obj = URI.parse(BASE + uri) | |
| success = false | |
| count = 0 | |
| while (!(File.exists?(uri)) && !(File.exists?("#{uri}.lock")) && !success) do | |
| begin | |
| FileUtils.touch("#{uri}.lock") | |
| res = Net::HTTP.start(uri_obj.host, uri_obj.port) do |http| | |
| head_data = http.head(uri_obj.path) | |
| if head_data.code.eql?("200") | |
| puts "Getting contents of #{uri}" | |
| http.get(uri_obj.path) | |
| else | |
| nil | |
| end | |
| end | |
| if (res != nil && res.body != nil) | |
| puts "Writing #{uri} to file" | |
| open(uri, "wb") { |file| file.write(res.body) } | |
| end | |
| success = true | |
| rescue | |
| puts "Pull failed, retrying" | |
| count = count + 1 | |
| success = true if count > 5 | |
| end | |
| FileUtils.rm_f("#{uri}.lock") if File.exists?("#{uri}.lock") | |
| end | |
| puts "File #{uri} in place" if File.exists?(uri) | |
| end | |
| end | 
  
    
      This file contains hidden or 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 'uri' | |
| require 'net/http' | |
| require 'fileutils' | |
| BASE = "http://openclassroom.stanford.edu/MainFolder/courses/WebApplications/videos/" | |
| for l in 1..42 do | |
| for p in 1..20 do | |
| uri = "CS142L" + l.to_s + "P" + p.to_s + ".flv" | |
| uri_obj = URI.parse(BASE + uri) | |
| success = false | |
| count = 0 | |
| while (!(File.exists?(uri)) && !(File.exists?("#{uri}.lock")) && !success) do | |
| begin | |
| FileUtils.touch("#{uri}.lock") | |
| res = Net::HTTP.start(uri_obj.host, uri_obj.port) do |http| | |
| head_data = http.head(uri_obj.path) | |
| if head_data.code.eql?("200") | |
| puts "Getting contents of #{uri}" | |
| http.get(uri_obj.path) | |
| else | |
| nil | |
| end | |
| end | |
| if (res != nil && res.body != nil) | |
| puts "Writing #{uri} to file" | |
| open(uri, "wb") { |file| file.write(res.body) } | |
| end | |
| success = true | |
| rescue | |
| puts "Pull failed, retrying" | |
| count = count + 1 | |
| success = true if count > 5 | |
| end | |
| FileUtils.rm_f("#{uri}.lock") if File.exists?("#{uri}.lock") | |
| end | |
| puts "File #{uri} in place" if File.exists?(uri) | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment