Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added iTunes artwork and track info scripts

  • Loading branch information...
commit f3720eee35d4b648d9fbc1b2a68160254f5a05e2 1 parent 2308d63
Andrew Burns authored
24 itunes_track_info.rb
... ... @@ -0,0 +1,24 @@
  1 +#!/usr/bin/env ruby
  2 +require 'yaml'
  3 +cache_file_path='/tmp/.itunes-current-track'
  4 +
  5 +# Run the cache updater, so we don't have to have an item in Geek Tool for it
  6 +cache_updater = File.join(File.dirname(__FILE__), 'update_itunes_cache.rb')
  7 +`#{cache_updater}`
  8 +
  9 +# This shouldn't happen but just in case
  10 +Kernel.exit 0 unless File.exists? cache_file_path
  11 +cache_file=File.open(cache_file_path, 'r') { |f| YAML.load(f.read) }
  12 +
  13 +
  14 +def right_align(str, amt=20)
  15 + "%#{amt}s" % str
  16 +end
  17 +
  18 +def stars_from_rating rating
  19 + "★" * (rating.to_i/20)
  20 +end
  21 +
  22 +puts cache_file[:name]
  23 +puts cache_file[:artist]
  24 +puts cache_file[:album]
13 itunes_track_stars.rb
... ... @@ -0,0 +1,13 @@
  1 +#!/usr/bin/env ruby
  2 +require 'yaml'
  3 +cache_file_path='/tmp/.itunes-current-track'
  4 +Kernel.exit 0 unless File.exists? cache_file_path
  5 +cache_file=File.open(cache_file_path, 'r') { |f| YAML.load(f.read) }
  6 +
  7 +
  8 +def stars_from_rating rating
  9 + "★" * rating
  10 + #"☆" * rating
  11 +end
  12 +
  13 +puts stars_from_rating(cache_file[:stars])
BIN  tools/iTunesArtwork.scpt
Binary file not shown
31 update_itunes_cache.rb
... ... @@ -0,0 +1,31 @@
  1 +#!/usr/bin/env ruby
  2 +require 'yaml'
  3 +cache_file_path='/tmp/.itunes-current-track'
  4 +cache_file=File.open(cache_file_path, 'r') { |f| YAML.load(f.read) } if File.exists? cache_file_path
  5 +
  6 +def update_album_artwork
  7 + artwork_script=File.join(File.dirname(__FILE__), 'tools/iTunesArtwork.scpt')
  8 + `osascript "#{artwork_script}"` if File.exists?(artwork_script)
  9 +end
  10 +
  11 +def track_info(clause)
  12 + script = %Q{tell application "iTunes" to get #{clause} of current track}
  13 + #puts "Running: #{script}"
  14 + `osascript -e '#{script}'`.strip
  15 +end
  16 +
  17 +# Get track info
  18 +track = {}
  19 +track[:id] = track_info 'id'
  20 +
  21 +# If our IDs match, there is no reason to re-do all of this
  22 +Kernel.exit 0 if cache_file && cache_file[:id] == track[:id]
  23 +
  24 +track[:name] = track_info 'name'
  25 +track[:artist] = track_info 'artist'
  26 +track[:album] = track_info 'album'
  27 +track[:rating] = track_info('rating').to_i
  28 +track[:stars] = (track[:rating]/20)
  29 +update_album_artwork
  30 +
  31 +File.open(cache_file_path, 'w') { |f| f.write(track.to_yaml) }

0 comments on commit f3720ee

Please sign in to comment.
Something went wrong with that request. Please try again.