Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@subratrout
Forked from callumj/hci.rb
Created January 5, 2012 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subratrout/1567187 to your computer and use it in GitHub Desktop.
Save subratrout/1567187 to your computer and use it in GitHub Desktop.
Download the Web Applications videos from Stanford's OpenClassroom. http://openclassroom.stanford.edu
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
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