File: findtrack.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 (52 lines) | stat: -rw-r--r-- 1,187 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
// Search for a track by title (and optionally by artist name). 
//
// Usage:
//	findtrack 'track name' ['artist name'] 
//
// $Id: findtrack.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: findtrack 'track name' ['artist name']"  << endl;
		return 1;
	}
	
	string artistName;
	if (argc > 2) 
		artistName = argv[2];
	
	Query q;
	TrackResultList results;
	
	try {
		TrackFilter f = TrackFilter().title(argv[1]).artistName(artistName);
		results = q.getTracks(&f);
	}
	catch (WebServiceError &e) {
		cout << "Error: " << e.what() << endl;
		return 1;
	}

	for (TrackResultList::iterator i = results.begin(); i != results.end(); i++) {
		TrackResult *result = *i;
		Track *track = result->getTrack();
		cout << "Score   : " << result->getScore() << endl;
		cout << "Id      : " << track->getId() << endl;
		cout << "Title   : " << track->getTitle() << endl;
		cout << "Artist  : " << track->getArtist()->getName() << endl;
		cout << endl;
	}

	return 0;
}