From b60af9cc25cc39f5f8759a63a323a658b5389d0c Mon Sep 17 00:00:00 2001 From: jcbirdwell Date: Sat, 16 Dec 2023 16:07:07 -0600 Subject: [PATCH] add: set_album_save as a convenience/alias/findable method for album rate_playlist --- tests/test.py | 7 +++++++ ytmusicapi/mixins/library.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/tests/test.py b/tests/test.py index f69f3d4..e4a9a2b 100644 --- a/tests/test.py +++ b/tests/test.py @@ -417,6 +417,13 @@ class TestYTMusic(unittest.TestCase): "INDIFFERENT") self.assertIn("actions", response) + def test_save_album(self): + response = self.yt_auth.set_album_save("OLAK5uy_kCxQGgn8Ayb-8VNSs3Ok7qdcKe5PJy6ZQ") + self.assertIn("actions", response) + response = self.yt_auth.set_album_save("OLAK5uy_kCxQGgn8Ayb-8VNSs3Ok7qdcKe5PJy6ZQ", + saved=False) + self.assertIn("actions", response) + def test_subscribe_artists(self): self.yt_auth.subscribe_artists(["UCUDVBtnOQi4c7E8jebpjc9Q", "UCiMhD4jzUqG-IgPzUmmytRQ"]) self.yt_auth.unsubscribe_artists(["UCUDVBtnOQi4c7E8jebpjc9Q", "UCiMhD4jzUqG-IgPzUmmytRQ"]) diff --git a/ytmusicapi/mixins/library.py b/ytmusicapi/mixins/library.py index 71b01bb..c265293 100644 --- a/ytmusicapi/mixins/library.py +++ b/ytmusicapi/mixins/library.py @@ -267,6 +267,25 @@ class LibraryMixin: return self._send_request(endpoint, body) + def set_album_save(self, audioPlaylistId: str, saved=True): + """ + Edit the save status of an album in the user's library. Findable convenience/alias + method for album portion of rate_playlist. + + :param audioPlaylistId: audioPlaylistId (starts with "OLAKuy_") for the target album + :param saved: Boolean. The resulting saved state of the album. (Default = True) + + :return: Full response + """ + + self._check_auth() + body = {'target': {'playlistId': audioPlaylistId}} + endpoint = prepare_like_endpoint('LIKE' if saved else 'INDIFFERENT') + if endpoint is None: + return + + 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.