Last change
on this file since 14 was
11,
checked in by peter, 11 years ago
|
- moved the MusicBrainz library into a lib/ directory
- use FindBin to locate the lib/ directory when using MusicBrainz
|
-
Property svn:executable set to
*
|
File size:
1.1 KB
|
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 | |
---|
[11] | 6 | use FindBin; |
---|
| 7 | use lib "$FindBin::RealBin/lib"; |
---|
| 8 | |
---|
[1] | 9 | use Getopt::Long; |
---|
[3] | 10 | use MusicBrainz; |
---|
[1] | 11 | |
---|
| 12 | GetOptions( |
---|
| 13 | 'flac=s' =>\my $FLAC_FILE, |
---|
| 14 | 'get-release-id' => \my $GET_RELEASE_ID, |
---|
| 15 | 'xml' =>\my $GET_XML, |
---|
| 16 | ); |
---|
| 17 | |
---|
| 18 | my $discid; |
---|
| 19 | |
---|
| 20 | if ($FLAC_FILE) { |
---|
| 21 | require Audio::FLAC::Header; |
---|
| 22 | my $flac = Audio::FLAC::Header->new($FLAC_FILE) or die "Can't read FLAC header from $FLAC_FILE\n"; |
---|
| 23 | $discid = $flac->tags('MBZ_DISCID') or die "No MBZ_DISCID tag in $FLAC_FILE\n"; |
---|
| 24 | } else { |
---|
| 25 | $discid = shift; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | # make the output terminal handle UTF-8 characters |
---|
| 29 | binmode STDOUT, ':utf8'; |
---|
| 30 | |
---|
[3] | 31 | # just dump the XML, if requested |
---|
| 32 | if ($GET_XML) { |
---|
| 33 | print lookup_release($discid); |
---|
| 34 | exit; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | # otherwise, do the full parsing of the data |
---|
[1] | 38 | my $info = get_musicbrainz_info($discid); |
---|
| 39 | |
---|
| 40 | exit unless $info; |
---|
| 41 | |
---|
| 42 | if ($GET_RELEASE_ID) { |
---|
[8] | 43 | print "$$info{MUSICBRAINZ_ALBUMID}\n"; |
---|
[1] | 44 | } else { |
---|
| 45 | for my $key (sort keys %{ $info }) { |
---|
[5] | 46 | print "$key=$$info{$key}\n" unless ref $info->{$key}; |
---|
[1] | 47 | } |
---|
| 48 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.