Changeset 20 in flacrip


Ignore:
Timestamp:
10/06/14 17:31:24 (10 years ago)
Author:
peter
Message:

applymeta now takes an optional list of track numbers instead of always using all of the tracks from the properties file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/applymeta

    r8 r20  
    88 
    99GetOptions( 
    10     'file|f=s' => \my $META_FILE, 
    11     'clear'    => \my $CLEAR, 
     10    'file|f=s'   => \my $META_FILE, 
     11    'clear'      => \my $CLEAR, 
     12    'tracks|t=s' => \my $TRACKS, 
    1213); 
    13  
    14 my @AUDIO_FILES = @ARGV; 
    1514 
    1615my $meta; 
     
    2726my $metadata = $meta->splitToTree; 
    2827 
    29 for my $i (1 .. @AUDIO_FILES) { 
    30     my $mp3 = MP3::Tag->new($AUDIO_FILES[$i - 1]); 
     28my $track_count = scalar grep { /^TRACK/ } keys %{ $metadata }; 
     29 
     30my @track_numbers; 
     31foreach (split /,/, $TRACKS) { 
     32    if (/^(\d+)$/) { 
     33        push @track_numbers, $1; 
     34    } elsif (/^(\d+)-(\d+)$/) { 
     35        push @track_numbers, ($1 .. $2); 
     36    } elsif (/^-(\d+)$/) { 
     37        push @track_numbers, (1 .. $1); 
     38    } elsif (/^(\d+)-$/) { 
     39        push @track_numbers, ($1 .. $track_count); 
     40    } 
     41} 
     42 
     43for my $i (@track_numbers) { 
     44    my $audio_file = shift or die "No more audio files to process\n"; 
     45    my $mp3 = MP3::Tag->new($audio_file); 
    3146 
    3247    # first clear the tags if asked 
     
    4762    $mp3->select_id3v2_frame_by_descr('TPE2', $metadata->{ALBUMARTIST}) if $metadata->{ALBUMARTIST}; 
    4863    $mp3->update_tags; 
    49     printf "    Apply to %s\n", $AUDIO_FILES[$i - 1]; 
     64    printf "    Apply to %s\n", $audio_file; 
    5065 
    5166    #TODO: full version of a make-string-filename-safe function 
Note: See TracChangeset for help on using the changeset viewer.