Skip to content

Commit

Permalink
Collection get methods for all collection entities (#175)
Browse files Browse the repository at this point in the history
Signed-off-by: Alastair Porter <[email protected]>
  • Loading branch information
alastair committed Dec 29, 2015
1 parent cffa983 commit 5208948
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 6 deletions.
8 changes: 6 additions & 2 deletions musicbrainzngs/mbxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,12 @@ def parse_collection(collection):
result = {}
attribs = ["id", "type", "entity-type"]
elements = ["name", "editor"]
# TODO: add event-list:
inner_els = {"release-list": parse_release_list}
inner_els = {"release-list": parse_release_list,
"artist-list": parse_artist_list,
"event-list": parse_event_list,
"place-list": parse_place_list,
"recording-list": parse_recording_list,
"work-list": parse_work_list}
result.update(parse_attributes(attribs, collection))
result.update(parse_elements(elements, inner_els, collection))

Expand Down
51 changes: 47 additions & 4 deletions musicbrainzngs/musicbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,16 +1182,59 @@ def get_collections():
# Missing <release-list count="n"> the count in the reply
return _do_mb_query("collection", '')

def _do_collection_query(collection, collection_type, limit, offset):
params = {}
if limit: params["limit"] = limit
if offset: params["offset"] = offset
return _do_mb_query("collection", "%s/%s" % (collection, collection_type), [], params)

def get_artists_in_collection(collection, limit=None, offset=None):
"""List the artists in a collection.
Returns a dict with a 'collection' key, which again has a 'artist-list'.
See `Browsing`_ for how to use `limit` and `offset`.
"""
return _do_collection_query(collection, "artists", limit, offset)

def get_releases_in_collection(collection, limit=None, offset=None):
"""List the releases in a collection.
Returns a dict with a 'collection' key, which again has a 'release-list'.
See `Browsing`_ for how to use `limit` and `offset`.
"""
params = {}
if limit: params["limit"] = limit
if offset: params["offset"] = offset
return _do_mb_query("collection", "%s/releases" % collection, [], params)
return _do_collection_query(collection, "releases", limit, offset)

def get_events_in_collection(collection, limit=None, offset=None):
"""List the events in a collection.
Returns a dict with a 'collection' key, which again has a 'event-list'.
See `Browsing`_ for how to use `limit` and `offset`.
"""
return _do_collection_query(collection, "events", limit, offset)

def get_places_in_collection(collection, limit=None, offset=None):
"""List the places in a collection.
Returns a dict with a 'collection' key, which again has a 'place-list'.
See `Browsing`_ for how to use `limit` and `offset`.
"""
return _do_collection_query(collection, "places", limit, offset)

def get_recordings_in_collection(collection, limit=None, offset=None):
"""List the recordings in a collection.
Returns a dict with a 'collection' key, which again has a 'recording-list'.
See `Browsing`_ for how to use `limit` and `offset`.
"""
return _do_collection_query(collection, "recordings", limit, offset)

def get_works_in_collection(collection, limit=None, offset=None):
"""List the works in a collection.
Returns a dict with a 'collection' key, which again has a 'work-list'.
See `Browsing`_ for how to use `limit` and `offset`.
"""
return _do_collection_query(collection, "works", limit, offset)


# Submission methods
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#"><collection entity-type="event" id="20562e36-c7cc-44fb-96b4-486d51a1174b" type="Event"><name>event collection</name><editor>alastairp</editor><event-list count="1"><event id="fe4bce99-6e9b-4050-9681-eac48cdf3199"><name>T on the Fringe 2006</name><life-span><begin>2006-08-04</begin><end>2006-08-30</end></life-span></event></event-list></collection></metadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#"><collection id="2326c2e8-be4b-4300-acc6-dbd0adf5645b" type="Work" entity-type="work"><name>work collection</name><editor>alastairp</editor><work-list count="1"><work id="541f07e2-389d-4a0c-8a97-896b6752dd35"><title>Maggot Brain</title></work></work-list></collection></metadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#"><collection entity-type="artist" type="Artist" id="29611d8b-b3ad-4ffb-acb5-27f77342a5b0"><name>artist collection</name><editor>alastairp</editor><artist-list count="1"><artist id="0383dadf-2a4e-4d10-a46a-e9e041da8eb3"><name>Queen</name><sort-name>Queen</sort-name><disambiguation>UK rock group</disambiguation><life-span><begin>1970-06-27</begin></life-span></artist></artist-list></collection></metadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#"><collection entity-type="place" type="Place" id="855b134e-9a3b-4717-8df8-8c4838d89924"><name>place collection</name><editor>alastairp</editor><place-list count="1"><place id="f75dd832-8cac-4068-8432-de0472866d33"><name>San Francisco Bath House</name><disambiguation>aka 'San Fran'</disambiguation><address>171 Cuba Street, Wellington, New Zealand</address></place></place-list></collection></metadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#"><collection type="Recording" id="a91320b2-fd2f-4a93-9e4e-603d16d514b6" entity-type="recording"><name>recording collection</name><editor>alastairp</editor><recording-list count="1"><recording id="be462d72-b71b-4cb0-8f65-3434f99822a7"><title>Maggot Brain</title><length>1201000</length></recording></recording-list></collection></metadata>

0 comments on commit 5208948

Please sign in to comment.