Skip to content

Instantly share code, notes, and snippets.

@ikemo3
Created April 12, 2018 14:00
Show Gist options
  • Save ikemo3/c03c285d5b5f5d6db664f2c91cfc7703 to your computer and use it in GitHub Desktop.
Save ikemo3/c03c285d5b5f5d6db664f2c91cfc7703 to your computer and use it in GitHub Desktop.
iTunes Lookup APIを使ってタイトルとアイコンを取得するコードです。
#!/usr/bin/ruby
require 'json'
require 'uri'
require 'open-uri'
id = ARGV[0]
params = {:id => id}
# URLを作成
query = URI.encode_www_form(params)
url = "https://itunes.apple.com/jp/lookup?" + query
# APIを発行
open(url) {|f|
json = JSON.parse(f.readlines.join("\n"))
result = json['results'][0]
puts result['trackCensoredName']
puts result['artworkUrl60']
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment