Created
April 12, 2018 14:00
-
-
Save ikemo3/c03c285d5b5f5d6db664f2c91cfc7703 to your computer and use it in GitHub Desktop.
iTunes Lookup APIを使ってタイトルとアイコンを取得するコードです。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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