Changeset 15 in flacrip for trunk


Ignore:
Timestamp:
09/19/14 22:37:22 (10 years ago)
Author:
peter
Message:

use Text::Unidecode to convert metadata in UTF-8 to ASCII-only for filenames and (if requested via the --ascii-tags option) the ID3 tags of the MP3 files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/flactrack

    r13 r15  
    1515use Audio::FLAC::Header; 
    1616use MusicBrainz; 
     17use Text::Unidecode; 
    1718 
    1819GetOptions( 
     
    2223    'all|a' => \my $ALL, 
    2324    'dir|d=s' => \my $DIRECTORY, 
     25    'ascii-tags' => \my $ASCII_TAGS, 
    2426); 
    2527 
     
    4143        require Config::Properties; 
    4244 
    43         my $properties = Config::Properties->new(file => $properties_file); 
     45        # the properties are in UTF-8; mark them as such so unidecode works correctly later 
     46        my $properties = Config::Properties->new(file => $properties_file, encoding => 'utf8'); 
    4447        $info = $properties->getProperties; 
    4548    } else { 
     
    103106        if ($info) { 
    104107            my $track_key = sprintf 'TRACK%02d', $tracknum; 
    105             $cmd .= sprintf q{ --tt %s --ta %s --tl %s --tn %d}, 
    106                 quote($info->{"$track_key.TITLE"}), 
    107                 quote($info->{"$track_key.ARTIST"}), 
    108                 quote($info->{ALBUM}), 
     108            $cmd .= sprintf q{ --tt %s --ta %s --tl %s --ty %d --tn %d}, 
     109                quote($ASCII_TAGS ? unidecode($info->{"$track_key.TITLE"}) : $info->{"$track_key.TITLE"}), 
     110                quote($ASCII_TAGS ? unidecode($info->{"$track_key.ARTIST"}) : $info->{"$track_key.ARTIST"}), 
     111                quote($ASCII_TAGS ? unidecode($info->{ALBUM}) : $info->{ALBUM}), 
     112                ($info->{ORIGINALDATE} =~ /^(\d\d\d\d)/)[0], 
    109113                $tracknum; 
    110114        } 
     
    130134sub to_filename { 
    131135    my @strings = @_; 
    132     #TODO: deal with non-ascii characters (unidecode) e.g. ü --> ue 
    133136    return map { 
    134137        s/&/ and /g; 
     138        unidecode($_); 
    135139        s/[^a-z0-9-_ ]+//gi; 
    136140        s/ +/_/g; 
Note: See TracChangeset for help on using the changeset viewer.