Skip to content

Commit

Permalink
fix: change renew logic
Browse files Browse the repository at this point in the history
Signed-off-by: yihong0618 <[email protected]>
  • Loading branch information
yihong0618 committed Mar 25, 2024
1 parent cb2f458 commit 6d22917
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="suno_songs",
version="0.2.3",
version="0.2.4",
author="yihong0618",
author_email="[email protected]",
description="High quality image generation by ideogram.ai. Reverse engineered API.",
Expand Down
23 changes: 11 additions & 12 deletions suno/suno.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,31 +96,30 @@ def _fetch_songs_metadata(self, ids):
id1, id2 = ids[:2]
url = f"https://studio-api.suno.ai/api/feed/?ids={id1}%2C{id2}"
response = self.session.get(url, impersonate=browser_version)
try:
data = response.json()
if type(data) == dict:
print(data)
data = [data]
self.now_data = data
except:
if response.json().get("detail", "") == "Unauthorized":
data = response.json()
if type(data) == dict:
if data.get("detail", "") == "Unauthorized":
print("Token expired, renewing...")
self.retry_time += 1
if self.retry_time > 3:
if self.retry_time > 2:
song_name, lyric = self._parse_lyrics(self.now_data[0])
self.song_info_dict["song_name"] = song_name
self.song_info_dict["lyric"] = lyric
self.song_info_dict["song_url"] = (
f"https://audiopipe.suno.ai/?item_id={id1}"
)
print("will sleep 45 and try to download")
time.sleep(45)
print("will sleep 30 and try to download")
time.sleep(30)
# Done here
return True
self._renew()
time.sleep(5)
return False
else:
data = [data]
# renew now data
self.now_data = data
try:

for d in data:
# only get one url for now
# and early return
Expand Down

0 comments on commit 6d22917

Please sign in to comment.