Skip to content

Instantly share code, notes, and snippets.

@jptix
Created May 24, 2009 21:31
Show Gist options
  • Save jptix/117266 to your computer and use it in GitHub Desktop.
Save jptix/117266 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "osx/cocoa"
require "erb"
require "base64"
include OSX
def pict_bytes_for(artwork)
image_rep = artwork.data.representations.first
data = image_rep.PICTRepresentation
bytestr = "\0"*512 + data.bytes.bytestr(data.length)
Base64.encode64 bytestr
end
require_framework "ScriptingBridge"
itunes = SBApplication.applicationWithBundleIdentifier 'com.apple.iTunes'
track = itunes.currentTrack
puts ERB.new(DATA.read, 0, "%-<>").result(binding)
__END__
<?xml version="1.0" encoding="UTF-8"?>
<track>
<name><%= track.name %></name>
<artist><%= track.artist %></artist>
<album><%= track.album %></album>
<artworks>
<% track.artworks.each do |artwork| %>
<artwork><%= pict_bytes_for artwork %></artwork>
<% end %>
</artworks>
</track>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment