Mercurial > hg > camir-aes2014
comparison core/magnatagatune/mbid_from_artist_album.py @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 #!/usr/bin/env python | |
2 """A simple script that searches for a release in the MusicBrainz | |
3 database and prints out a few details about the first matching release. | |
4 | |
5 $ ./releasesearch.py "the beatles" revolver | |
6 Revolver, by The Beatles | |
7 Released 1966-08-08 (Official) | |
8 MusicBrainz ID: b4b04cbf-118a-3944-9545-38a0a88ff1a2 | |
9 """ | |
10 from __future__ import print_function | |
11 from __future__ import unicode_literals | |
12 import musicbrainzngs | |
13 import sys | |
14 | |
15 musicbrainzngs.set_useragent( | |
16 "python-musicbrainz-ngs-example", | |
17 "0.1", | |
18 "https://github.com/alastair/python-musicbrainz-ngs/", | |
19 ) | |
20 | |
21 def show_release_details(rel): | |
22 """Print some details about a release dictionary to stdout. | |
23 """ | |
24 # "artist-credit-phrase" is a flat string of the credited artists | |
25 # joined with " + " or whatever is given by the server. | |
26 # You can also work with the "artist-credit" list manually. | |
27 print("{}, by {}".format(rel['title'], rel["artist-credit-phrase"])) | |
28 print("{}".format(rel['id'])) | |
29 | |
30 | |
31 | |
32 def fail(message): | |
33 """Print a message to stderr and then exit with an error status. | |
34 """ | |
35 print(message, file=sys.stderr) | |
36 sys.exit(1) | |
37 | |
38 if __name__ == '__main__': | |
39 args = sys.argv[1:] | |
40 if len(args) != 2: | |
41 fail("usage: {} ARTIST ALBUM".format(sys.argv[0])) | |
42 artist, album = args | |
43 | |
44 # Keyword arguments to the "search_*" functions limit keywords to | |
45 # specific fields. The "limit" keyword argument is special (like as | |
46 # "offset", not shown here) and specifies the number of results to | |
47 # return. | |
48 result = musicbrainzngs.search_releases(artist=artist, release=album, | |
49 limit=1) | |
50 # On success, result is a dictionary with a single key: | |
51 # "release-list", which is a list of dictionaries. | |
52 if not result['release-list']: | |
53 fail("no release found") | |
54 for (idx, release) in enumerate(result['release-list']): | |
55 # print("match #{}:".format(idx+1)) | |
56 show_release_details(release) |