Sha256: 3c6185a91bbf26a513fa5d9b675e2f9a0984849e6551ddc9e183c2389a97f592
Contents?: true
Size: 1.12 KB
Versions: 2
Compression:
Stored size: 1.12 KB
Contents
#!/usr/bin/ruby # encoding: utf-8 # # Grab iTunes Icon - Brett Terpstra 2014 <http://brettterpstra.com> # # This version has been modified by Eric Dejonckheere %w[net/http open-uri cgi].each do |filename| require filename end class ItunesIcon def find_icon terms url = URI.parse("http://itunes.apple.com/search?term=#{CGI.escape(terms)}&entity=#{@entity}") res = Net::HTTP.get_response(url).body match = res.match(/"#{@icon_size}":"(.*?)",/) unless match.nil? return match[1] else return false end end def grab_small *args @entity = "macSoftware" @icon_size = "artworkUrl60" grab args end def grab_big *args @entity = "macSoftware" @icon_size = "artworkUrl100" grab args end def grab *args terms = args.join(" ") icon_url = find_icon terms if icon_url URI.parse(icon_url) else '' end end def download url, path begin open(url) do |f| File.open(path,'w+') do |file| file.puts f.read end puts "#{path}" end rescue puts "Error: failed to save icon." end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
TokiCLI-0.2.1 | lib/TokiServer/itunesicon.rb |
TokiCLI-0.2.0 | lib/TokiServer/itunesicon.rb |