File: findartist.cpp

package info (click to toggle)
libmusicbrainz3 3.0.1-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 848 kB
  • ctags: 977
  • sloc: cpp: 7,302; xml: 882; ansic: 455; makefile: 10
file content (58 lines) | stat: -rw-r--r-- 1,488 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Search for an artist by name.
//
// Usage:
//	findartist 'artist-name' 
//
// $Id: findartist.cpp 8247 2006-07-22 19:29:52Z luks $

#include <iostream>
#include <musicbrainz3/webservice.h>
#include <musicbrainz3/query.h>
#include <musicbrainz3/model.h>

using namespace std;
using namespace MusicBrainz;

int
main(int argc, char **argv)
{
	if (argc < 2) {
		cout << "Usage: findartist 'artist name'" << endl;
		return 1;
	}
	
	Query q;
	ArtistResultList results;
	
	try {
		// Search for all artists matching the given name. Limit the results
		// to the 5 best matches.
		
		ArtistFilter f = ArtistFilter().name(argv[1]).limit(5);
		results = q.getArtists(&f);
	}
	catch (WebServiceError &e) {
		cout << "Error: " << e.what() << endl;
		return 1;
	}

	// No error occurred, so display the results of the search. It consists of
	// ArtistResult objects, where each contains an artist.
	
	for (ArtistResultList::iterator i = results.begin(); i != results.end(); i++) {
		ArtistResult *result = *i;
		Artist *artist = result->getArtist();
		cout << "Score   : " << result->getScore() << endl;
		cout << "Id      : " << artist->getId() << endl;
		cout << "Name    : " << artist->getName() << endl;
		cout << "SortName: " << artist->getSortName() << endl;
		cout << endl;
	}

	// Now that you have artist IDs, you can request an artist in more detail, for
	// example to display all official albums by that artist. See the 'getartist.cpp'
	// example on how achieve that. 
	
	return 0;
}