From 3eee8795da3d6809675509dad3e0e360ba48687f Mon Sep 17 00:00:00 2001 From: sigma67 Date: Tue, 15 Dec 2020 15:54:22 +0100 Subject: [PATCH] Feature: add edit_song_library_status (closes #68) --- docs/source/reference.rst | 1 + tests/test.py | 9 +++++++++ ytmusicapi/mixins/library.py | 13 +++++++++++++ 3 files changed, 23 insertions(+) diff --git a/docs/source/reference.rst b/docs/source/reference.rst index 4958c2e..291d5ed 100644 --- a/docs/source/reference.rst +++ b/docs/source/reference.rst @@ -45,6 +45,7 @@ Library .. automethod:: YTMusic.get_history .. automethod:: YTMusic.remove_history_items .. automethod:: YTMusic.rate_song +.. automethod:: YTMusic.edit_song_library_status .. automethod:: YTMusic.rate_playlist .. automethod:: YTMusic.subscribe_artists .. automethod:: YTMusic.unsubscribe_artists diff --git a/tests/test.py b/tests/test.py index fe8e273..d9244d5 100644 --- a/tests/test.py +++ b/tests/test.py @@ -196,6 +196,15 @@ class TestYTMusic(unittest.TestCase): response = youtube_auth.rate_song('ZrOKjDZOtkA', 'INDIFFERENT') self.assertIn('actions', response) + def test_edit_song_library_status(self): + album = youtube_brand.get_album('MPREb_9nqEki4ZDpp') + response = youtube_brand.edit_song_library_status( + album['tracks'][2]['feedbackTokens']['add']) + self.assertTrue(response['feedbackResponses'][0]['isProcessed']) + response = youtube_brand.edit_song_library_status( + album['tracks'][2]['feedbackTokens']['remove']) + self.assertTrue(response['feedbackResponses'][0]['isProcessed']) + def test_rate_playlist(self): response = youtube_auth.rate_playlist('OLAK5uy_l3g4WcHZsEx_QuEDZzWEiyFzZl6pL0xZ4', 'LIKE') self.assertIn('actions', response) diff --git a/ytmusicapi/mixins/library.py b/ytmusicapi/mixins/library.py index 095bb38..6c267f4 100644 --- a/ytmusicapi/mixins/library.py +++ b/ytmusicapi/mixins/library.py @@ -255,6 +255,19 @@ class LibraryMixin: return self._send_request(endpoint, body) + def edit_song_library_status(self, feedbackTokens: List[str] = None) -> Dict: + """ + Adds or removes a song from your library depending on the token provided. + + :param feedbackTokens: List of feedbackTokens obtained from authenticated requests + to endpoints that return songs (i.e. :py:func:`get_album`) + :return: Full response + """ + self._check_auth() + body = {'feedbackTokens': feedbackTokens} + endpoint = 'feedback' + return endpoint if not endpoint else self._send_request(endpoint, body) + def rate_playlist(self, playlistId: str, rating: str = 'INDIFFERENT') -> Dict: """ Rates a playlist/album ("Add to library"/"Remove from library" interactions on YouTube Music)