--- Info.pm.orig 2008-10-21 11:54:11.000000000 +0900 +++ Info.pm 2008-11-01 12:52:54.812867287 +0900 @@ -616,6 +616,16 @@ # for possible ID3 v2.x parsing below. my $oldSuspects = $Encode::Encoding{'Guess'}->{'Suspects'}; + my $detector; + if ($unicode_detect_module) { + $detector = Encode::Detect::Detector->new(); + for my $key (keys %{$info}) { + next unless $info->{$key}; + $detector->handle($info->{$key}); + } + $detector->eof(); + } + for my $key (keys %{$info}) { next unless $info->{$key}; @@ -623,7 +633,7 @@ # Try and guess the encoding. if ($unicode_detect_module) { - my $charset = Encode::Detect::Detector::detect($info->{$key}) || 'iso-8859-1'; + my $charset = $detector->getresult() || Encode::Detect::Detector::detect($info->{$key}) || 'iso-8859-1'; my $enc = Encode::find_encoding($charset); if ($enc) { @@ -695,6 +705,25 @@ my $hash = $raw_v2 == 2 ? { map { ($_, $_) } keys %v2_tag_names } : \%v2_to_v1_names; + # Detect character encoding of text fields. + my $detector; + if ($UNICODE and $unicode_detect_module) { + $detector = Encode::Detect::Detector->new(); + for my $id (keys %{$hash}) { + next if $id !~ /^T/ and $id !~ /^COM/; + next if !exists $v2->{$id}; + my $data1 = $v2->{$id}; + $data1 = [ $data1 ] if ref($data1) ne 'ARRAY'; + for my $data (@$data1) { + $data =~ s/^(.)//; + my $encoding = $1; + $detector->handle($data) + if $encoding eq "\000" and $data and $data !~ /^[\x00-\x7F]+$/; + } + } + $detector->eof(); + } + for my $id (keys %{$hash}) { next if !exists $v2->{$id}; @@ -870,7 +899,7 @@ if ($unicode_detect_module) { - my $charset = Encode::Detect::Detector::detect($data) || 'iso-8859-1'; + my $charset = $detector->getresult() || Encode::Detect::Detector::detect($data) || 'iso-8859-1'; my $enc = Encode::find_encoding($charset); if ($enc) {