Skip to content

Commit

Permalink
Set Songs Visibility Function Added | Public or Private
Browse files Browse the repository at this point in the history
  • Loading branch information
Malith-Rukshan committed Jun 26, 2024
1 parent b3346c6 commit b865838
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 24 additions & 0 deletions suno/suno.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

1 comment on commit b865838

@Malith-Rukshan
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Request Added : #1

Please sign in to comment.