Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added iTunes artwork and track info scripts
- Loading branch information
Andrew Burns
committed
Dec 28, 2011
1 parent
2308d63
commit f3720ee
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env ruby | ||
require 'yaml' | ||
cache_file_path='/tmp/.itunes-current-track' | ||
|
||
# Run the cache updater, so we don't have to have an item in Geek Tool for it | ||
cache_updater = File.join(File.dirname(__FILE__), 'update_itunes_cache.rb') | ||
`#{cache_updater}` | ||
|
||
# This shouldn't happen but just in case | ||
Kernel.exit 0 unless File.exists? cache_file_path | ||
cache_file=File.open(cache_file_path, 'r') { |f| YAML.load(f.read) } | ||
|
||
|
||
def right_align(str, amt=20) | ||
"%#{amt}s" % str | ||
end | ||
|
||
def stars_from_rating rating | ||
"★" * (rating.to_i/20) | ||
end | ||
|
||
puts cache_file[:name] | ||
puts cache_file[:artist] | ||
puts cache_file[:album] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env ruby | ||
require 'yaml' | ||
cache_file_path='/tmp/.itunes-current-track' | ||
Kernel.exit 0 unless File.exists? cache_file_path | ||
cache_file=File.open(cache_file_path, 'r') { |f| YAML.load(f.read) } | ||
|
||
|
||
def stars_from_rating rating | ||
"★" * rating | ||
#"☆" * rating | ||
end | ||
|
||
puts stars_from_rating(cache_file[:stars]) |
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env ruby | ||
require 'yaml' | ||
cache_file_path='/tmp/.itunes-current-track' | ||
cache_file=File.open(cache_file_path, 'r') { |f| YAML.load(f.read) } if File.exists? cache_file_path | ||
|
||
def update_album_artwork | ||
artwork_script=File.join(File.dirname(__FILE__), 'tools/iTunesArtwork.scpt') | ||
`osascript "#{artwork_script}"` if File.exists?(artwork_script) | ||
end | ||
|
||
def track_info(clause) | ||
script = %Q{tell application "iTunes" to get #{clause} of current track} | ||
#puts "Running: #{script}" | ||
`osascript -e '#{script}'`.strip | ||
end | ||
|
||
# Get track info | ||
track = {} | ||
track[:id] = track_info 'id' | ||
|
||
# If our IDs match, there is no reason to re-do all of this | ||
Kernel.exit 0 if cache_file && cache_file[:id] == track[:id] | ||
|
||
track[:name] = track_info 'name' | ||
track[:artist] = track_info 'artist' | ||
track[:album] = track_info 'album' | ||
track[:rating] = track_info('rating').to_i | ||
track[:stars] = (track[:rating]/20) | ||
update_album_artwork | ||
|
||
File.open(cache_file_path, 'w') { |f| f.write(track.to_yaml) } |