source: flacrip/trunk/applymeta @ 12

Last change on this file since 12 was 8, checked in by peter, 11 years ago
  • use the VorbisComment style tag names in the info hash returned by MusicBrainz::get_musicbrainz_info()
  • use the MusicBrainz name credit join phrase to build the string where there are multiple artists
  • include the artist sort names in the returned info, as TRACKnn.ARTISTSORT keys, and ALBUMARTIST
  • added an applymeta script that applies the metadata listed in a file to a set of MP3 files
  • when loooking up a release, MusicBrainz::get_musicbrainz_info() prints the number of releases and some other debugging info to STDERR
  • Property svn:executable set to *
File size: 1.5 KB
Line 
1#!/usr/bin/perl -w
2use strict;
3
4use Getopt::Long;
5use Config::Properties;
6use YAML;
7use MP3::Tag;
8
9GetOptions(
10    'file|f=s' => \my $META_FILE,
11    'clear'    => \my $CLEAR,
12);
13
14my @AUDIO_FILES = @ARGV;
15
16my $meta;
17
18if ($META_FILE eq '-') {
19    $meta = Config::Properties->new;
20    $meta->load(*STDIN);
21} else {
22    $meta = Config::Properties->new(
23        file => $META_FILE,
24    );
25}
26
27my $metadata = $meta->splitToTree;
28
29for my $i (1 .. @AUDIO_FILES) {
30    my $mp3 = MP3::Tag->new($AUDIO_FILES[$i - 1]);
31
32    # first clear the tags if asked
33    if ($CLEAR) {
34        warn "clearing first";
35        $mp3->delete_tag($_) foreach qw{ID3v1 ID3v2};
36    }
37
38    my $track_key = sprintf "TRACK%02d", $i;
39    my $track = $metadata->{$track_key};
40    #TODO: for reissues, what should the year/date be tagged as?
41    my ($year) = ($metadata->{ORIGINALDATE} || $metadata->{DATE} || '' =~ /^(\d{4})/);
42    $mp3->title_set($track->{TITLE});
43    $mp3->artist_set($track->{ARTIST} || $metadata->{ALBUMARTIST});
44    $mp3->album_set($track->{ALBUM}  || $metadata->{ALBUM});
45    $mp3->year_set($year) if $year;
46    $mp3->track_set($i);
47    $mp3->select_id3v2_frame_by_descr('TPE2', $metadata->{ALBUMARTIST}) if $metadata->{ALBUMARTIST};
48    $mp3->update_tags;
49    printf "    Apply to %s\n", $AUDIO_FILES[$i - 1];
50
51    #TODO: full version of a make-string-filename-safe function
52    my $sort_filename = lc $track->{ARTISTSORT};
53    for ($sort_filename) {
54        s/&/and/g;
55        s/\W/-/g;
56        s/--/-/g;
57    }
58    print "Artist sort filename would be: " . $sort_filename . "\n";
59}
Note: See TracBrowser for help on using the repository browser.