3

I am creating a Perl script which will move a mp3 file to my music folder in format artist/album/mp3file. Now it is possible that some of my mp3 files don't have an album tag so I thought of querying the MusicBrainz database to retrieve album metadata given track title & artist.

I am using WebService::MusicBrainz Perl module for this task, but I am not able to see any method that gives album metadata info. My current code is:

use WebService::MusicBrainz::Track;

my $ws = WebService::MusicBrainz::Track->new();
my $response = $ws->search({ ARTIST => 'Ryan Adams', TITLE => 'when the stars go blue'  }); 

my $track = $response->track();
print $track->title(), " - ", $track->artist()->name(), "\n";

say $track->id();

So, how do I get my the album info for a given track using MusicBrainz and if it is not possible what are my alternative options?

Jonathan Leffler
  • 666,971
  • 126
  • 813
  • 1,185
ronnie
  • 1,641
  • 2
  • 15
  • 21

2 Answers2

5

First of all, what you want is adding metadata to mp3s which is the most common usage scenario people have. The "normal" way is to use a Musicbrainz Tagger, open these files there and work with the interface to attach the correct metadata. The suggested (gui) tool is Musicbrain Picard

I also want to state that the Perl module is using the now deprecated Web Service Version 1 of MusicBrainz. That Web Service has a couple of problems because it was made for another database scheme than the one used now at MusicBrainz.

However, the current Web Service Version 2 has only a python library available: python-musicbrainzngs.

You can still work with the Perl module, but if you run into "weird" problems, this might be the reason.


This is how the Web Service works in general (and how it should apply directly for the Perl module as a wrapper for this web service): Your search gives this:

http://musicbrainz.org/ws/1/track/?artist=%22Ryan%20Adams%22&title=%22when%20the%20stars%20go%20blue%22

There you get a list of recordings of this track. These recodings occur on multiple releases (ReleaseList). You can disregard many of these, as they are of the type "compilation". You probably want the "album" releases.

You probably ask yourself why there are multiple album releases with the same name in the list. This is because a "release" on MusicBrainz is a combination of a release-event and a couple of mediums. You might have an US release and a german deluxe edition and so on. All of these releases are in one "release group".

You probably want the name of this "release group", which mostly is also the name of every release in this group.

You might want to read a bit on how the MusicBrainz Database is structured.


This is only the basic use case of course. You might run into misspellings in artist/title, multiple or missing album release groups and other things. However, altogether it should work and you can just drop the "problem" cases in a special directory and work with them in Picard. Picard also has other means of identifying files per "musical analysis" (PUIDs, Acoustids)


EDIT:

my @tracklist = $response->track_list();
foreach my $track ( @tracklist ) {
  print $track->title(), " - ", $track->artist()->name(), "\n";
  my @releaselist = $track->release_list();
  foreach my $release ( @releaselist ) {
    print "  ", $release->title(), " - ", $release->type();
  }
}

Should work in general, but it doesn't. It gives you all tracks of the response, but somehow it can't extract releases from release_list(). Possibly because the schema changed or because the perl module is broken.

JonnyJD
  • 2,345
  • 1
  • 27
  • 40
  • 1
    You should be able to post the links as comments here. Otherwise write them as `hXXp://...` and a someone with more rep can fix them for you. – OACDesigns Dec 16 '12 at 01:08
  • Receiving my first vote gave me enough reputation -> added the links – JonnyJD Dec 16 '12 at 01:23
  • $response->track_list() will give you an array of Tracks. However $track->release_list() does not give you anything useful. I guess the perl module is just broken in this case. You better use the python module. – JonnyJD Dec 16 '12 at 15:21
1

Check out our perl modules for accessing the Cover Art Archive:

http://metacpan.org/pod/Net::CoverArtArchive

More info on our archive is here, including specs:

http://coverartarchive.org/

Good luck!

szabgab
  • 5,884
  • 9
  • 45
  • 61