Skip to content

Instantly share code, notes, and snippets.

@springaki
Created February 3, 2013 12:03
Show Gist options
  • Save springaki/4701522 to your computer and use it in GitHub Desktop.
Save springaki/4701522 to your computer and use it in GitHub Desktop.
# -*- encoding: utf-8 -*-
# TED Subtitles sample
require 'json'
require 'open-uri'
base_url = 'http://www.ted.com/talks/subtitles'
id = 1405
url_en = "#{base_url}/id/#{id.to_s}/lang"
url_ja = "#{base_url}/id/#{id.to_s}/lang/ja"
data_en = JSON.parse(open(url_en).read)
data_ja = JSON.parse(open(url_ja).read)
if data_en && data_en.key?('captions')
captions_en = data_en['captions']
captions_ja = data_ja['captions']
captions_en.zip(captions_ja){ |en, ja|
puts en['content']
puts ja['content']
puts
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment