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/.
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++
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 MusicBrainz5::CQuery::tParamMap Params; 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; } } } } catch (MusicBrainz5::CConnectionError& Error) { 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; } catch (MusicBrainz5::CTimeoutError& Error) { 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; } catch (MusicBrainz5::CAuthenticationError& Error) { 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; } catch (MusicBrainz5::CFetchError& Error) { 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; } catch (MusicBrainz5::CRequestError& Error) { 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; } catch (MusicBrainz5::CResourceNotFoundError& Error) { 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; }