root/python-musicbrainz2/trunk/examples/getartist.py

Revision 9734, 1.5 kB (checked in by matt, 9 months ago)

Display tags in getartist.py.

  • Property svn:executable set to *
  • Property svn:keywords set to Id HeadURL
Line 
1 #! /usr/bin/env python
2 #
3 # Retrieve an artist by ID and display all official albums.
4 #
5 # Usage:
6 #   python getartist.py artist-id
7 #
8 # $Id$
9 #
10 import sys
11 import logging
12 import musicbrainz2.webservice as ws
13 import musicbrainz2.model as m
14
15 logging.basicConfig()
16 logger = logging.getLogger()
17 logger.setLevel(logging.DEBUG)
18
19
20 if len(sys.argv) < 2:
21     print "Usage: getartist.py artist-id"
22     sys.exit(1)
23
24 q = ws.Query()
25
26 try:
27     # The result should include all official albums.
28     #
29     inc = ws.ArtistIncludes(
30         releases=(m.Release.TYPE_OFFICIAL, m.Release.TYPE_ALBUM),
31         tags=True)
32     artist = q.getArtistById(sys.argv[1], inc)
33 except ws.WebServiceError, e:
34     print 'Error:', e
35     sys.exit(1)
36
37
38 print "Id         :", artist.id
39 print "Name       :", artist.name
40 print "SortName   :", artist.sortName
41 print "UniqueName :", artist.getUniqueName()
42 print "Type       :", artist.type
43 print "BeginDate  :", artist.beginDate
44 print "EndDate    :", artist.endDate
45 print "Tags       :", ', '.join(t.value for t in artist.tags)
46 print
47
48
49 if len(artist.getReleases()) == 0:
50     print "No releases found."
51 else:
52     print "Releases:"
53
54 for release in artist.getReleases():
55     print
56     print "Id        :", release.id
57     print "Title     :", release.title
58     print "ASIN      :", release.asin
59     print "Text      :", release.textLanguage, '/', release.textScript
60     print "Types     :", release.types
61
62 #
63 # Using the release IDs and Query.getReleaseById(), you could now request
64 # those releases, including the tracks, release events, the associated
65 # DiscIDs, and more. The 'getrelease.py' example shows how this works.
66 #
67
68 # EOF
Note: See TracBrowser for help on using the browser.