Skip to content

Commit b61aabb

Browse files
committed
Add feature to vote on tags (alastair#240)
Signed-off-by: Thomas Brockmöller <tho.b.j@gmx.de>
1 parent 865cae6 commit b61aabb

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

musicbrainzngs/mbxml.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,17 @@ def make_tag_request(**kwargs):
775775
e_xml = ET.SubElement(e_list, "{%s}%s" % (NS, entity_type.replace('_', '-')))
776776
e_xml.set("{%s}id" % NS, e)
777777
taglist = ET.SubElement(e_xml, "{%s}user-tag-list" % NS)
778-
for tag in tags:
779-
usertag_xml = ET.SubElement(taglist, "{%s}user-tag" % NS)
780-
name_xml = ET.SubElement(usertag_xml, "{%s}name" % NS)
781-
name_xml.text = tag
778+
if isinstance(tags, dict):
779+
for tag, vote in tags.items():
780+
usertag_xml = ET.SubElement(taglist, "{%s}user-tag" % NS)
781+
usertag_xml.set('vote', vote)
782+
name_xml = ET.SubElement(usertag_xml, "{%s}name" % NS)
783+
name_xml.text = tag
784+
else:
785+
for tag in tags:
786+
usertag_xml = ET.SubElement(taglist, "{%s}user-tag" % NS)
787+
name_xml = ET.SubElement(usertag_xml, "{%s}name" % NS)
788+
name_xml.text = tag
782789
if kwargs.keys():
783790
raise TypeError("make_tag_request() got an unexpected keyword argument '%s'" % kwargs.popitem()[0])
784791

musicbrainzngs/musicbrainz.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1259,8 +1259,10 @@ def submit_tags(**kwargs):
12591259
"""Submit user tags.
12601260
Takes parameters named e.g. 'artist_tags', 'recording_tags', etc.,
12611261
and of the form:
1262+
{entity_id1: {tag1: vote, ...}, ...}
1263+
If you don't want to vote, you can use a list of tags instead:
12621264
{entity_id1: [tag1, ...], ...}
1263-
If you only have one tag for an entity you can use a string instead
1265+
If you only have one tag for an entity, you can use a string instead
12641266
of a list.
12651267
12661268
The user's tags for each entity will be set to that list, adding or
@@ -1269,7 +1271,7 @@ def submit_tags(**kwargs):
12691271
"""
12701272
for k, v in kwargs.items():
12711273
for id, tags in v.items():
1272-
kwargs[k][id] = tags if isinstance(tags, list) else [tags]
1274+
kwargs[k][id] = tags if isinstance(tags, (list, dict)) else [tags]
12731275

12741276
query = mbxml.make_tag_request(**kwargs)
12751277
return _do_mb_post("tag", query)

0 commit comments

Comments
 (0)