iTunesで再生中の曲を取得 on Mac

#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use LWP::Simple;
use Encode::Detect::Detector;

use Mac::Glue;

my $itunes = new Mac::Glue 'iTunes';
#print Dumper($itunes);

my $library = $itunes->obj(library_playlist => 1);
#print Dumper($library);

my $tracks  = $itunes->obj(tracks => $library);
my @tracks = $itunes->get($tracks);
#print scalar(@tracks), " ----", $/;

# 再生中か?
#print $itunes->get($itunes->prop('player_state')), $/;

# 再生中の楽曲ID
#my $current_track_id = $itunes->{NAMES}->{playing}->{id};
#print Dumper $library->get(id => $current_track_id);

# 再生中の楽曲
my $current_track = $itunes->prop('current track');

print "current track:", $/;
my $current_track_location = $itunes->get($itunes->prop(location => $current_track));
print $current_track_location, $/;

my $current_track_name = $itunes->get($itunes->prop(name => $current_track));
print $current_track_name, $/;

my $current_track_artist = $itunes->get($itunes->prop(artist => $current_track));
print $current_track_artist, $/;

print $/;

print "track list:", $/;
foreach my $track(@tracks) {
  # ファイルのパス取得
  my $path = $itunes->get( $itunes->prop(location => $track) );
  #print $itunes->prop(location => $track), $/;
  print $path, $/;

  # 曲名
  my $name = $itunes->get( $itunes->prop(name => $track) );
  print $name, $/;

  # アーティスト
  my $artist = $itunes->get( $itunes->prop(artist => $track) );
  print $artist, $/;

  last;
}


こんなんで行けたんだけど、日本語が文字化けする.....


※追記
Macの64bit機でやる場合には、
export VERSIONER_PERL_PREFER_32_BIT=yes
しないと行けない場合があるっぽい


あと、上記ソース実行する前に
http://subtech.g.hatena.ne.jp/otsune/20070526/AppleScriptandPerl
を参考に、Mac::GlueでiTunes使えるように下記の手順を行う必要があった

$ su
# export VERSIONER_PERL_PREFER_32_BIT=yes
# gluemac /Applications/iTunes.app
Making glue for '/Applications/iTunes.app'
What is the glue name? [iTunes]:
Created and installed App glue for 'iTunes.app, v10.2.2' (iTunes)


ちなみに、Finder用は以下のコマンド

# gluemac /System/Library/CoreServices/Finder.app