From b865838f4019f3638161010749a549f038302bcf Mon Sep 17 00:00:00 2001 From: Malith-Rukshan Date: Wed, 26 Jun 2024 09:06:11 +0530 Subject: [PATCH] Set Songs Visibility Function Added | Public or Private --- README.md | 12 ++++++++++++ api.py | 3 +++ suno/suno.py | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/README.md b/README.md index b99df03..889e1c0 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,18 @@ for song in songs: songs = client.get_songs(song_ids="123,456") print(songs) ``` +`set_visibility()` +- **Arguments**: + - **song_id** (str): The ID of the song to update. + - **is_public** (bool): A string indicating whether the song should be public (True) or private (False). +- **Returns** (bool): Status of the public visibility of the song. True if the song is public, False if private. +- **Example**: +```python +response = client.set_visibility( + song_id="uuid-type-songid-1234", + is_public=False) +print(response) +``` `get_credits()` - Returns: Current billing and credits information as a `CreditsInfo` object. diff --git a/api.py b/api.py index abd0e0c..c87da75 100644 --- a/api.py +++ b/api.py @@ -83,6 +83,9 @@ def generate(song_id: str) -> JSONResponse: clip = client.get_song(song_id) return JSONResponse(content=clip.model_dump()) +@app.post(f"/set_visibility") +def set_visibility(song_id: str, is_public: bool) -> JSONResponse: + return JSONResponse(content=dict(is_public=client.set_visibility(song_id, is_public))) @app.get(f"/credits", response_model=CreditsInfo) def credits() -> JSONResponse: diff --git a/suno/suno.py b/suno/suno.py index 297a32c..f1132d6 100644 --- a/suno/suno.py +++ b/suno/suno.py @@ -212,6 +212,30 @@ def get_song(self, id: str) -> Clip: logger.info(response.text) self._cehck_error(response) return create_clip_from_data(response.json()[0]) + + def set_visibility(self, song_id: str, is_public: bool) -> bool: + """ + Set the visibility of a song to public or private. + + Parameters: + - song_id (str): The ID of the song to update. + - is_public (bool): A string indicating whether the song should be public (True) or private (False). + + Returns: + bool: Status of the public visibility of the song. True if the song is public, False if private. + """ + self._keep_alive() # Ensure session is active + payload = { + "is_public": is_public + } + response = self.client.post( + f"{Suno.BASE_URL}/api/gen/{song_id}/set_visibility/", json=payload) + logger.info(response.text) + if response.status_code == 200: + data = response.json() + return data["is_public"] + else: + raise Exception(f"Error setting visibility: {response.text}") def get_credits(self) -> CreditsInfo: """Retrieve current billing and credits information."""