Last change
on this file since 4 was
3,
checked in by peter, 13 years ago
|
moved the MusicBrainz info lookup code into a common MusicBrainz.pm module, to be used by both the mbz and flactrack scripts
|
-
Property svn:executable set to
*
|
File size:
1012 bytes
|
Rev | Line | |
---|
[1] | 1 | #!/usr/bin/perl -w |
---|
| 2 | use strict; |
---|
| 3 | |
---|
| 4 | # one use case: for f in ~/cds/*.flac; do mbid=`./mbz --flac $f --get-release-id`; echo $f $mbid; done; |
---|
| 5 | |
---|
| 6 | use Getopt::Long; |
---|
[3] | 7 | use MusicBrainz; |
---|
[1] | 8 | |
---|
| 9 | GetOptions( |
---|
| 10 | 'flac=s' =>\my $FLAC_FILE, |
---|
| 11 | 'get-release-id' => \my $GET_RELEASE_ID, |
---|
| 12 | 'xml' =>\my $GET_XML, |
---|
| 13 | ); |
---|
| 14 | |
---|
| 15 | my $discid; |
---|
| 16 | |
---|
| 17 | if ($FLAC_FILE) { |
---|
| 18 | require Audio::FLAC::Header; |
---|
| 19 | my $flac = Audio::FLAC::Header->new($FLAC_FILE) or die "Can't read FLAC header from $FLAC_FILE\n"; |
---|
| 20 | $discid = $flac->tags('MBZ_DISCID') or die "No MBZ_DISCID tag in $FLAC_FILE\n"; |
---|
| 21 | } else { |
---|
| 22 | $discid = shift; |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | # make the output terminal handle UTF-8 characters |
---|
| 26 | binmode STDOUT, ':utf8'; |
---|
| 27 | |
---|
[3] | 28 | # just dump the XML, if requested |
---|
| 29 | if ($GET_XML) { |
---|
| 30 | print lookup_release($discid); |
---|
| 31 | exit; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | # otherwise, do the full parsing of the data |
---|
[1] | 35 | my $info = get_musicbrainz_info($discid); |
---|
| 36 | |
---|
| 37 | exit unless $info; |
---|
| 38 | |
---|
| 39 | if ($GET_RELEASE_ID) { |
---|
| 40 | print "$$info{RELEASE_MBID}\n"; |
---|
| 41 | } else { |
---|
| 42 | for my $key (sort keys %{ $info }) { |
---|
| 43 | print "$key=$$info{$key}\n"; |
---|
| 44 | } |
---|
| 45 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.