On Nov 17, 5:33 pm, Robert Jacobson <
teri...@gmail.com> wrote:
> I don't know, that sounds correct. What happens when you run
>
itunes_scripts.pl itunes_rating_to_popm
>
> It should say (after the copyright):
> "Running itunes_rating_to_popm"
Yep, it shows that line so it looks like it's executing it. But after
seeing nothing happen to the songs,I decided to add in some debugging
code like 'print "foo";' in certain sections to know it was executing.
"foo" never got printed so I think there's something else afoot.
> If might help if you post the code changes you made.
here's the code, modified from your original:
================
sub set_popm_rating($);
our %itunes_rating_to_popm_rating = (
20 => "23", # 1.0 stars
20 => "53", # 1.0 stars
40 => "64", # 2.0 stars
40 => "104", # 2.0 stars
60 => "128", # 3.0 stars
60 => "154", # 3.0 stars
80 => "196", # 4.0 stars
80 => "205", # 4.0 stars
100 => "252", # 5.0 stars
100 => "255", # 5.0 stars
);
sub itunes_rating_to_popm {
use strict;
use Win32::OLE;
use MP3::Tag;
use Data::Dumper;
## Create the OLE Object
my $iTunes = Win32::OLE->new('iTunes.Application') or die Win32::OLE-
>LastError();
my $tracks = $iTunes->SelectedTracks;
if (not defined $tracks) {
print "You must select some tracks in iTunes first!\n";
}
for (my $i = 1 ; $i <= $tracks->Count ; $i++ ) {
my $track = $tracks->Item($i);
my $kind_string = $track->KindAsString();
if ($kind_string =~ m/^MPEG/) {
&set_popm_rating($track);
} else {
print "Track " . $track->Name() . "does not appear to be an
MP3\n" . "Its kind is: " . $kind_string . "\n";
}
}
}
sub set_popm_rating ($) {
my $track= shift;
my $filename = $track->Location();
# my $filename = $ARGV[0];
# my $filename = "./MP3samples/BF2RealTone-1star.mp3";
my $rating;
my $itunesrating;
my $popmrating;
my $mp3 = MP3::Tag->new($filename);
$mp3->get_tags();
# print Dumper $mp3;
my $tag;
if (exists $mp3->{'ID3v2'} ) {
$tag = $mp3->{'ID3v2'};
} else {
print "ERROR: no ID3v2 tag exists in file $filename!\n";
}
my ($info, $name, @rest) = $tag->get_frame("POPM");
if (not defined $info) {
print "Error getting ID3v2 POPM tag for $filename, skipping\n";
return 0;
} else {
# POPM tag $info is a hash:
# {
# 'URL' => 'no@email',
# 'Counter' => 0,
# 'Rating' => 53
# };
$rating = $info->{'Rating'}; # get the current popm rating
$popmrating = $itunes_rating_to_popm_rating{$rating};
$itunesrating = $track->{'Rating'};
if (exists $itunes_rating_to_popm_rating{$rating} ) { #check that
the rating matches our defined translation
# only write POPM rating if it's different
print "rating is $rating\n";
print "popmrating is $popmrating\n";
print "itunesrating is $itunesrating\n";
if ($popmrating != $itunesrating) {
$track->{'Rating'} = $popmrating;
print "for track " . $track->Name . " with rating
$itunesrating, POPM rating is $popmrating\n";
}
} else {
print "ERROR: Got iTunes rating of $rating, for which no
translation exists\n";
}
}
}
1;
================