Skip to content

Instantly share code, notes, and snippets.

@mattt
Created June 17, 2014 04:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattt/1b407afc546d914c1c6b to your computer and use it in GitHub Desktop.
Save mattt/1b407afc546d914c1c6b to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'nokogiri'
year = 2014
doc = Nokogiri::HTML(open("https://developer.apple.com/videos/wwdc/#{year}/"))
doc.search("p.download").each do |download|
href = download.at("a").attr('href')
uri = URI(href)
uri.path = uri.path.split('/')[0...-1].join('/') + '/'
uri.query = nil
p session = uri.path.split('/').last.to_i
begin
subtitles = []
m3u8 = open(URI.join(uri, "subtitles/eng/prog_index.m3u8"))
m3u8.each_line do |line|
next unless /\.webvtt$/ === line
webvtt = open(URI.join(uri, "subtitles/eng/", line.strip))
subtitles << webvtt.read
end
File.open("#{session}.vtt", "w") do |f|
f.write subtitles.join("\n")
end
rescue => e
p "! #{session} (#{e})"
next
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment