Skip to content

Commit

Permalink
add feedback get and post (#22)
Browse files Browse the repository at this point in the history
* add feedback get and post

* reviews

---------

Co-authored-by: Petitminion <[email protected]>
  • Loading branch information
petitminion and Petitminion authored Dec 19, 2023
1 parent f2bf583 commit 964fab1
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion pylistenbrainz/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,27 @@ def submit_playing_now(self, listen):
"""
return self._post_submit_listens([listen], LISTEN_TYPE_PLAYING_NOW)

def submit_user_feedback(self, feedback, recording_mbid):
""" Submit a feedback to Listenbrainz
Requires that the auth token for the user whose data is being submitted has been set.
:param feedback The type of feedback 1 = loved, -1 = hated, 0 = delete feedback if any
:param recording_mbid The recording Musicbrainz Id of the track being anotated
"""
data = {
'score': feedback,
'recording_mbid': recording_mbid,
}
headers = {
'Content-Type': 'application/json',
}
return self._post(
'/1/feedback/recording-feedback',
data=json.dumps(data),
headers=headers,
)


def delete_listen(self, listen):
""" Delete a particular listen from a user’s listen history.
Expand Down Expand Up @@ -445,4 +466,17 @@ def get_user_listen_count(self, username):
if e.status_code == 204:
return None
else:
raise
raise

def get_user_feedback(self, username):
""" Get feedback given by user
:param username The user to get the feedbacks from
"""
try:
return self._get(f'/1/feedback/user/{username}/get-feedback',)
except errors.ListenBrainzAPIException as e:
if e.status_code == 204:
return None
else:
raise

0 comments on commit 964fab1

Please sign in to comment.