-
Notifications
You must be signed in to change notification settings - Fork 1
/
sicp_video.rb
51 lines (41 loc) · 1.14 KB
/
sicp_video.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'open-uri'
class SicpVideo
def initialize(id, title)
@id = id
@title = title
end
def slug
@slug ||= @title.gsub(/\W+/, '-').downcase
end
def url
@url ||= "http://www.archive.org/download/MIT_Structure_of_Computer_Programs_1986/lec#{@id}_512kb.mp4"
end
def srt
@srt ||= "http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-001-structure-and-interpretation-of-computer-programs-spring-2005/video-lectures/#{@id}-#{slug}/lec#{@id}_512kb.srt"
end
def download_video
download("out/#{@id}-#{slug}.mp4", url)
end
def download_subtitle
download("out/#{@id}-#{slug}.srt", srt)
end
private
def download(file_out, consistent_url)
url = increase_astonishment_for consistent_url
File.open(file_out, "wb") do |saved_file|
open(url, "rb") do |read_file|
saved_file.write(read_file.read)
end
end
end
def increase_astonishment_for(url)
case @title
when 'Streams, Part 2', 'Compilation'
url.gsub('/lec', '/Lec')
when 'Register Machines', 'Explicit-control Evaluator'
url.gsub('_512kb', '')
else
url
end
end
end