Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "recording" methods for collections #275

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 recordings
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 recordings
recording_list = ";".join(recordings)
return _do_mb_delete(
"collection/%s/recordings/%s" % (collection_mbid, recording_list)
)