libmusicbrainz5 5.1.0
Loading...
Searching...
No Matches
libmusicbrainz5

This is the documentation for libmusicbrainz5, a library for retrieving data from the MusicBrainz service.

The main entry point to the library is the MusicBrainz5::CQuery object.

For details of the C interface, see the documentation for the file mb5_c.h.

Please report any issues with this library at http://tickets.musicbrainz.org/.

Compiling and Linking

This package provides a pkg-config script that returns the necessary compiler and linker flags, as well as the version number. To build a small sample program one would use:

g++ -o test_app test_app.cpp pkg-config libmusicbrainz5 --cflags --libs

If you don't want/can't use pkg-config and you are using the C API, make sure you link in the C++ standard library:

gcc -o test_app test_app.c -lmusicbrainz5 -lm -lstdc++
Example:

A brief example showing how to lookup a list of releases matching a disc id

MusicBrainz5::CQuery Query("cdlookupexample-1.0");
try
{
MusicBrainz5::CMetadata Metadata=Query.Query("discid",DiscID);
if (Metadata.Disc() && Metadata.Disc()->ReleaseList())
{
MusicBrainz5::CReleaseList *ReleaseList=Metadata.Disc()->ReleaseList();
std::cout << "Found " << ReleaseList->NumItems() << " release(s)" << std::endl;
for (int count=0;count<ReleaseList->NumItems();count++)
{
MusicBrainz5::CRelease *Release=ReleaseList->Item(count);
std::cout << "Basic release: " << std::endl << *Release << std::endl;
//The releases returned from LookupDiscID don't contain full information
Params["inc"]="artists labels recordings release-groups url-rels discids artist-credits";
Metadata=Query.Query("release",Release.ID(),"",Params);
if (Metadata.Release())
{
MusicBrainz5::CRelease *FullRelease=Metadata.Release();
std::cout << *FullRelease << std::endl;
}
}
}
}
{
std::cout << "Connection Exception: '" << Error.what() << "'" << std::endl;
std::cout << "LastResult: " << Query.LastResult() << std::endl;
std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl;
std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl;
}
{
std::cout << "Timeout Exception: '" << Error.what() << "'" << std::endl;
std::cout << "LastResult: " << Query.LastResult() << std::endl;
std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl;
std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl;
}
{
std::cout << "Authentication Exception: '" << Error.what() << "'" << std::endl;
std::cout << "LastResult: " << Query.LastResult() << std::endl;
std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl;
std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl;
}
{
std::cout << "Fetch Exception: '" << Error.what() << "'" << std::endl;
std::cout << "LastResult: " << Query.LastResult() << std::endl;
std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl;
std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl;
}
{
std::cout << "Request Exception: '" << Error.what() << "'" << std::endl;
std::cout << "LastResult: " << Query.LastResult() << std::endl;
std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl;
std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl;
}
{
std::cout << "ResourceNotFound Exception: '" << Error.what() << "'" << std::endl;
std::cout << "LastResult: " << Query.LastResult() << std::endl;
std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl;
std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl;
}
Exception thrown when an authentication error occurs.
Definition: HTTPFetch.h:90
Exception thrown when an error occurs connecting to web service.
Definition: HTTPFetch.h:64
CReleaseList * ReleaseList() const
virtual const char * what() const
Definition: HTTPFetch.h:48
Exception thrown when an error occurs fetching data.
Definition: HTTPFetch.h:103
int NumItems() const
Definition: ListImpl.h:35
T * Item(int Item) const
Definition: ListImpl.h:94
Definition: Metadata.h:70
CRelease * Release() const
CDisc * Disc() const
Main object for generating queries to MusicBrainz.
Definition: Query.h:186
std::map< std::string, std::string > tParamMap
Definition: Query.h:188
Definition: Release.h:50
std::string ID() const
Exception thrown when an invalid request is made.
Definition: HTTPFetch.h:116
Exception thrown when the requested resource is not found.
Definition: HTTPFetch.h:129
Exception thrown when a connection to the web service times out.
Definition: HTTPFetch.h:77