Skip to content

Commit

Permalink
Add feature to vote on tags (alastair#240)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Brockmöller <[email protected]>
  • Loading branch information
gorgobacka committed Oct 31, 2018
1 parent 865cae6 commit b61aabb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 11 additions & 4 deletions musicbrainzngs/mbxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,10 +775,17 @@ def make_tag_request(**kwargs):
e_xml = ET.SubElement(e_list, "{%s}%s" % (NS, entity_type.replace('_', '-')))
e_xml.set("{%s}id" % NS, e)
taglist = ET.SubElement(e_xml, "{%s}user-tag-list" % NS)
for tag in tags:
usertag_xml = ET.SubElement(taglist, "{%s}user-tag" % NS)
name_xml = ET.SubElement(usertag_xml, "{%s}name" % NS)
name_xml.text = tag
if isinstance(tags, dict):
for tag, vote in tags.items():
usertag_xml = ET.SubElement(taglist, "{%s}user-tag" % NS)
usertag_xml.set('vote', vote)
name_xml = ET.SubElement(usertag_xml, "{%s}name" % NS)
name_xml.text = tag
else:
for tag in tags:
usertag_xml = ET.SubElement(taglist, "{%s}user-tag" % NS)
name_xml = ET.SubElement(usertag_xml, "{%s}name" % NS)
name_xml.text = tag
if kwargs.keys():
raise TypeError("make_tag_request() got an unexpected keyword argument '%s'" % kwargs.popitem()[0])

Expand Down
6 changes: 4 additions & 2 deletions musicbrainzngs/musicbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,8 +1259,10 @@ def submit_tags(**kwargs):
"""Submit user tags.
Takes parameters named e.g. 'artist_tags', 'recording_tags', etc.,
and of the form:
{entity_id1: {tag1: vote, ...}, ...}
If you don't want to vote, you can use a list of tags instead:
{entity_id1: [tag1, ...], ...}
If you only have one tag for an entity you can use a string instead
If you only have one tag for an entity, you can use a string instead
of a list.
The user's tags for each entity will be set to that list, adding or
Expand All @@ -1269,7 +1271,7 @@ def submit_tags(**kwargs):
"""
for k, v in kwargs.items():
for id, tags in v.items():
kwargs[k][id] = tags if isinstance(tags, list) else [tags]
kwargs[k][id] = tags if isinstance(tags, (list, dict)) else [tags]

query = mbxml.make_tag_request(**kwargs)
return _do_mb_post("tag", query)
Expand Down

0 comments on commit b61aabb

Please sign in to comment.