File: findlabel.py

package info (click to toggle)
python-musicbrainz2 0.6.0-2
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 564 kB
  • ctags: 730
  • sloc: python: 3,837; xml: 882; makefile: 10
file content (53 lines) | stat: -rwxr-xr-x 1,209 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
#! /usr/bin/env python
#
# Search for a label by name.
#
# Usage:
#	python findlabel.py 'label-name'
#
# $Id: findlabel.py 9316 2007-08-11 07:38:14Z matt $
#
import sys
import logging
from musicbrainz2.webservice import Query, LabelFilter, WebServiceError

logging.basicConfig()
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
	

if len(sys.argv) < 2:
	print "Usage: findlabel.py 'label name'"
	sys.exit(1)

q = Query()

try:
	# Search for all labels matching the given name. Limit the results
	# to the 5 best matches. The offset parameter could be used to page
	# through the results.
	#
	f = LabelFilter(name=sys.argv[1], limit=5)
	labelResults = q.getLabels(f)
except WebServiceError, e:
	print 'Error:', e
	sys.exit(1)


# No error occurred, so display the results of the search. It consists of
# LabelResult objects, where each contains a label.
#
for result in labelResults:
	label = result.label
	print "Score     :", result.score
	print "Id        :", label.id
	print "Name      :", label.name
	print "Sort Name :", label.sortName
	print

#
# Now that you have label IDs, you can request a label directly to get more
# detail. See 'getlabel.py' for an example on how to do that.
#

# EOF