Skip to content

Commit

Permalink
Add "recording" methods for collections
Browse files Browse the repository at this point in the history
Collections can consist of recordings too and this adds the ability to manipulate
 the recordings in those.
  • Loading branch information
LoveIsGrief committed Dec 31, 2021
1 parent 8ed0187 commit 1186305
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
14 changes: 11 additions & 3 deletions examples/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,25 @@ def show_releases(collection):
musicbrainzngs.auth(username, password)

if args:
# Actions for a specific collction.
# Actions for a specific collection.
collection_id = args[0]
if options.add:
if option.type == "release":
if options.type == "recording":
musicbrainzngs.add_recordings_to_collection(
collection_id, [options.add]
)
elif options.type == "release":
musicbrainzngs.add_releases_to_collection(
collection_id, [options.add]
)
else:
sys.exit("only release collections can be modified ATM")
elif options.remove:
if option.type == "release":
if options.type == "recording":
musicbrainzngs.remove_recordings_from_collection(
collection_id, [options.remove]
)
elif options.type == "release":
musicbrainzngs.remove_releases_from_collection(
collection_id, [options.remove]
)
Expand Down
26 changes: 26 additions & 0 deletions musicbrainzngs/musicbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,3 +1315,29 @@ def remove_releases_from_collection(collection, releases=[]):
"""
releaselist = ";".join(releases)
return _do_mb_delete("collection/%s/releases/%s" % (collection, releaselist))

def add_recordings_to_collection(collection_mbid, recordings):
"""
:param collection_mbid: Musicbrainz ID of the collection
:param recordings: Musicbrainz IDs of the recordings to add
"""

# XXX: Maximum URI length of 16kb means we should only allow ~400 releases
recording_list = ";".join(recordings)
return _do_mb_put(
"collection/%s/recordings/%s" % (collection_mbid, recording_list)
)


def remove_recordings_from_collection(collection_mbid, recordings):
"""
:param collection_mbid: Musicbrainz ID of the collection
:param recordings: Musicbrainz IDs of the recordings to remove
"""

# XXX: Maximum URI length of 16kb means we should only allow ~400 releases
recording_list = ";".join(recordings)
return _do_mb_delete(
"collection/%s/recordings/%s" % (collection_mbid, recording_list)
)

0 comments on commit 1186305

Please sign in to comment.