From 520894802ca146c9a09616362487a753a83ff6be Mon Sep 17 00:00:00 2001 From: Alastair Porter Date: Tue, 29 Dec 2015 22:45:46 +0100 Subject: [PATCH] Collection get methods for all collection entities (#175) Signed-off-by: Alastair Porter --- musicbrainzngs/mbxml.py | 8 ++- musicbrainzngs/musicbrainz.py | 51 +++++++++++++++++-- ...e36-c7cc-44fb-96b4-486d51a1174b-events.xml | 1 + ...c2e8-be4b-4300-acc6-dbd0adf5645b-works.xml | 1 + ...8b-b3ad-4ffb-acb5-27f77342a5b0-artists.xml | 1 + ...34e-9a3b-4717-8df8-8c4838d89924-places.xml | 1 + ...fd2f-4a93-9e4e-603d16d514b6-recordings.xml | 1 + 7 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 test/data/collection/20562e36-c7cc-44fb-96b4-486d51a1174b-events.xml create mode 100644 test/data/collection/2326c2e8-be4b-4300-acc6-dbd0adf5645b-works.xml create mode 100644 test/data/collection/29611d8b-b3ad-4ffb-acb5-27f77342a5b0-artists.xml create mode 100644 test/data/collection/855b134e-9a3b-4717-8df8-8c4838d89924-places.xml create mode 100644 test/data/collection/a91320b2-fd2f-4a93-9e4e-603d16d514b6-recordings.xml diff --git a/musicbrainzngs/mbxml.py b/musicbrainzngs/mbxml.py index 345a2fa..dd0420d 100644 --- a/musicbrainzngs/mbxml.py +++ b/musicbrainzngs/mbxml.py @@ -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)) diff --git a/musicbrainzngs/musicbrainz.py b/musicbrainzngs/musicbrainz.py index 9c7ac9c..8d73fc3 100644 --- a/musicbrainzngs/musicbrainz.py +++ b/musicbrainzngs/musicbrainz.py @@ -1182,16 +1182,59 @@ def get_collections(): # Missing 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 diff --git a/test/data/collection/20562e36-c7cc-44fb-96b4-486d51a1174b-events.xml b/test/data/collection/20562e36-c7cc-44fb-96b4-486d51a1174b-events.xml new file mode 100644 index 0000000..6e57b6c --- /dev/null +++ b/test/data/collection/20562e36-c7cc-44fb-96b4-486d51a1174b-events.xml @@ -0,0 +1 @@ +event collectionalastairpT on the Fringe 20062006-08-042006-08-30 \ No newline at end of file diff --git a/test/data/collection/2326c2e8-be4b-4300-acc6-dbd0adf5645b-works.xml b/test/data/collection/2326c2e8-be4b-4300-acc6-dbd0adf5645b-works.xml new file mode 100644 index 0000000..3883252 --- /dev/null +++ b/test/data/collection/2326c2e8-be4b-4300-acc6-dbd0adf5645b-works.xml @@ -0,0 +1 @@ +work collectionalastairpMaggot Brain \ No newline at end of file diff --git a/test/data/collection/29611d8b-b3ad-4ffb-acb5-27f77342a5b0-artists.xml b/test/data/collection/29611d8b-b3ad-4ffb-acb5-27f77342a5b0-artists.xml new file mode 100644 index 0000000..ef40493 --- /dev/null +++ b/test/data/collection/29611d8b-b3ad-4ffb-acb5-27f77342a5b0-artists.xml @@ -0,0 +1 @@ +artist collectionalastairpQueenQueenUK rock group1970-06-27 \ No newline at end of file diff --git a/test/data/collection/855b134e-9a3b-4717-8df8-8c4838d89924-places.xml b/test/data/collection/855b134e-9a3b-4717-8df8-8c4838d89924-places.xml new file mode 100644 index 0000000..6c248f8 --- /dev/null +++ b/test/data/collection/855b134e-9a3b-4717-8df8-8c4838d89924-places.xml @@ -0,0 +1 @@ +place collectionalastairpSan Francisco Bath Houseaka 'San Fran'
171 Cuba Street, Wellington, New Zealand
\ No newline at end of file diff --git a/test/data/collection/a91320b2-fd2f-4a93-9e4e-603d16d514b6-recordings.xml b/test/data/collection/a91320b2-fd2f-4a93-9e4e-603d16d514b6-recordings.xml new file mode 100644 index 0000000..8a38f33 --- /dev/null +++ b/test/data/collection/a91320b2-fd2f-4a93-9e4e-603d16d514b6-recordings.xml @@ -0,0 +1 @@ +recording collectionalastairpMaggot Brain1201000 \ No newline at end of file