File: findreleasegroup.py

package info (click to toggle)
python-musicbrainz2 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 648 kB
  • ctags: 881
  • sloc: python: 4,624; xml: 999; makefile: 14
file content (58 lines) | stat: -rw-r--r-- 1,556 bytes parent folder | download | duplicates (2)
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
#! /usr/bin/env python
#
# Search for a release group by name.
#
# Usage:
#	python findreleasegroup.py 'album name/Lucene query'
#
# Examples:
#	findreleasegroup.py "Signal morning"
#	findreleasegroup.py '"Gimme Fiction" AND artist:"Spoon"'
#	findreleasegroup.py '"Skylarking" AND type:"Album"'
#
import sys
import logging
from musicbrainz2.webservice import Query, ReleaseGroupFilter, WebServiceError

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

if len(sys.argv) < 2:
	print "Usage: findreleasegroup.py 'release group name/Lucene query'"
	sys.exit(1)

q = Query()

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


# No error occurred, so display the results of the search. It consists of
# ReleaseGroupResult objects, where each contains an artist.
#
for result in results:
	releaseGroup = result.releaseGroup
	print "Score\t\t :", result.score
	print "Id        :", releaseGroup.id
	print "Name      :", releaseGroup.title
	print "Artist    :", releaseGroup.artist.name
	print "Type      :", releaseGroup.type
	print

#
# Now that you have release group IDs, you can request a release group in more detail, for
# example to display all official releases in that group. See the 'getreleasegroup.py'
# example on how achieve that.
#

# EOF